git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Bug Report: Multi-line trailers containing empty lines break parsing
@ 2021-02-15 21:54 Matthias Buehlmann
  2021-02-16  2:29 ` Junio C Hamano
  0 siblings, 1 reply; 12+ messages in thread
From: Matthias Buehlmann @ 2021-02-15 21:54 UTC (permalink / raw)
  To: git

Thank you for filling out a Git bug report!
Please answer the following questions to help us understand your issue.

What did you do before the bug happened? (Steps to reproduce your issue)

    create a file containing multiline trailer:

    $ echo "Test" > test.txt
    $ git interpret-trailers --where end --if-exists addIfDifferent
--trailer "SingleLineTrailer: This is a single line trailer"
--in-place test.txt
    $ git interpret-trailers --where end --if-exists addIfDifferent
--trailer "MultiLineTrailer: This is"$'\n a folded multi-line\n
trailer' --in-place test.txt

    parse trailers:

    $ git interpret-trailers --parse test.txt
    SingleLineTrailer: This is a single line trailer
    MultiLineTrailer: This is a folded multi-line trailer

    (so far, all is as expected)

    now, adding multiline trailer containing empty line:

    $ git interpret-trailers --where end --if-exists addIfDifferent
--trailer "MultiLineTrailer: This is"$'\n a folded multi-line\n
trailer which\n \n contains an\n empty line' --in-place test.txt

    parse trailers again:

    $ git interpret-trailers --parse test.txt

What did you expect to happen? (Expected behavior)

I would expect the following output:

    $ git interpret-trailers --parse test.txt
    SingleLineTrailer: This is a single line trailer
    MultiLineTrailer: This is a folded multi-line trailer
    MultiLineTrailer: This is a folded multi-line trailer which
contains an empty line

What happened instead? (Actual behavior)

    no output is generated, but exit code is nevertheless 0:

    $ git interpret-trailers --parse test.txt
    $ echo $?
    0

What's different between what you expected and what actually happened?

    I would expect either to get an output or the call to exit non-zero

Anything else you want to add:

    According to my interpretation of the documentation of git
intepret-trailers, empty lines should be supported if properly folded,
in the same way as for example the PGP signature added to the commit
header contains a (properly folded) empty line

Please review the rest of the bug report below.
You can delete any lines you don't wish to share.


[System Info]
git version:
git version 2.30.0.windows.2
cpu: x86_64
built from commit: f8cbc844b81bf6b9e72178bbe891a86c8bf5e9e7
sizeof-long: 4
sizeof-size_t: 8
shell-path: /bin/sh
uname: Windows 10.0 18363
compiler info: gnuc: 10.2
libc info: no libc information available
$SHELL (typically, interactive shell): C:\Program Files\Git\usr\bin\bash.exe


[Enabled Hooks]
post-commit

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Bug Report: Multi-line trailers containing empty lines break parsing
  2021-02-15 21:54 Bug Report: Multi-line trailers containing empty lines break parsing Matthias Buehlmann
@ 2021-02-16  2:29 ` Junio C Hamano
  2021-02-16 18:07   ` Taylor Blau
  0 siblings, 1 reply; 12+ messages in thread
From: Junio C Hamano @ 2021-02-16  2:29 UTC (permalink / raw)
  To: Christian Couder; +Cc: git, Matthias Buehlmann

Matthias Buehlmann <Matthias.Buehlmann@mabulous.com> writes:

> Thank you for filling out a Git bug report!
> Please answer the following questions to help us understand your issue.

Thanks; let's ping our resident trailers expert ;-)

I somehow thought that a trailer is always a single-line thing,
without funky line-folding that we have to deal with when we are
dealing with e-mail headers.


> What did you do before the bug happened? (Steps to reproduce your issue)
>
>     create a file containing multiline trailer:
>
>     $ echo "Test" > test.txt
>     $ git interpret-trailers --where end --if-exists addIfDifferent
> --trailer "SingleLineTrailer: This is a single line trailer"
> --in-place test.txt
>     $ git interpret-trailers --where end --if-exists addIfDifferent
> --trailer "MultiLineTrailer: This is"$'\n a folded multi-line\n
> trailer' --in-place test.txt
>
>     parse trailers:
>
>     $ git interpret-trailers --parse test.txt
>     SingleLineTrailer: This is a single line trailer
>     MultiLineTrailer: This is a folded multi-line trailer
>
>     (so far, all is as expected)
>
>     now, adding multiline trailer containing empty line:
>
>     $ git interpret-trailers --where end --if-exists addIfDifferent
> --trailer "MultiLineTrailer: This is"$'\n a folded multi-line\n
> trailer which\n \n contains an\n empty line' --in-place test.txt
>
>     parse trailers again:
>
>     $ git interpret-trailers --parse test.txt
>
> What did you expect to happen? (Expected behavior)
>
> I would expect the following output:
>
>     $ git interpret-trailers --parse test.txt
>     SingleLineTrailer: This is a single line trailer
>     MultiLineTrailer: This is a folded multi-line trailer
>     MultiLineTrailer: This is a folded multi-line trailer which
> contains an empty line
>
> What happened instead? (Actual behavior)
>
>     no output is generated, but exit code is nevertheless 0:
>
>     $ git interpret-trailers --parse test.txt
>     $ echo $?
>     0
>
> What's different between what you expected and what actually happened?
>
>     I would expect either to get an output or the call to exit non-zero
>
> Anything else you want to add:
>
>     According to my interpretation of the documentation of git
> intepret-trailers, empty lines should be supported if properly folded,
> in the same way as for example the PGP signature added to the commit
> header contains a (properly folded) empty line
>
> Please review the rest of the bug report below.
> You can delete any lines you don't wish to share.
>
>
> [System Info]
> git version:
> git version 2.30.0.windows.2
> cpu: x86_64
> built from commit: f8cbc844b81bf6b9e72178bbe891a86c8bf5e9e7
> sizeof-long: 4
> sizeof-size_t: 8
> shell-path: /bin/sh
> uname: Windows 10.0 18363
> compiler info: gnuc: 10.2
> libc info: no libc information available
> $SHELL (typically, interactive shell): C:\Program Files\Git\usr\bin\bash.exe
>
>
> [Enabled Hooks]
> post-commit

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Bug Report: Multi-line trailers containing empty lines break parsing
  2021-02-16  2:29 ` Junio C Hamano
