diff options
author | Junio C Hamano <gitster@pobox.com> | 2012-06-20 23:03:09 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2012-07-03 11:17:59 -0700 |
commit | aa1dec9ef6ff184792520eb4539af1555c01604c (patch) | |
tree | 57f7ce140695ba2f9f6ce28f3674a204a899c9de /sha1_name.c | |
parent | 37c00e5590605c9d3ba76b6c9d7a94ac0356f703 (diff) | |
download | git-aa1dec9ef6ff184792520eb4539af1555c01604c.tar.gz git-aa1dec9ef6ff184792520eb4539af1555c01604c.tar.xz |
sha1_name.c: teach get_short_sha1() a commit-only option
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>
Diffstat (limited to 'sha1_name.c')
-rw-r--r-- | sha1_name.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/sha1_name.c b/sha1_name.c index 793d80cbf..174d3df9b 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -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); |