summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 04794fd)
raw | patch | inline | side by side (parent: 04794fd)
author | Michael J Gruber <git@drmicha.warpmail.net> | |
Thu, 13 May 2010 12:31:46 +0000 (14:31 +0200) | ||
committer | Junio 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>
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 | patch | blob | history | |
builtin/for-each-ref.c | patch | blob | history | |
t/t6300-for-each-ref.sh | patch | blob | history |
index 7e83288d1846a7fcd53ec46776160a2f5ffbad84..390d85ccaea6ada3f3bce6148bcdd84d4f0bc2ac 100644 (file)
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''
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index 62be1bbfd6659f9dfac73a17acd1e2d5322dac66..3a97953177eee234c310bbf37bab5f2d7e03e5aa 100644 (file)
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
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)
--- a/t/t6300-for-each-ref.sh
+++ b/t/t6300-for-each-ref.sh
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)"
'