]> git.ipfire.org Git - thirdparty/git.git/commitdiff
for-each-ref: Field with abbreviated objectname
authorMichael J Gruber <git@drmicha.warpmail.net>
Thu, 13 May 2010 12:31:46 +0000 (14:31 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 19 May 2010 04:49:04 +0000 (21:49 -0700)
Introduce a :short modifier to objectname which outputs the abbreviated
object name.

Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
Reviewed-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-for-each-ref.txt
builtin/for-each-ref.c
t/t6300-for-each-ref.sh

index 7e83288d1846a7fcd53ec46776160a2f5ffbad84..390d85ccaea6ada3f3bce6148bcdd84d4f0bc2ac 100644 (file)
@@ -86,6 +86,7 @@ objectsize::
 
 objectname::
        The object name (aka SHA-1).
+       For a non-ambiguous abbreviation of the object name append `:short`.
 
 upstream::
        The name of a local ref which can be considered ``upstream''
index 62be1bbfd6659f9dfac73a17acd1e2d5322dac66..3a97953177eee234c310bbf37bab5f2d7e03e5aa 100644 (file)
@@ -227,6 +227,9 @@ static void grab_common_values(struct atom_value *val, int deref, struct object
                        strcpy(s, sha1_to_hex(obj->sha1));
                        v->s = s;
                }
+               else if (!strcmp(name, "objectname:short")) {
+                       v->s = find_unique_abbrev(obj->sha1, DEFAULT_ABBREV);
+               }
        }
 }
 
index 8052c86ad3516505765ab214f4801940c8cc1684..7dc8a510c7f33d048cd3268424298fdda2f8c2bb 100755 (executable)
@@ -295,6 +295,15 @@ test_expect_success 'Check short upstream format' '
        test_cmp expected actual
 '
 
+cat >expected <<EOF
+67a36f1
+EOF
+
+test_expect_success 'Check short objectname format' '
+       git for-each-ref --format="%(objectname:short)" refs/heads >actual &&
+       test_cmp expected actual
+'
+
 test_expect_success 'Check for invalid refname format' '
        test_must_fail git for-each-ref --format="%(refname:INVALID)"
 '