Merge branch 'rh/peeling-tag-to-tag'

Make "foo^{tag}" to peel a tag to itself, i.e. no-op., and fail if
"foo" is not a tag.  "git rev-parse --verify v1.0^{tag}" would be a
more convenient way to say "test $(git cat-file -t v1.0) = tag".

* rh/peeling-tag-to-tag:
  peel_onion: do not assume length of x_type globals
  peel_onion(): add support for <rev>^{tag}
This commit is contained in:
Junio C Hamano 2013-09-20 12:27:18 -07:00
commit 638924fec2
3 changed files with 15 additions and 3 deletions

View File

@ -125,6 +125,9 @@ some output processing may assume ref names in UTF-8.
object that exists, without requiring 'rev' to be a tag, and object that exists, without requiring 'rev' to be a tag, and
without dereferencing 'rev'; because a tag is already an object, without dereferencing 'rev'; because a tag is already an object,
it does not have to be dereferenced even once to get to an object. it does not have to be dereferenced even once to get to an object.
+
'rev{caret}\{tag\}' can be used to ensure that 'rev' identifies an
existing tag object.
'<rev>{caret}\{\}', e.g. 'v0.99.8{caret}\{\}':: '<rev>{caret}\{\}', e.g. 'v0.99.8{caret}\{\}'::
A suffix '{caret}' followed by an empty brace pair A suffix '{caret}' followed by an empty brace pair

View File

@ -677,11 +677,13 @@ static int peel_onion(const char *name, int len, unsigned char *sha1)
return -1; return -1;
sp++; /* beginning of type name, or closing brace for empty */ sp++; /* beginning of type name, or closing brace for empty */
if (!strncmp(commit_type, sp, 6) && sp[6] == '}') if (!prefixcmp(sp, "commit}"))
expected_type = OBJ_COMMIT; expected_type = OBJ_COMMIT;
else if (!strncmp(tree_type, sp, 4) && sp[4] == '}') else if (!prefixcmp(sp, "tag}"))
expected_type = OBJ_TAG;
else if (!prefixcmp(sp, "tree}"))
expected_type = OBJ_TREE; expected_type = OBJ_TREE;
else if (!strncmp(blob_type, sp, 4) && sp[4] == '}') else if (!prefixcmp(sp, "blob}"))
expected_type = OBJ_BLOB; expected_type = OBJ_BLOB;
else if (!prefixcmp(sp, "object}")) else if (!prefixcmp(sp, "object}"))
expected_type = OBJ_ANY; expected_type = OBJ_ANY;

View File

@ -54,6 +54,13 @@ test_expect_success 'ref^{tree}' '
test_must_fail git rev-parse blob-tag^{tree} test_must_fail git rev-parse blob-tag^{tree}
' '
test_expect_success 'ref^{tag}' '
test_must_fail git rev-parse HEAD^{tag} &&
git rev-parse commit-tag >expected &&
git rev-parse commit-tag^{tag} >actual &&
test_cmp expected actual
'
test_expect_success 'ref^{/.}' ' test_expect_success 'ref^{/.}' '
git rev-parse master >expected && git rev-parse master >expected &&
git rev-parse master^{/.} >actual && git rev-parse master^{/.} >actual &&