]> Pileus Git - ~andy/git/commitdiff
sha1_name.c: teach get_short_sha1() a commit-only option
authorJunio C Hamano <gitster@pobox.com>
Thu, 21 Jun 2012 06:03:09 +0000 (23:03 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 3 Jul 2012 18:17:59 +0000 (11:17 -0700)
When the caller knows that the parameter is meant to name a commit,
e.g. "56789a" in describe name "v1.2.3-4-g56789a", pass that as a
hint so that lower level can use it to disambiguate objects when
there is only one commit whose name begins with 56789a even if there
are objects of other types whose names share the same prefix.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
cache.h
sha1_name.c

diff --git a/cache.h b/cache.h
index 1bafa45a7ec65a5df1c6bf79f8706faa23bea961..2d91dbd958bd78b7580b535a8a5249470aa9acc0 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -812,6 +812,7 @@ struct object_context {
 };
 
 #define GET_SHA1_QUIETLY 01
+#define GET_SHA1_COMMIT 02
 
 extern int get_sha1(const char *str, unsigned char *sha1);
 extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix);
index 793d80cbf9d0f2d232032a844c5fadf47d76e0b0..174d3df9b34bc208bd552a3452a9c46a399c07ba 100644 (file)
@@ -218,6 +218,12 @@ static int finish_object_disambiguation(struct disambiguate_state *ds,
        return 0;
 }
 
+static int disambiguate_commit_only(const unsigned char *sha1, void *cb_data_unused)
+{
+       int kind = sha1_object_info(sha1, NULL);
+       return kind == OBJ_COMMIT;
+}
+
 static int get_short_sha1(const char *name, int len, unsigned char *sha1,
                          unsigned flags)
 {
@@ -253,6 +259,9 @@ static int get_short_sha1(const char *name, int len, unsigned char *sha1,
        prepare_alt_odb();
 
        memset(&ds, 0, sizeof(ds));
+       if (flags & GET_SHA1_COMMIT)
+               ds.fn = disambiguate_commit_only;
+
        find_short_object_filename(len, hex_pfx, &ds);
        find_short_packed_object(len, bin_pfx, &ds);
        status = finish_object_disambiguation(&ds, sha1);