]> git.ipfire.org Git - thirdparty/git.git/commitdiff
sha1_name.c: introduce get_sha1_committish()
authorJunio C Hamano <gitster@pobox.com>
Mon, 2 Jul 2012 19:04:52 +0000 (12:04 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 9 Jul 2012 23:42:22 +0000 (16:42 -0700)
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>
cache.h
commit.c
revision.c
sha1_name.c
t/t1512-rev-parse-disambiguation.sh

diff --git a/cache.h b/cache.h
index e1fa63b3196238b5df5348ab3498fd454511e386..e947b48d0da4db838c16c1bb4ae112755600877d 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -817,6 +817,7 @@ struct object_context {
 #define GET_SHA1_ONLY_TO_DIE 04000
 
 extern int get_sha1(const char *str, unsigned char *sha1);
+extern int get_sha1_committish(const char *str, unsigned char *sha1);
 extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix);
 extern int get_sha1_with_context(const char *str, unsigned flags, unsigned char *sha1, struct object_context *orc);
 
index 35af4988f0ff83c6a3379ea9f6de4e4e1568c39f..8b84efff98296abf97690a914750568103aebced 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -67,7 +67,7 @@ struct commit *lookup_commit_reference_by_name(const char *name)
        unsigned char sha1[20];
        struct commit *commit;
 
-       if (get_sha1(name, sha1))
+       if (get_sha1_committish(name, sha1))
                return NULL;
        commit = lookup_commit_reference(sha1);
        if (!commit || parse_commit(commit))
index 7444f2eaa13c50afc0fa13b8c43d4f6a08f767fb..c3160f2e6fd13bb2ca8cc6f5817a2a2206784d94 100644 (file)
@@ -979,7 +979,7 @@ static int add_parents_only(struct rev_info *revs, const char *arg_, int flags)
                flags ^= UNINTERESTING;
                arg++;
        }
-       if (get_sha1(arg, sha1))
+       if (get_sha1_committish(arg, sha1))
                return 0;
        while (1) {
                it = get_reference(revs, arg, sha1, 0);
@@ -1120,8 +1120,8 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs,
                        next = "HEAD";
                if (dotdot == arg)
                        this = "HEAD";
-               if (!get_sha1(this, from_sha1) &&
-                   !get_sha1(next, sha1)) {
+               if (!get_sha1_committish(this, from_sha1) &&
+                   !get_sha1_committish(next, sha1)) {
                        struct commit *a, *b;
                        struct commit_list *exclude;
 
index c045be8e13e16d09487023eecad31e570397cf98..9e13d60bfa1bbc26b6f68c50cf67253bbd1dd776 100644 (file)
@@ -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,
index 7652f1c2e96c529fe6ee421fb544a3a48b16d135..6f87d8ea9d7dc17b1e3f41f457e8d4605fc4526d 100755 (executable)
@@ -102,7 +102,7 @@ test_expect_failure 'disambiguate commit' '
        test $(git rev-parse $commit^) = $(git rev-parse 0000000000e4f)
 '
 
-test_expect_failure 'log name1..name2 takes only commit-ishes on both ends' '
+test_expect_success 'log name1..name2 takes only commit-ishes on both ends' '
        git log 000000000..000000000 &&
        git log ..000000000 &&
        git log 000000000.. &&