Thread (1 message) 1 message, 1 author, 2016-06-15

Re: [PATCH 2/2] peel_onion(): teach $foo^{object} peeler

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:56:36
Subsystem: the rest · Maintainer: Linus Torvalds

Possibly related (same subject, not in this thread)

Michael Haggerty [off-list ref] writes:
On 04/02/2013 05:45 PM, Junio C Hamano wrote:
quoted
Also, v1.8.2^{tag} would be give the tag itself, while master^{tag}
would not report the commit "master" but would error out, which
would be useless.  You are better off doing `git cat-file -t foo`
and seeing if it is a tag object at that point.
All correct, of course.  But the user would never use "master^{tag}"
unless he wants a tag and nothing else, so erroring out would be exactly
the thing he wants in that case.  This is no different than the
"^{commit}" part of "master^{tree}^{commit}", which correctly errors out
because a commit cannot be inferred from a tree.
Correct; I was only saying adding it is not something that solves a
problem that cannot be solved with the current system (i.e. no added
value from feature point-of-view).  I would not object to a patch to
allow "git rev-parse v1.8.2^{tag}" for completeness.

We may want to rethink if we can lose the hardcoded lengths like 6,
3, 4, 4 from here, but I didn't bother ;-).


 sha1_name.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/sha1_name.c b/sha1_name.c
index 85b6e75..47f39a8 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -639,16 +639,18 @@ 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 (!strncmp(tag_type, sp, 3) && sp[3] == '}')
+		expected_type = OBJ_TAG;
+	else if (!strncmp(commit_type, sp, 6) && sp[6] == '}')
 		expected_type = OBJ_COMMIT;
 	else if (!strncmp(tree_type, sp, 4) && sp[4] == '}')
 		expected_type = OBJ_TREE;
 	else if (!strncmp(blob_type, sp, 4) && sp[4] == '}')
 		expected_type = OBJ_BLOB;
 	else if (!prefixcmp(sp, "object}"))
-		expected_type = OBJ_ANY;
+		expected_type = OBJ_ANY; /* ok as long as it exists */
 	else if (sp[0] == '}')
-		expected_type = OBJ_NONE;
+		expected_type = OBJ_NONE; /* unwrap until we get a non-tag */
 	else if (sp[0] == '/')
 		expected_type = OBJ_COMMIT;
 	else
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help