Skip to content

Commit 638924f

Browse files
committed
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}
2 parents 2e6e3e8 + c969b6a commit 638924f

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

Documentation/revisions.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ some output processing may assume ref names in UTF-8.
125125
object that exists, without requiring 'rev' to be a tag, and
126126
without dereferencing 'rev'; because a tag is already an object,
127127
it does not have to be dereferenced even once to get to an object.
128+
+
129+
'rev{caret}\{tag\}' can be used to ensure that 'rev' identifies an
130+
existing tag object.
128131

129132
'<rev>{caret}\{\}', e.g. 'v0.99.8{caret}\{\}'::
130133
A suffix '{caret}' followed by an empty brace pair

sha1_name.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -677,11 +677,13 @@ static int peel_onion(const char *name, int len, unsigned char *sha1)
677677
return -1;
678678

679679
sp++; /* beginning of type name, or closing brace for empty */
680-
if (!strncmp(commit_type, sp, 6) && sp[6] == '}')
680+
if (!prefixcmp(sp, "commit}"))
681681
expected_type = OBJ_COMMIT;
682-
else if (!strncmp(tree_type, sp, 4) && sp[4] == '}')
682+
else if (!prefixcmp(sp, "tag}"))
683+
expected_type = OBJ_TAG;
684+
else if (!prefixcmp(sp, "tree}"))
683685
expected_type = OBJ_TREE;
684-
else if (!strncmp(blob_type, sp, 4) && sp[4] == '}')
686+
else if (!prefixcmp(sp, "blob}"))
685687
expected_type = OBJ_BLOB;
686688
else if (!prefixcmp(sp, "object}"))
687689
expected_type = OBJ_ANY;

t/t1511-rev-parse-caret.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ test_expect_success 'ref^{tree}' '
5454
test_must_fail git rev-parse blob-tag^{tree}
5555
'
5656

57+
test_expect_success 'ref^{tag}' '
58+
test_must_fail git rev-parse HEAD^{tag} &&
59+
git rev-parse commit-tag >expected &&
60+
git rev-parse commit-tag^{tag} >actual &&
61+
test_cmp expected actual
62+
'
63+
5764
test_expect_success 'ref^{/.}' '
5865
git rev-parse master >expected &&
5966
git rev-parse master^{/.} >actual &&

0 commit comments

Comments
 (0)