@ 2021-02-16 18:07   ` Taylor Blau
  2021-02-16 19:39     ` Junio C Hamano
  0 siblings, 1 reply; 12+ messages in thread
From: Taylor Blau @ 2021-02-16 18:07 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Christian Couder, git, Matthias Buehlmann, Jonathan Tan

On Mon, Feb 15, 2021 at 06:29:55PM -0800, Junio C Hamano wrote:
> Matthias Buehlmann <Matthias.Buehlmann@mabulous.com> writes:
>
> > Thank you for filling out a Git bug report!
> > Please answer the following questions to help us understand your issue.
>
> Thanks; let's ping our resident trailers expert ;-)

I'm not Christian, but hopefully I'm an OK substitute :).

I originally thought that this was an ambiguous test, since you could
reasonably say the trailers begin after the blank line in the second
"MultiLineTrailer" block. In that case, neither of the following lines
look like a trailer, so 'git interpret-trailers' could reasonably print
nothing.

But I was being tricked, since I looked at "test.txt" in my editor,
which automatically replaces blank lines (zero or more space characters
ending in a newline) with a single newline. In fact, this isn't
ambiguous at all, since the blank lines are continuations (they are a
single space character and then a newline):

		00000090  65 64 20 6d 75 6c 74 69  2d 6c 69 6e 65 0a 20 74  |ed multi-line. t|
		000000a0  72 61 69 6c 65 72 20 77  68 69 63 68 0a 20 0a 20  |railer which. . |

(see the repeated '0a 20' space + newline pair after "which").

