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

Re: git format-patch escaping issues in the patch format

From
Jeff King <peff@peff.net>
Date
Nov 5, 2024, 15:05 UTC
Message-ID
<20241105150540.GA3043294@coredump.intra.peff.net>
In-Reply-To
<3a96888e76e4dd26a3b0a81a19cda8ec7de72662.camel@scientia.org>
On Tue, Nov 05, 2024 at 02:03:21AM +0100, Christoph Anton Mitterer wrote:
Show 10 quoted lines
> On Mon, 2024-11-04 at 18:54 -0500, Jeff King wrote:
> > As you note, the mbox format is not well defined. :) The variant with
> > ">"-quoting of "From" lines is often called "mboxrd", and you can get
> > it
> > with the "--format=mboxrd" option.
> 
> But as you've said below, here too, the receiving side most likely
> doesn’t know that and then a wrong commit message would be applied
> (with no unescaping being performed or it would simply break again when
> the magic From is used).
I think there are two differences between ">From" and quote "---":
  1. There are already mbox parsers that understand and unquote ">From".
     If you know you are feeding your patches to such a parser (e.g.,
     the one in mutt) then using "mboxrd" makes sense.
  2. The consumer of the mbox format is much "closer" than the consumer
     of the "---" line.
     If you produce some patches with format-patch, you might feed them
     to your MUA or another local tool, and you know how that tool will
     unquote them. Once you email the patches, that ">From" quoting is
     irrelevant, because the receiver will get individual emails without
     the quoting. They may themselves choose to store them in an mbox,
     of course, but the details are up to them.
     Whereas the "---" line is inside the email, and will be interpreted
     on the other end by a tool like "git am". So if we introduce
     quoting in format-patch and unquoting in git-am, then correctly
     unquoting will depend on the version that the other side is using.

IMHO that is not necessarily a reason to avoid implementing quoting. If you do accidentally put "---" in a commit message, the current outcome is for your commit message to get silently cut off by "git am". But in a world where we quote it and the other side is too old to unquote, then they may end up with an extra quoting character in the result. But that is probably a less bad outcome overall.

  There's also another flip-side mistake, which is somebody who doesn't
  quote sends to somebody who unquotes, and the result is similarly
  slightly corrupted. The mbox equivalent is that you meant to say
  ">From" with the ">", but the receiver turned it into just "From".

So I don't think it's a totally wrong direction to go. But like I said, it doesn't seem to happen often enough in practice that anybody has been motivated to add the feature.

-Peff
Previous: Christoph Anton MittererNext: Junio C Hamano
Message 8 of 10 in “git format-patch escaping issues in the patch format”
  1. Christoph Anton MittererNov 4, 2024
  2. Kristoffer HaugsbakkNov 4, 2024
  3. Christoph Anton MittererNov 5, 2024
  4. Kristoffer HaugsbakkNov 5, 2024
  5. Christoph Anton MittererNov 5, 2024
  6. Jeff KingNov 4, 2024
  7. Christoph Anton MittererNov 5, 2024
  8. Jeff KingNov 5, 2024
  9. Junio C HamanoNov 5, 2024
  10. Christoph Anton MittererNov 5, 2024

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.