summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2013-09-20 12:27:18 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2013-09-20 12:27:18 -0700
commit638924fec2189f3f20ebf5d0ff4cc34ee551dd39 (patch)
tree3a7b24c2855c88f95885e5fc5f6bfd372d72097d
parentMerge branch 'jx/branch-vv-always-compare-with-upstream' (diff)
parentpeel_onion: do not assume length of x_type globals (diff)
downloadtgif-638924fec2189f3f20ebf5d0ff4cc34ee551dd39.tar.xz
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}
-rw-r--r--Documentation/revisions.txt3
-rw-r--r--sha1_name.c8
-rwxr-xr-xt/t1511-rev-parse-caret.sh7
3 files changed, 15 insertions, 3 deletions
diff --git a/Documentation/revisions.txt b/Documentation/revisions.txt
index b0f4284cfb..71dcd12ebd 100644
--- a/Documentation/revisions.txt
+++ b/Documentation/revisions.txt
@@ -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
without dereferencing 'rev'; because a tag is already 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}\{\}'::
A suffix '{caret}' followed by an empty brace pair
diff --git a/sha1_name.c b/sha1_name.c
index ad79d7b812..78c093f79e 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -677,11 +677,13 @@ static int peel_onion(const char *name, int len, unsigned char *sha1)
return -1;
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;
- 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;
- else if (!strncmp(blob_type, sp, 4) && sp[4] == '}')
+ else if (!prefixcmp(sp, "blob}"))
expected_type = OBJ_BLOB;
else if (!prefixcmp(sp, "object}"))
expected_type = OBJ_ANY;
diff --git a/t/t1511-rev-parse-caret.sh b/t/t1511-rev-parse-caret.sh
index eaefc777bd..15973f2094 100755
--- a/t/t1511-rev-parse-caret.sh
+++ b/t/t1511-rev-parse-caret.sh
@@ -54,6 +54,13 @@ test_expect_success 'ref^{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^{/.}' '
git rev-parse master >expected &&
git rev-parse master^{/.} >actual &&