I think that this is a legitimate bug in 'interpret-trailers' that it
doesn't know to continue multi-line trailers that have empty lines in
them.

I thought that this might have dated back to 022349c3b0 (trailer: avoid
unnecessary splitting on lines, 2016-11-02), but checking out that
commit's first parent shows the bug (albeit without --parse, which
didn't exist then).

Anyway, I'm pretty sure the problem is that
trailer.c:find_trailer_start() doesn't disambiguate between a blank line
and one that contains only space characters.

This patch might do the trick:

--- 8< ---

Subject: [PATCH] trailer.c: handle empty continuation lines

In a multi-line trailer, it is possible to have a continuation line
which contains at least one space character, terminating in a newline.

In this case, the trailer should continue across the blank continuation
line, but 'trailer.c:find_trailer_start()' handles this case
incorrectly.

When it encounters a blank line, find_trailer_start() assumes that the
trailers must begin on the line following the one it's looking at. But
this isn't the case if the line is a non-empty continuation, in which
the line may be part of a trailer.

Fix this by only considering a blank line which has exactly zero space
characters before the LF as delimiting the start of trailers.

Reported-by: Matthias Buehlmann <Matthias.Buehlmann@mabulous.com>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
 t/t7513-interpret-trailers.sh | 23 +++++++++++++++++++++++
 trailer.c                     |  2 +-
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/t/t7513-interpret-trailers.sh b/t/t7513-interpret-trailers.sh
index 6602790b5f..af602ff329 100755
--- a/t/t7513-interpret-trailers.sh
+++ b/t/t7513-interpret-trailers.sh
@@ -1476,4 +1476,27 @@ test_expect_success 'suppress --- handling' '
 	test_cmp expected actual
 '

+test_expect_success 'handling of empty continuations lines' '
+	tr _ " " >input <<-\EOF &&
+	subject
+
+	body
+
+	trailer: single
+	multi: one
+	_two
+	multi: one
+	_
+	_two
+	_three
+	EOF
+	cat >expect <<-\EOF &&
+	trailer: single
+	multi: one two
+	multi: one two three
+	EOF
+	git interpret-trailers --parse <input >actual &&
+	test_cmp expect actual
+'
+
 test_done
diff --git a/trailer.c b/trailer.c
index 249ed618ed..7ca7200aec 100644
--- a/trailer.c
+++ b/trailer.c
@@ -846,7 +846,7 @@ static size_t find_trailer_start(const char *buf, size_t len)
 			possible_continuation_lines = 0;
 			continue;
 		}
