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

Re: git log doesn't allow %x00 in custom format anymore?

From
Jeff King <peff@peff.net>
Date
Oct 7, 2010, 17:29 UTC
Message-ID
<20101007172939.GA12130@sigill.intra.peff.net>
In-Reply-To
<FF2FF369-0B1C-457E-A86E-8651BF0A82CB@jetbrains.com>
On Thu, Oct 07, 2010 at 07:18:18PM +0400, Kirill Likhodedov wrote:
Show 13 quoted lines
> Thanks for pointing that out.
> I confirm that on Mac OS X that happens for rev-list as well. 
> 
> # git log --pretty=format:foo%x00bar HEAD -1 | od -c
> 0000000   f   o   o  \0   b   a   r
> 0000007
> 
> # git rev-list --pretty=format:foo%x00bar HEAD -1 | od -c
> 0000000   c   o   m   m   i   t       2   3   6   0   1   a   2   c   3
> 0000020   e   4   6   4   a   4   4   7   9   f   1   7   7   4   e   3
> 0000040   6   e   a   5   b   9   5   8   b   4   6   0   5   2   1  \n
> 0000060   f   o   o  \n
> 0000064

Ugh. Even worse, it does print with --graph, which uses a slightly different code path.

  $ git rev-list --graph -1 --format=foo%x00bar HEAD | cat -A
  *   commit 81d866a6a213d5524ce389369377ba3529461e1b$
  |\  foo^@bar$

I am inclined to call the rev-list behavior a bug, and the fix is probably:

diff --git a/builtin/rev-list.c b/builtin/rev-list.c
index efe9360..3b2dca0 100644
--- a/builtin/rev-list.c
+++ b/builtin/rev-list.c
@@ -147,8 +147,10 @@ static void show_commit(struct commit *commit, void *data)
 			}
 		} else {
 			if (revs->commit_format != CMIT_FMT_USERFORMAT ||
-			    buf.len)
-				printf("%s%c", buf.buf, info->hdr_termination);
+			    buf.len) {
+				fwrite(buf.buf, 1, buf.len, stdout);
+				putchar(info->hdr_termination);
+			}
 		}
 		strbuf_release(&buf);
 	} else {
Previous: Kirill LikhodedovNext: Matthieu Moy
Message 7 of 19 in “git log doesn't allow %x00 in custom format anymore?”
  1. Kirill LikhodedovOct 7, 2010
  2. Jeff KingOct 7, 2010
  3. Kirill LikhodedovOct 7, 2010
  4. Jeff KingOct 7, 2010
  5. Johannes SixtOct 7, 2010
  6. Kirill LikhodedovOct 7, 2010
  7. Jeff KingOct 7, 2010
  8. Matthieu MoyOct 7, 2010
  9. Drew NorthupOct 7, 2010
  10. Erik Faye-LundOct 7, 2010
  11. Erik Faye-LundOct 7, 2010
  12. Jeff KingOct 7, 2010
  13. Matthieu MoyOct 7, 2010
  14. Jeff KingOct 7, 2010
  15. Erik Faye-LundOct 7, 2010
  16. Jeff KingOct 7, 2010
  17. Erik Faye-LundOct 7, 2010
  18. Jeff KingOct 7, 2010
  19. Erik Faye-LundOct 7, 2010

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.