git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 2, 2013, 16:56 UTC
Message-ID
<7v6204g9bl.fsf@alter.siamese.dyndns.org>
In-Reply-To
<515B083A.5050808@alum.mit.edu>
Michael Haggerty <mhagger@alum.mit.edu> writes:
Show 12 quoted lines
> On 04/02/2013 05:45 PM, Junio C Hamano wrote:
>
>> 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
Previous: Michael Haggerty
Message 22 of 22 in “Bug in "git rev-parse --verify"”
  1. Michael HaggertyMar 28, 2013
  2. Jeff KingMar 28, 2013
  3. Junio C HamanoMar 28, 2013
  4. Michael HaggertyMar 28, 2013
  5. Jeff KingMar 28, 2013
  6. Michael HaggertyMar 28, 2013
  7. Jeff KingMar 28, 2013
  8. Junio C HamanoMar 28, 2013
  9. Michael HaggertyMar 30, 2013
  10. Junio C HamanoMar 30, 2013
  11. Junio C HamanoMar 30, 2013
  12. Michael HaggertyMar 30, 2013
  13. Junio C HamanoMar 30, 2013
  14. Junio C HamanoMar 30, 2013
  15. Michael HaggertyMar 30, 2013
  16. Elia PintoMar 30, 2013
  17. 1/2 peel_onion: disambiguate to favor tree-ish when we want a tree-ishJunio C Hamano, Mar 31, 2013
  18. 2/2 peel_onion(): teach $foo^{object} peelerJunio C Hamano, Mar 31, 2013
  19. Michael HaggertyApr 2, 2013
  20. Junio C HamanoApr 2, 2013
  21. Michael HaggertyApr 2, 2013
  22. Junio C HamanoApr 2, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.