-		if (is_blank_line(bol)) {
+		if (is_blank_line(bol) && *bol == '\n') {
 			if (only_spaces)
 				continue;
 			non_trailer_lines += possible_continuation_lines;
--
2.30.0.667.g81c0cbc6fd


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: Bug Report: Multi-line trailers containing empty lines break parsing
  2021-02-16 18:07   ` Taylor Blau
@ 2021-02-16 19:39     ` Junio C Hamano
  2021-02-16 19:47       ` Taylor Blau
  0 siblings, 1 reply; 12+ messages in thread
From: Junio C Hamano @ 2021-02-16 19:39 UTC (permalink / raw)
  To: Taylor Blau; +Cc: Christian Couder, git, Matthias Buehlmann, Jonathan Tan

Taylor Blau <me@ttaylorr.com> writes:

> Anyway, I'm pretty sure the problem is that
> trailer.c:find_trailer_start() doesn't disambiguate between a blank line
> and one that contains only space characters.

I saw that while reviewing another topic the other day and found it
a bit strange, but kept it as I thought it was deliberate and the
behaviour (i.e. a line with only blanks and a line that is empty are
treated the same) was protected with some tests, but looking at your
patch below, I guess there is no such test.

> When it encounters a blank line, find_trailer_start() assumes that the
> trailers must begin on the line following the one it's looking at. But
> this isn't the case if the line is a non-empty continuation, in which
> the line may be part of a trailer.
>
> Fix this by only considering a blank line which has exactly zero space
> characters before the LF as delimiting the start of trailers.

Hmph...

> +test_expect_success 'handling of empty continuations lines' '
> +	tr _ " " >input <<-\EOF &&
> +	subject
> +
> +	body
> +
> +	trailer: single
> +	multi: one
> +	_two
> +	multi: one
> +	_
> +	_two
> +	_three
> +	EOF
> +	cat >expect <<-\EOF &&
> +	trailer: single
> +	multi: one two
> +	multi: one two three
> +	EOF
> +	git interpret-trailers --parse <input >actual &&
> +	test_cmp expect actual
> +'

A few comments (not pointing out bugs, but just sharing
observations).

 - if the line before "trailer: single" were not an empty line but a
   line with a single SP on it (which is is_blank_line()), would the
   new logic get confused?

 - if the second "multi:" trailer did not have the funny blank line
   before "_two", the expected output would still be "multi:"
   followed by "one two three", iow, the line after the second
   "multi: one" is a total no-op?  If we added many more " \n" lines
   there, they are all absorbed and ignored?  It somehow feels wrong

> diff --git a/trailer.c b/trailer.c
> index 249ed618ed..7ca7200aec 100644
> --- a/trailer.c
> +++ b/trailer.c
> @@ -846,7 +846,7 @@ static size_t find_trailer_start(const char *buf, size_t len)
>  			possible_continuation_lines = 0;
>  			continue;
>  		}
> -		if (is_blank_line(bol)) {
> +		if (is_blank_line(bol) && *bol == '\n') {
>  			if (only_spaces)
>  				continue;
>  			non_trailer_lines += possible_continuation_lines;
> --
> 2.30.0.667.g81c0cbc6fd

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Bug Report: Multi-line trailers containing empty lines break parsing
  2021-02-16 19:39     ` Junio C Hamano
@ 2021-02-16 19:47       ` Taylor Blau
  2021-03-23 15:17         ` Christian Couder
  0 siblings, 1 reply; 12+ messages in thread
From: Taylor Blau @ 2021-02-16 19:47 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Taylor Blau, Christian Couder, git, Matthias Buehlmann, Jonathan Tan

On Tue, Feb 16, 2021 at 11:39:00AM -0800, Junio C Hamano wrote:
> A few comments (not pointing out bugs, but just sharing
> observations).
>
>  - if the line before "trailer: single" were not an empty line but a
>    line with a single SP on it (which is is_blank_line()), would the
>    new logic get confused?

Oof. That breaks the new test, but it makes me worried about whether
this can be parsed without ambiguity. I think not, but here I'd defer to
Christian or Jonathan Tan.

>  - if the second "multi:" trailer did not have the funny blank line
>    before "_two", the expected output would still be "multi:"
>    followed by "one two three", iow, the line after the second
>    "multi: one" is a total no-op?  If we added many more " \n" lines
>    there, they are all absorbed and ignored?  It somehow feels wrong

That's definitely the outcome of this patch, but I agree it feels wrong.
I'm not sure that we define the behavior that strictly in
git-interpret-trailers(1), so we have some wiggle room, I guess.

Thanks,
Taylor

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Bug Report: Multi-line trailers containing empty lines break parsing
  2021-02-16 19:47       ` Taylor Blau
@ 2021-03-23 15:17         ` Christian Couder
  2021-03-23 17:39           ` Junio C Hamano
  0 siblings, 1 reply; 12+ messages in thread
From: Christian Couder @ 2021-03-23 15:17 UTC (permalink / raw)
  To: Taylor Blau; +Cc: Junio C Hamano, git, Matthias Buehlmann, Jonathan Tan

On Tue, Feb 16, 2021 at 8:47 PM Taylor Blau <me@ttaylorr.com> wrote:
>
> On Tue, Feb 16, 2021 at 11:39:00AM -0800, Junio C Hamano wrote:
> > A few comments (not pointing out bugs, but just sharing
> > observations).
> >
> >  - if the line before "trailer: single" were not an empty line but a
> >    line with a single SP on it (which is is_blank_line()), would the
> >    new logic get confused?
>
> Oof. That breaks the new test, but it makes me worried about whether
> this can be parsed without ambiguity. I think not, but here I'd defer to
> Christian or Jonathan Tan.

Sorry for the late answer on this. It looks like this fell into my
email reading cracks.

My opinion, when I worked on this, was that it's very difficult to
avoid ambiguity, so it's better if `git interpret-trailers` is strict
by default, which could be relaxed later in special cases where there
is not much risk of ambiguity.

It's especially ambiguous because many commit message subjects or even
bodies can be of the form "area: change" which can look like a
trailer. And some people might want to process whole commit messages,
while others might want to process templates that might contain only
trailers.

So I thought that blank lines should not appear in the trailers. And
if any appears, it means that the trailers should start after the last
blank line. This might actually have been already relaxed a bit.

> >  - if the second "multi:" trailer did not have the funny blank line
> >    before "_two", the expected output would still be "multi:"
> >    followed by "one two three", iow, the line after the second
> >    "multi: one" is a total no-op?  If we added many more " \n" lines
> >    there, they are all absorbed and ignored?  It somehow feels wrong
>
> That's definitely the outcome of this patch, but I agree it feels wrong.
> I'm not sure that we define the behavior that strictly in
> git-interpret-trailers(1), so we have some wiggle room, I guess.

Any patch to relax how blank lines and other aspects of trailers
parsing in my opinion should come with some documentation change to
explain what we now accept and what we don't accept, and also tests to
enforce that.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Bug Report: Multi-line trailers containing empty lines break parsing
  2021-03-23 15:17         ` Christian Couder
@ 2021-03-23 17:39           ` Junio C Hamano
  2021-03-25  7:53             ` Christian Couder
  0 siblings, 1 reply; 12+ messages in thread
From: Junio C Hamano @ 2021-03-23 17:39 UTC (permalink / raw)
  To: Christian Couder; +Cc: Taylor Blau, git, Matthias Buehlmann, Jonathan Tan

Christian Couder <christian.couder@gmail.com> writes:

> So I thought that blank lines should not appear in the trailers. And
> if any appears, it means that the trailers should start after the last
> blank line.

I think that is a good principle to stick to.

>> >  - if the second "multi:" trailer did not have the funny blank line
>> >    before "_two", the expected output would still be "multi:"
>> >    followed by "one two three", iow, the line after the second
>> >    "multi: one" is a total no-op?  If we added many more " \n" lines
>> >    there, they are all absorbed and ignored?  It somehow feels wrong
>>
>> That's definitely the outcome of this patch, but I agree it feels wrong.
>> I'm not sure that we define the behavior that strictly in
>> git-interpret-trailers(1), so we have some wiggle room, I guess.
>
> Any patch to relax how blank lines and other aspects of trailers
> parsing in my opinion should come with some documentation change to
> explain what we now accept and what we don't accept, and also tests to
> enforce that.

OK.  But do we document clearly what we accept and we don't before
any change?


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Bug Report: Multi-line trailers containing empty lines break parsing
  2021-03-23 17:39           ` Junio C Hamano
@ 2021-03-25  7:53             ` Christian Couder
  2021-03-25  9:33               ` ZheNing Hu
  2021-03-25 18:08               ` Junio C Hamano
  0 siblings, 2 replies; 12+ messages in thread
From: Christian Couder @ 2021-03-25  7:53 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Taylor Blau, git, Matthias Buehlmann, Jonathan Tan

On Tue, Mar 23, 2021 at 6:39 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> Christian Couder <christian.couder@gmail.com> writes:
>
> > So I thought that blank lines should not appear in the trailers. And
> > if any appears, it means that the trailers should start after the last
> > blank line.
>
> I think that is a good principle to stick to.
>
> >> >  - if the second "multi:" trailer did not have the funny blank line
> >> >    before "_two", the expected output would still be "multi:"
> >> >    followed by "one two three", iow, the line after the second
> >> >    "multi: one" is a total no-op?  If we added many more " \n" lines
> >> >    there, they are all absorbed and ignored?  It somehow feels wrong
> >>
> >> That's definitely the outcome of this patch, but I agree it feels wrong.
> >> I'm not sure that we define the behavior that strictly in
> >> git-interpret-trailers(1), so we have some wiggle room, I guess.
> >
> > Any patch to relax how blank lines and other aspects of trailers
> > parsing in my opinion should come with some documentation change to
> > explain what we now accept and what we don't accept, and also tests to
> > enforce that.
>
> OK.  But do we document clearly what we accept and we don't before
> any change?

Maybe it's not enough, but the doc already has the following:

------
Existing trailers are extracted from the input message by looking for
a group of one or more lines that (i) is all trailers, or (ii) contains at
least one Git-generated or user-configured trailer and consists of at
least 25% trailers.
The group must be preceded by one or more empty (or whitespace-only) lines.
The group must either be at the end of the message or be the last
non-whitespace lines before a line that starts with '---' (followed by a
space or the end of the line). Such three minus signs start the patch
part of the message. See also `--no-divider` below.

When reading trailers, there can be whitespaces after the
token, the separator and the value. There can also be whitespaces
inside the token and the value. The value may be split over multiple lines with
each subsequent line starting with whitespace, like the "folding" in RFC 822.
------

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Bug Report: Multi-line trailers containing empty lines break parsing
  2021-03-25  7:53             ` Christian Couder
@ 2021-03-25  9:33               ` ZheNing Hu
  2021-03-25 18:16                 ` Junio C Hamano
  2021-03-25 18:08               ` Junio C Hamano
  1 sibling, 1 reply; 12+ messages in thread
From: ZheNing Hu @ 2021-03-25  9:33 UTC (permalink / raw)
  To: Christian Couder
  Cc: Junio C Hamano, Taylor Blau, git, Matthias Buehlmann, Jonathan Tan

Christian Couder <christian.couder@gmail.com> 于2021年3月25日周四 下午3:54写道:
>
> On Tue, Mar 23, 2021 at 6:39 PM Junio C Hamano <gitster@pobox.com> wrote:
> >
> > Christian Couder <christian.couder@gmail.com> writes:
> >
> > > So I thought that blank lines should not appear in the trailers. And
> > > if any appears, it means that the trailers should start after the last
> > > blank line.
> >
> > I think that is a good principle to stick to.
> >
> > >> >  - if the second "multi:" trailer did not have the funny blank line
> > >> >    before "_two", the expected output would still be "multi:"
> > >> >    followed by "one two three", iow, the line after the second
> > >> >    "multi: one" is a total no-op?  If we added many more " \n" lines
> > >> >    there, they are all absorbed and ignored?  It somehow feels wrong
> > >>
> > >> That's definitely the outcome of this patch, but I agree it feels wrong.
> > >> I'm not sure that we define the behavior that strictly in
> > >> git-interpret-trailers(1), so we have some wiggle room, I guess.
> > >
> > > Any patch to relax how blank lines and other aspects of trailers
> > > parsing in my opinion should come with some documentation change to
> > > explain what we now accept and what we don't accept, and also tests to
> > > enforce that.
> >
> > OK.  But do we document clearly what we accept and we don't before
> > any change?
>
> Maybe it's not enough, but the doc already has the following:
>
> ------
> Existing trailers are extracted from the input message by looking for
> a group of one or more lines that (i) is all trailers, or (ii) contains at
> least one Git-generated or user-configured trailer and consists of at
> least 25% trailers.
> The group must be preceded by one or more empty (or whitespace-only) lines.
> The group must either be at the end of the message or be the last
> non-whitespace lines before a line that starts with '---' (followed by a
> space or the end of the line). Such three minus signs start the patch
> part of the message. See also `--no-divider` below.
>
> When reading trailers, there can be whitespaces after the
> token, the separator and the value. There can also be whitespaces
> inside the token and the value. The value may be split over multiple lines with
> each subsequent line starting with whitespace, like the "folding" in RFC 822.
> ------


Maybe I don't have enough right to speak on this issue, but I always think that
 the empty line is intentional by the designer, especially when I test it.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Bug Report: Multi-line trailers containing empty lines break parsing
  2021-03-25  7:53             ` Christian Couder
  2021-03-25  9:33               ` ZheNing Hu
@ 2021-03-25 18:08               ` Junio C Hamano
  1 sibling, 0 replies; 12+ messages in thread
From: Junio C Hamano @ 2021-03-25 18:08 UTC (permalink / raw)
  To: Christian Couder; +Cc: Taylor Blau, git, Matthias Buehlmann, Jonathan Tan

Christian Couder <christian.couder@gmail.com> writes:

>> > Any patch to relax how blank lines and other aspects of trailers
>> > parsing in my opinion should come with some documentation change to
>> > explain what we now accept and what we don't accept, and also tests to
>> > enforce that.
>>
>> OK.  But do we document clearly what we accept and we don't before
>> any change?
>
> Maybe it's not enough, but the doc already has the following:

OK.

The next step is to find out if there is anything unclear in the
description of the current behaviour in that paragraph that may have
resulted in the report of the "bug" that turned out to be a non-bug.

> ------
> Existing trailers are extracted from the input message by looking for
> a group of one or more lines that (i) is all trailers, or (ii) contains at
> least one Git-generated or user-configured trailer and consists of at
> least 25% trailers.
> The group must be preceded by one or more empty (or whitespace-only) lines.
> The group must either be at the end of the message or be the last
> non-whitespace lines before a line that starts with '---' (followed by a
> space or the end of the line). Such three minus signs start the patch
> part of the message. See also `--no-divider` below.
>
> When reading trailers, there can be whitespaces after the
> token, the separator and the value. There can also be whitespaces
> inside the token and the value. The value may be split over multiple lines with
> each subsequent line starting with whitespace, like the "folding" in RFC 822.
> ------

Thanks.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Bug Report: Multi-line trailers containing empty lines break parsing
  2021-03-25  9:33               ` ZheNing Hu
@ 2021-03-25 18:16                 ` Junio C Hamano
  2021-03-26 10:25                   ` ZheNing Hu
  0 siblings, 1 reply; 12+ messages in thread
From: Junio C Hamano @ 2021-03-25 18:16 UTC (permalink / raw)
  To: ZheNing Hu
  Cc: Christian Couder, Taylor Blau, git, Matthias Buehlmann, Jonathan Tan

ZheNing Hu <adlternative@gmail.com> writes:

> Christian Couder <christian.couder@gmail.com> 于2021年3月25日周四 下午3:54写道:
>>
>> Maybe it's not enough, but the doc already has the following:
>>
>> ------
>> Existing trailers are extracted from the input message by looking for
>> a group of one or more lines that (i) is all trailers, or (ii) contains at
>> least one Git-generated or user-configured trailer and consists of at
>> least 25% trailers.
>> The group must be preceded by one or more empty (or whitespace-only) lines.
>> The group must either be at the end of the message or be the last
>> non-whitespace lines before a line that starts with '---' (followed by a
>> space or the end of the line). Such three minus signs start the patch
>> part of the message. See also `--no-divider` below.
>>
>> When reading trailers, there can be whitespaces after the
>> token, the separator and the value. There can also be whitespaces
>> inside the token and the value. The value may be split over multiple lines with
>> each subsequent line starting with whitespace, like the "folding" in RFC 822.
>> ------
>
>
> Maybe I don't have enough right to speak on this issue, but I always think that
>  the empty line is intentional by the designer, especially when I test it.

People like you, who is relatively new to the system and the list,
are valuable source of information for us to learn where in the
current system and documentation we have room to improve and
clarify.  You do have right, and we welcome your input.

Care to clarify what you mean by "the empty line is intentional by
the designer"?  The designer of the current "trailer" intended to
make the "last paragraph" (where "paragraph" is defined as a run of
lines without an empty line in it, so that one or more continguous
empty lines separate "paragraphs") where the trailers sit in the log
message.  Is that what you mean?  Or something else?

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Bug Report: Multi-line trailers containing empty lines break parsing
  2021-03-25 18:16                 ` Junio C Hamano
@ 2021-03-26 10:25                   ` ZheNing Hu
  0 siblings, 0 replies; 12+ messages in thread
From: ZheNing Hu @ 2021-03-26 10:25 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Christian Couder, Taylor Blau, git, Matthias Buehlmann, Jonathan Tan

Junio C Hamano <gitster@pobox.com> 于2021年3月26日周五 上午2:16写道:
>
> ZheNing Hu <adlternative@gmail.com> writes:
>
> > Christian Couder <christian.couder@gmail.com> 于2021年3月25日周四 下午3:54写道:
> >>
> >> Maybe it's not enough, but the doc already has the following:
> >>
> >> ------
> >> Existing trailers are extracted from the input message by looking for
> >> a group of one or more lines that (i) is all trailers, or (ii) contains at
> >> least one Git-generated or user-configured trailer and consists of at
> >> least 25% trailers.
> >> The group must be preceded by one or more empty (or whitespace-only) lines.
> >> The group must either be at the end of the message or be the last
> >> non-whitespace lines before a line that starts with '---' (followed by a
> >> space or the end of the line). Such three minus signs start the patch
> >> part of the message. See also `--no-divider` below.
> >>
> >> When reading trailers, there can be whitespaces after the
> >> token, the separator and the value. There can also be whitespaces
> >> inside the token and the value. The value may be split over multiple lines with
> >> each subsequent line starting with whitespace, like the "folding" in RFC 822.
> >> ------
> >
> >
> > Maybe I don't have enough right to speak on this issue, but I always think that
> >  the empty line is intentional by the designer, especially when I test it.
>
> People like you, who is relatively new to the system and the list,
> are valuable source of information for us to learn where in the
> current system and documentation we have room to improve and
> clarify.  You do have right, and we welcome your input.
>

Thanks:)

> Care to clarify what you mean by "the empty line is intentional by
> the designer"?  The designer of the current "trailer" intended to
> make the "last paragraph" (where "paragraph" is defined as a run of
> lines without an empty line in it, so that one or more continguous
> empty lines separate "paragraphs") where the trailers sit in the log
> message.  Is that what you mean?  Or something else?

Emmm, I mean generally speaking, the entire commit infomations is divided into
three paragraphs: "subject"/"message"/"trailers".

When we use `--parse` to get those trailers, normally it can indeed be obtained,
But if in the middle of the trailers have a extra empty lines or lines with only
whitespaces, All trailers before the blank line will be discarded, I think it is
acceptable.Because It seems that the previous content belongs to the message
section.

Like this:
------
(subject)

First paragraph:
hello world

Second paragraph:
what happen if some thing like

this: Use git to commit code to git

Signed-off-by: CoCo <cc@gg.com>
Deleted-by: ADL <a@gg.com>
-----

"this: Use git to commit code to git" seem like a trailer,
but it's user's message.

So I think the purpose of these blank lines is to separate the
three parts of the commit information. It is normal for the blank
lines inside trailers to cause ambiguity.

Please correct me if I what I said is wrong.
--
ZheNing Hu

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2021-03-26 10:26 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-15 21:54 Bug Report: Multi-line trailers containing empty lines break parsing Matthias Buehlmann
2021-02-16  2:29 ` Junio C Hamano
2021-02-16 18:07   ` Taylor Blau
2021-02-16 19:39     ` Junio C Hamano
2021-02-16 19:47       ` Taylor Blau
2021-03-23 15:17         ` Christian Couder
2021-03-23 17:39           ` Junio C Hamano
2021-03-25  7:53             ` Christian Couder
2021-03-25  9:33               ` ZheNing Hu
2021-03-25 18:16                 ` Junio C Hamano
2021-03-26 10:25                   ` ZheNing Hu
2021-03-25 18:08               ` Junio C Hamano

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).