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

Re: [PATCH 00/22] Refactor to accept NUL in commit messages

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 23, 2011, 05:51 UTC
Message-ID
<7vipng5k80.fsf@alter.siamese.dyndns.org>
In-Reply-To
<CACsJy8B=TsC4A=R6b3jyYBCvorEDBYHQ8uA864WrB0-3pgNyKA@mail.gmail.com>
Nguyen Thai Ngoc Duy <pclouds@gmail.com> writes:
Show 9 quoted lines
> We could allocate just one block with length as the first field:
>
> struct commit_buffer {
>         unsigned long len;
>         char buf[FLEX_ARRAY];
> };
>
> The downside is commit_buffer field type in struct commit changes,
> which impacts many codepaths.

I think that is a good thing overall to _force_ us to audit all the code, *if* our goal were to avoid losing bytes. And the solution above is better than adding a length field to "struct commit". It certainly is better than quoting NUL byte to ^@, keep using the "char *" field and risking some codepaths forget to convert it back to NUL. For types of payloads for which losing everything after the first NUL matters, converting NUL to ^@ and then forgetting to convert it back to NUL is equally bad breakage to the payload anyway, so such a conversion would not be a particularly good approach to avoid losing bytes.

But as Jeff suggested, we should step back a bit and think what our goal is.

The low level object format of our commit is textual header fields, each of which is terminated with a LF, followed by a LF to mark the end of header fields, and then opaque payload that can contain any bytes. It does not forbid a non-Git application to reuse the object store infrastructure to store ASN.1 binary goo there, and the low level interface we give such as cat-file is a perfectly valid way to inspect such a "commit" object.

But when it comes to "Git" Porcelains (e.g. the log family of commands), we do assume people do not store random binary byte sequences in commits, and we do take advantage of that assumption by splitting each "line" at LF, indenting them with 4 spaces, etc. In other words, a commit log in the Git context _is_ pretty much text and not arbitrary byte sequence. Even the "--pretty=raw" option for "log" family is not about the "raw" body; the "raw"-ness applies only to the header fields. So even if we _were_ to update the codepaths involved to avoid losing bytes, the end result will not be useful for users to whom ability to include NUL matters.

So in that sense, I do not think it is unreasonable to chop it off at the first NUL, which is the current behaviour. IOW, it is entirely sane to argue that there is nothing to fix.

Previous: Nguyen Thai Ngoc DuyNext: Nguyen Thai Ngoc Duy
Message 6 of 26 in “Re: [PATCH 00/22] Refactor to accept NUL in commit messages”
  1. Jeff KingOct 22, 2011
  2. Robin RosenbergOct 23, 2011
  3. Jeff KingOct 23, 2011
  4. Junio C HamanoOct 22, 2011
  5. Nguyen Thai Ngoc DuyOct 23, 2011
  6. Junio C HamanoOct 23, 2011
  7. Nguyen Thai Ngoc DuyOct 23, 2011
  8. Junio C HamanoOct 23, 2011
  9. Nguyen Thai Ngoc DuyOct 23, 2011
  10. Jeff KingOct 23, 2011
  11. Junio C HamanoOct 23, 2011
  12. Junio C HamanoOct 24, 2011
  13. Nguyen Thai Ngoc DuyOct 24, 2011
  14. Štěpán NěmecOct 24, 2011
  15. Jeff KingOct 24, 2011
  16. Štěpán NěmecOct 25, 2011
  17. Junio C HamanoOct 25, 2011
  18. Jeff KingOct 27, 2011
  19. Junio C HamanoOct 27, 2011
  20. Jeff KingOct 27, 2011
  21. Junio C HamanoOct 27, 2011
  22. Jeff KingOct 27, 2011
  23. Junio C HamanoOct 28, 2011
  24. Jeff KingOct 28, 2011
  25. Miles BaderOct 28, 2011
  26. Junio C HamanoOct 28, 2011

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.