git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Anton Mitterer <calestyo@scientia.org>
To: Kristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com>,
	 git@vger.kernel.org
Subject: Re: git format-patch escaping issues in the patch format
Date: Tue, 05 Nov 2024 02:26:00 +0100	[thread overview]
Message-ID: <83639e75d9d04208aa0dee345d9ef3536de105c9.camel@scientia.org> (raw)
In-Reply-To: <305dc9f7-4bdb-40c5-92f4-7438a9ecd482@app.fastmail.com>

On Mon, 2024-11-04 at 23:15 +0100, Kristoffer Haugsbakk wrote:
> It seems to me (totally naïve) that you would do something like
> 
> 1. Blank line terminates headers
> 2. Then there might be some optional commit-headers which can
> override
>    things (`From`)
> 3. Commit message
> 4. `---`
> 5. Look for a regex `^diff` line
>    • Now the indentation will tell you when it ends
> 6. `^Range-diff` and `^Interdiff` can also make an appearance in this
>    section

Well as you've seen by the follow-up, such a naive approach is not
really possible, as the commit message may also contain ---, unified
diffs, etc.



> At first I thought that it is a magic string for a reason.

I think such magic cookies can always only (safely) be used to detect a
type, but not as a separator, at least not when free text is allowed,
too.


> It did the right thing for me with this (last part) of the commit
> message:
> 
>     We should look into Pedro’s backup system.  Why does he use
> email?
> 
>         diff --git a/a.txt b/a.txt
>         index ce01362503..a32119c8aa 100644
>         --- a/a.txt
>         +++ b/a.txt
>         @@ -1 +1,2 @@
>          hello
>         +goodbye
> 
> ***

But yours look indented? I mean then it's clear it works.


> It seems like it would be nice if format-patch complained if it found
> regex `^---$` in the commit body.

Actually already when committing... cause there it's taken as valid and
then it should also work with any following tools.


> The magic string is unlikely but could happen.  The solution is to
> use
> an indented block.  Same for the diff.  (Hopefully few have to
> code-quote diffs)

As written in the other mail, there is nothing real obvious for the
user that this wouldn’t be allowed, and in fact committing and such
works.
The simple problem here is the fuzzy format which cannot be parsed
properly.




> But escaping things in this format?

Coudln't one do something like this:

If the line consisting of three - is the line that ends the commit
message, check during format-patch whether it's contained in that.
If not, generate the patch as now.
If so, use another magic timestamp and/or (since that might get lost
when sending as mail, set some X-git-patch-format: header, there adding
perhaps a flag like "escaped" and if that's set, any line that matches
the regexp:
>*---
get's another > prepended when escaping, and one removed when
unescaping (well in the latter only lines that match >+---).
* = 0..n
+ = 1..n

Or probably thinking about some more sophisticated solution or at least
a better character than > .


> > btw and shamelessly off-topic question:
> > Any chance that git format-patch / am will ever support keeping
> > track
> > of the branch/merge history of generated / applied patches?
> > That would be really neat.
> 
> What does this mean more concretely?  :)

I guess I want what's been asked there:
https://stackoverflow.com/questions/2285699/git-how-to-create-patches-for-a-merge


In short, imagine I have the following commit tree (just a simple
example with --no-ff):
*
|\
|*
|/
*

And I make a series of git format-patch patches from that, it would be
nice if git am *.patches, give back that structure (i.e. with the
branch and the merge).


Cheers,
Chris.

  reply	other threads:[~2024-11-05  1:26 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-04 19:24 git format-patch escaping issues in the patch format Christoph Anton Mitterer
2024-11-04 22:15 ` Kristoffer Haugsbakk
2024-11-05  1:26   ` Christoph Anton Mitterer [this message]
2024-11-05 14:32     ` Kristoffer Haugsbakk
2024-11-05 15:02       ` Christoph Anton Mitterer
2024-11-04 23:54 ` Jeff King
2024-11-05  1:03   ` Christoph Anton Mitterer
2024-11-05 15:05     ` Jeff King
2024-11-05  0:22 ` Junio C Hamano
2024-11-05  1:01   ` Christoph Anton Mitterer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=83639e75d9d04208aa0dee345d9ef3536de105c9.camel@scientia.org \
    --to=calestyo@scientia.org \
    --cc=git@vger.kernel.org \
    --cc=kristofferhaugsbakk@fastmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).