# [bug (maybe)] Applying patch with '---'

3 messages from 2015-04-01 to 2015-04-01. Participants: Chris Packham, Junio C Hamano.
Thread: https://gitlist.dev/t/38969

## Chris Packham, 2015-04-01 02:37

Subject: [bug (maybe)] Applying patch with '---'
Message-ID: <CAFOYHZC6Qd9wkoWPcTJDxAs9u=FGpHQTkjE-guhwkya0DRVA6g@mail.gmail.com>
URL: https://gitlist.dev/e/CAFOYHZC6Qd9wkoWPcTJDxAs9u%3DFGpHQTkjE-guhwkya0DRVA6g%40mail.gmail.com

```
Hi List,

So I was just sent a patch generated with 'git format-patch' that 'git
am' fails to apply correctly. It applies but part of the commit
message is lost.

The problem is that the commit message has lines like

--- Foo happened
    did some things to handle Foo
--- Bar happened
    Still processing update from Foo which led to a crash

git mailinfo seems to discard everything after the first '--- Blah'. I
know ^---$ is special but I thought ^---.+$ would be OK. I know git
mailinfo shouldn't handle garbage input but I guess the problem I have
is that the patch was generated by git format-patch so surely git
mailinfo (and therefore git am) _should_ handle something generated by
generated by git format-patch.

Do people agree with my thinking? I'm not sure if it would be
appropriate for git format-patch to produce a warning or for git
mailinfo to tighten the matching of '---'.

Regards,
Chris

```

## Junio C Hamano, 2015-04-01 06:20

Subject: Re: [bug (maybe)] Applying patch with '---'
Message-ID: <xmqqy4mcmkt2.fsf@gitster.dls.corp.google.com>
URL: https://gitlist.dev/e/xmqqy4mcmkt2.fsf%40gitster.dls.corp.google.com
In-Reply-To: <CAFOYHZC6Qd9wkoWPcTJDxAs9u=FGpHQTkjE-guhwkya0DRVA6g@mail.gmail.com>

```
Chris Packham <judge.packham@gmail.com> writes:

> So I was just sent a patch generated with 'git format-patch' that 'git
> am' fails to apply correctly. It applies but part of the commit
> message is lost.
>
> The problem is that the commit message has lines like
>
> --- Foo happened
>     did some things to handle Foo
> --- Bar happened
>     Still processing update from Foo which led to a crash
>
> git mailinfo seems to discard everything after the first '--- Blah'.

Yes, this is well known.  So is a line that begins with "diff --git"
makes mailinfo to guess that it is the end of the log message.

> ... I know git
> mailinfo shouldn't handle garbage input but I guess the problem I have
> is that the patch was generated by git format-patch ...

Whatever message you write format-patch emits without escaping, so
"patch was generated by format-patch" does not guarantee anything,
unfortunately.  A related similar issue is that a line that begins
with "From " may be corrupted into a line that begins with ">From "
by the time the message hits your mailbox.  These are unfortunately
something you have to know and long-time users learned to avoid
doing so unconsciously ;-).

```

## Chris Packham, 2015-04-01 08:06

Subject: Re: [bug (maybe)] Applying patch with '---'
Message-ID: <CAFOYHZDYcF0=kH=L2CZ5=4DBUaGoJihVE9J=s=uuoJQhGGd5yA@mail.gmail.com>
URL: https://gitlist.dev/e/CAFOYHZDYcF0%3DkH%3DL2CZ5%3D4DBUaGoJihVE9J%3Ds%3DuuoJQhGGd5yA%40mail.gmail.com
In-Reply-To: <xmqqy4mcmkt2.fsf@gitster.dls.corp.google.com>

```
On Wed, Apr 1, 2015 at 7:20 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Chris Packham <judge.packham@gmail.com> writes:
>
>> So I was just sent a patch generated with 'git format-patch' that 'git
>> am' fails to apply correctly. It applies but part of the commit
>> message is lost.
>>
>> The problem is that the commit message has lines like
>>
>> --- Foo happened
>>     did some things to handle Foo
>> --- Bar happened
>>     Still processing update from Foo which led to a crash
>>
>> git mailinfo seems to discard everything after the first '--- Blah'.
>
> Yes, this is well known.  So is a line that begins with "diff --git"
> makes mailinfo to guess that it is the end of the log message.
>

So it looks like code in mailinfo.c to handle

  --- a/file
  +++ b/file

Also interprets

  --- Blah
  more text

as the start of the patch portion. Perhaps mailinfo could search for
both the --- and +++ lines before deciding it's the patch portion has
started. Or search for "diff -" first and work backwards towards to
drop text up to the "---".

>> ... I know git
>> mailinfo shouldn't handle garbage input but I guess the problem I have
>> is that the patch was generated by git format-patch ...
>
> Whatever message you write format-patch emits without escaping, so
> "patch was generated by format-patch" does not guarantee anything,
> unfortunately.  A related similar issue is that a line that begins
> with "From " may be corrupted into a line that begins with ">From "
> by the time the message hits your mailbox.  These are unfortunately
> something you have to know and long-time users learned to avoid
> doing so unconsciously ;-).

So perhaps the newer users need some training wheels built into
format-patch :). It'd actually annoy me if it was too intrusive as I
actually use --- as a light weight alternative to git-notes for
commentary I want to include with a patch submission.  But a message
saying "if you send this verbatim commit message text will be lost"
would at least let the user know that something needs attention .

```
