From: Michael J Gruber Date: Thu, 13 May 2010 12:31:46 +0000 (+0200) Subject: for-each-ref: Field with abbreviated objectname X-Git-Tag: v1.7.2-rc0~136 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=67687feae52ff2d3ab7edf3ac42a39c5e44be299;p=git.git for-each-ref: Field with abbreviated objectname Introduce a :short modifier to objectname which outputs the abbreviated object name. Signed-off-by: Michael J Gruber Reviewed-by: Jeff King Signed-off-by: Junio C Hamano --- diff --git a/Documentation/git-for-each-ref.txt b/Documentation/git-for-each-ref.txt index 7e83288d1..390d85cca 100644 --- a/Documentation/git-for-each-ref.txt +++ b/Documentation/git-for-each-ref.txt @@ -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'' diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c index 62be1bbfd..3a9795317 100644 --- a/builtin/for-each-ref.c +++ b/builtin/for-each-ref.c @@ -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); + } } } diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh index 8052c86ad..7dc8a510c 100755 --- a/t/t6300-for-each-ref.sh +++ b/t/t6300-for-each-ref.sh @@ -295,6 +295,15 @@ test_expect_success 'Check short upstream format' ' test_cmp expected actual ' +cat >expected <actual && + test_cmp expected actual +' + test_expect_success 'Check for invalid refname format' ' test_must_fail git for-each-ref --format="%(refname:INVALID)" '