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

Re: [PATCH 2/3] tag: die when listing missing or corrupt objects

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 6, 2012, 18:13 UTC
Message-ID
<7vty337rug.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20120206083832.GA9425@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
> OK, that's easy enough to do. Should we show lightweight tags to commits
> for backwards compatibility (and just drop the parse_signature junk in
> that case)? The showing of blobs or trees is the really bad thing, I
> think.
For now, dropping 3/3 and queuing this instead...
---
Subject: tag: do not show non-tag contents with "-n"

"git tag -n" did not check the type of the object it is reading the top n lines from. At least, avoid showing the beginning of trees and blobs when dealing with lightweight tags that point at them.

As the payload of a tag and a commit look similar in that they both start with a header block, which is skipped for the purpose of "-n" output, followed by human readable text, allow the message of commit objects to be shown just like the contents of tag objects. This avoids regression for people who have been using "tag -n" to show the log messages of commits that are pointed at by lightweight tags.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin/tag.c |   22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/builtin/tag.c b/builtin/tag.c
index 1e27f5c..6d6ae88 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -95,19 +95,20 @@ static void show_tag_lines(const unsigned char *sha1, int lines)
 	buf = read_sha1_file(sha1, &type, &size);
 	if (!buf)
 		die_errno("unable to read object %s", sha1_to_hex(sha1));
-	if (!size) {
-		free(buf);
-		return;
-	}
+	if (type != OBJ_COMMIT || type != OBJ_TAG)
+		goto free_return;
+	if (!size)
+		die("an empty %s object %s?",
+		    typename(type), sha1_to_hex(sha1));
 
 	/* skip header */
 	sp = strstr(buf, "\n\n");
-	if (!sp) {
-		free(buf);
-		return;
-	}
-	/* only take up to "lines" lines, and strip the signature */
-	size = parse_signature(buf, size);
+	if (!sp)
+		goto free_return;
+
+	/* only take up to "lines" lines, and strip the signature from a tag */
+	if (type == OBJ_TAG)
+		size = parse_signature(buf, size);
 	for (i = 0, sp += 2; i < lines && sp < buf + size; i++) {
 		if (i)
 			printf("\n    ");
@@ -118,6 +119,7 @@ static void show_tag_lines(const unsigned char *sha1, int lines)
 			break;
 		sp = eol + 1;
 	}
+free_return:
 	free(buf);
 }
 
Previous: Junio C HamanoNext: Jeff King
Message 19 of 53 in “tag: add --points-at list option”
  1. tag: add --points-at list optionTom Grennan, Feb 5, 2012
  2. Junio C HamanoFeb 5, 2012
  3. Tom GrennanFeb 6, 2012
  4. Junio C HamanoFeb 6, 2012
  5. Tom GrennanFeb 6, 2012
  6. Jeff KingFeb 6, 2012
  7. Tom GrennanFeb 6, 2012
  8. Jeff KingFeb 6, 2012
  9. Jeff KingFeb 6, 2012
  10. Jeff KingFeb 6, 2012
  11. Jeff KingFeb 6, 2012
  12. 1/3 tag: fix output of "tag -n" when errors occurJeff King, Feb 6, 2012
  13. 2/3 tag: die when listing missing or corrupt objectsJeff King, Feb 6, 2012
  14. Junio C HamanoFeb 6, 2012
  15. Jeff KingFeb 6, 2012
  16. Junio C HamanoFeb 6, 2012
  17. Jeff KingFeb 6, 2012
  18. Junio C HamanoFeb 6, 2012
  19. Junio C HamanoFeb 6, 2012
  20. Jeff KingFeb 6, 2012
  21. Junio C HamanoFeb 6, 2012
  22. Jeff KingFeb 8, 2012
  23. Junio C HamanoFeb 9, 2012
  24. 3/3 tag: don't show non-tag contents with "-n"Jeff King, Feb 6, 2012
  25. [PATCHv2] tag: add --points-at list optionTom Grennan, Feb 7, 2012
  26. [PATCHv2] tag: add --points-at list optionTom Grennan, Feb 7, 2012
  27. Junio C HamanoFeb 7, 2012
  28. Tom GrennanFeb 7, 2012
  29. Jeff KingFeb 7, 2012
  30. Tom GrennanFeb 7, 2012
  31. Jeff KingFeb 7, 2012
  32. Tom GrennanFeb 7, 2012
  33. Jeff KingFeb 7, 2012
  34. Junio C HamanoFeb 7, 2012
  35. Jeff KingFeb 7, 2012
  36. Tom GrennanFeb 7, 2012
  37. Jeff KingFeb 8, 2012
  38. Tom GrennanFeb 8, 2012
  39. Jeff KingFeb 8, 2012
  40. [PATCHv3] tag: add --points-at list optionTom Grennan, Feb 8, 2012
  41. [PATCHv3] tag: add --points-at list optionTom Grennan, Feb 8, 2012
  42. Jeff KingFeb 8, 2012
  43. Tom GrennanFeb 8, 2012
  44. Jeff KingFeb 8, 2012
  45. [PATCHv4] tag: add --points-at list optionTom Grennan, Feb 8, 2012
  46. [PATCHv4] tag: add --points-at list optionTom Grennan, Feb 8, 2012
  47. Jeff KingFeb 8, 2012
  48. Tom GrennanFeb 8, 2012
  49. tag: add --points-at list optionTom Grennan, Feb 8, 2012
  50. tag: add --points-at list optionTom Grennan, Feb 8, 2012
  51. Jeff KingFeb 9, 2012
  52. Junio C HamanoFeb 9, 2012
  53. Tom GrennanFeb 8, 2012

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.