diff options
author | Junio C Hamano <gitster@pobox.com> | 2012-07-02 12:04:52 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2012-07-09 16:42:22 -0700 |
commit | cd74e4733db3e2353077bdc7021caa70bed2a483 (patch) | |
tree | 0f8f243291844cb4208996065ff8ca84b99a4de1 /sha1_name.c | |
parent | sha1_name.c: teach lookup context to get_sha1_with_context() (diff) | |
download | tgif-cd74e4733db3e2353077bdc7021caa70bed2a483.tar.xz |
sha1_name.c: introduce get_sha1_committish()
Many callers know that the user meant to name a committish by
syntactical positions where the object name appears. Calling this
function allows the machinery to disambiguate shorter-than-unique
abbreviated object names between committish and others.
Note that this does NOT error out when the named object is not a
committish. It is merely to give a hint to the disambiguation
machinery.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1_name.c')
-rw-r--r-- | sha1_name.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/sha1_name.c b/sha1_name.c index c045be8e13..9e13d60bfa 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -872,7 +872,7 @@ int get_sha1_mb(const char *name, unsigned char *sha1) struct strbuf sb; strbuf_init(&sb, dots - name); strbuf_add(&sb, name, dots - name); - st = get_sha1(sb.buf, sha1_tmp); + st = get_sha1_committish(sb.buf, sha1_tmp); strbuf_release(&sb); } if (st) @@ -881,7 +881,7 @@ int get_sha1_mb(const char *name, unsigned char *sha1) if (!one) return -1; - if (get_sha1(dots[3] ? (dots + 3) : "HEAD", sha1_tmp)) + if (get_sha1_committish(dots[3] ? (dots + 3) : "HEAD", sha1_tmp)) return -1; two = lookup_commit_reference_gently(sha1_tmp, 0); if (!two) @@ -999,6 +999,23 @@ int get_sha1(const char *name, unsigned char *sha1) return get_sha1_with_context(name, 0, sha1, &unused); } +/* + * Many callers know that the user meant to name a committish by + * syntactical positions where the object name appears. Calling this + * function allows the machinery to disambiguate shorter-than-unique + * abbreviated object names between committish and others. + * + * Note that this does NOT error out when the named object is not a + * committish. It is merely to give a hint to the disambiguation + * machinery. + */ +int get_sha1_committish(const char *name, unsigned char *sha1) +{ + struct object_context unused; + return get_sha1_with_context(name, GET_SHA1_COMMITTISH, + sha1, &unused); +} + /* Must be called only when object_name:filename doesn't exist. */ static void diagnose_invalid_sha1_path(const char *prefix, const char *filename, |