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 <git@drmicha.warpmail.net> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
04794fdc27
commit
67687feae5
@ -86,6 +86,7 @@ objectsize::
|
|||||||
|
|
||||||
objectname::
|
objectname::
|
||||||
The object name (aka SHA-1).
|
The object name (aka SHA-1).
|
||||||
|
For a non-ambiguous abbreviation of the object name append `:short`.
|
||||||
|
|
||||||
upstream::
|
upstream::
|
||||||
The name of a local ref which can be considered ``upstream''
|
The name of a local ref which can be considered ``upstream''
|
||||||
|
@ -227,6 +227,9 @@ static void grab_common_values(struct atom_value *val, int deref, struct object
|
|||||||
strcpy(s, sha1_to_hex(obj->sha1));
|
strcpy(s, sha1_to_hex(obj->sha1));
|
||||||
v->s = s;
|
v->s = s;
|
||||||
}
|
}
|
||||||
|
else if (!strcmp(name, "objectname:short")) {
|
||||||
|
v->s = find_unique_abbrev(obj->sha1, DEFAULT_ABBREV);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,6 +295,15 @@ test_expect_success 'Check short upstream format' '
|
|||||||
test_cmp expected actual
|
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_expect_success 'Check for invalid refname format' '
|
||||||
test_must_fail git for-each-ref --format="%(refname:INVALID)"
|
test_must_fail git for-each-ref --format="%(refname:INVALID)"
|
||||||
'
|
'
|
||||||
|
Loading…
Reference in New Issue
Block a user