All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Fix 'git am' in-body header continuations
@ 2017-04-03  0:49 Linus Torvalds
  2017-04-03 18:00 ` Jonathan Tan
  0 siblings, 1 reply; 3+ messages in thread
From: Linus Torvalds @ 2017-04-03  0:49 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Jonathan Tan, Jeff King, Git Mailing List


From: Linus Torvalds <torvalds@linux-foundation.org>
Date: Sat, 1 Apr 2017 12:14:39 -0700
Subject: [PATCH] Fix 'git am' in-body header continuations

An empty line should stop any pending in-body headers, and start the
actual body parsing.

This also modifies the original test for the in-body headers to actually
have a real commit body that starts with spaces, and changes the test to
check that the long line matches _exactly_, and doesn't get extra data
from the body.

Fixes:6b4b013f1884 ("mailinfo: handle in-body header continuations")
Cc: Jonathan Tan <jonathantanmy@google.com>
Cc: Jeff King <peff@peff.net>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
---

On Sun, 2 Apr 2017, Junio C Hamano wrote:
> 
> And that is exactly your patch does.  The change "feels" correct to
> me.

Ok, resent with the test-case for the original behavior changed to be 
stricter (so it fails without this fix), and with Signed-off lines etc.

I didn't really test the test-case very much, but it seemed to fail 
without this patch (because the "Body test" thing from the body becomes 
part of the long first line), and passes with it.

But somebody who is more used to the test-suite should double-check my 
stupid test edit.

 mailinfo.c    | 7 ++++++-
 t/t4150-am.sh | 6 ++++--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/mailinfo.c b/mailinfo.c
index a489d9d0f..68037758f 100644
--- a/mailinfo.c
+++ b/mailinfo.c
@@ -757,8 +757,13 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
 	assert(!mi->filter_stage);
 
 	if (mi->header_stage) {
-		if (!line->len || (line->len == 1 && line->buf[0] == '\n'))
+		if (!line->len || (line->len == 1 && line->buf[0] == '\n')) {
+			if (mi->inbody_header_accum.len) {
+				flush_inbody_header_accum(mi);
+				mi->header_stage = 0;
+			}
 			return 0;
+		}
 	}
 
 	if (mi->use_inbody_headers && mi->header_stage) {
diff --git a/t/t4150-am.sh b/t/t4150-am.sh
index 89a5bacac..44807e218 100755
--- a/t/t4150-am.sh
+++ b/t/t4150-am.sh
@@ -983,7 +983,9 @@ test_expect_success 'am works with multi-line in-body headers' '
 	rm -fr .git/rebase-apply &&
 	git checkout -f first &&
 	echo one >> file &&
-	git commit -am "$LONG" --author="$LONG <long@example.com>" &&
+	git commit -am "$LONG
+
+    Body test" --author="$LONG <long@example.com>" &&
 	git format-patch --stdout -1 >patch &&
 	# bump from, date, and subject down to in-body header
 	perl -lpe "
@@ -997,7 +999,7 @@ test_expect_success 'am works with multi-line in-body headers' '
 	git am msg &&
 	# Ensure that the author and full message are present
 	git cat-file commit HEAD | grep "^author.*long@example.com" &&
-	git cat-file commit HEAD | grep "^$LONG"
+	git cat-file commit HEAD | grep "^$LONG$"
 '
 
 test_done
-- 
2.12.2.578.g5c4e54f4e


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

* Re: [PATCH] Fix 'git am' in-body header continuations
  2017-04-03  0:49 [PATCH] Fix 'git am' in-body header continuations Linus Torvalds
@ 2017-04-03 18:00 ` Jonathan Tan
  2017-04-04  6:48   ` Jeff King
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Tan @ 2017-04-03 18:00 UTC (permalink / raw)
  To: Linus Torvalds, Junio C Hamano; +Cc: Jeff King, Git Mailing List

This looks good to me.

On 04/02/2017 05:49 PM, Linus Torvalds wrote:
>
> From: Linus Torvalds <torvalds@linux-foundation.org>
> Date: Sat, 1 Apr 2017 12:14:39 -0700
> Subject: [PATCH] Fix 'git am' in-body header continuations
>
> An empty line should stop any pending in-body headers, and start the
> actual body parsing.
>
> This also modifies the original test for the in-body headers to actually
> have a real commit body that starts with spaces, and changes the test to
> check that the long line matches _exactly_, and doesn't get extra data
> from the body.
>
> Fixes:6b4b013f1884 ("mailinfo: handle in-body header continuations")
> Cc: Jonathan Tan <jonathantanmy@google.com>
> Cc: Jeff King <peff@peff.net>
> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
> ---
> diff --git a/t/t4150-am.sh b/t/t4150-am.sh
> index 89a5bacac..44807e218 100755
> --- a/t/t4150-am.sh
> +++ b/t/t4150-am.sh
> @@ -983,7 +983,9 @@ test_expect_success 'am works with multi-line in-body headers' '
>  	rm -fr .git/rebase-apply &&
>  	git checkout -f first &&
>  	echo one >> file &&
> -	git commit -am "$LONG" --author="$LONG <long@example.com>" &&
> +	git commit -am "$LONG
> +
> +    Body test" --author="$LONG <long@example.com>" &&

Instead of "Body test", I would write something more descriptive like 
"Not a continuation line because of blank line above", but I'm fine with 
either.

>  	git format-patch --stdout -1 >patch &&
>  	# bump from, date, and subject down to in-body header
>  	perl -lpe "
> @@ -997,7 +999,7 @@ test_expect_success 'am works with multi-line in-body headers' '
>  	git am msg &&
>  	# Ensure that the author and full message are present
>  	git cat-file commit HEAD | grep "^author.*long@example.com" &&
> -	git cat-file commit HEAD | grep "^$LONG"
> +	git cat-file commit HEAD | grep "^$LONG$"
>  '
>
>  test_done
>

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

* Re: [PATCH] Fix 'git am' in-body header continuations
  2017-04-03 18:00 ` Jonathan Tan
@ 2017-04-04  6:48   ` Jeff King
  0 siblings, 0 replies; 3+ messages in thread
From: Jeff King @ 2017-04-04  6:48 UTC (permalink / raw)
  To: Jonathan Tan; +Cc: Linus Torvalds, Junio C Hamano, Git Mailing List

On Mon, Apr 03, 2017 at 11:00:09AM -0700, Jonathan Tan wrote:

> > diff --git a/t/t4150-am.sh b/t/t4150-am.sh
> > index 89a5bacac..44807e218 100755
> > --- a/t/t4150-am.sh
> > +++ b/t/t4150-am.sh
> > @@ -983,7 +983,9 @@ test_expect_success 'am works with multi-line in-body headers' '
> >  	rm -fr .git/rebase-apply &&
> >  	git checkout -f first &&
> >  	echo one >> file &&
> > -	git commit -am "$LONG" --author="$LONG <long@example.com>" &&
> > +	git commit -am "$LONG
> > +
> > +    Body test" --author="$LONG <long@example.com>" &&
> 
> Instead of "Body test", I would write something more descriptive like "Not a
> continuation line because of blank line above", but I'm fine with either.

Yeah. I also wonder if we can make the indentation more obvious. I
thought at first that the patch was whitespace mangled. :-/

Maybe:

  SP=" " &&
  cat >msg <<-EOF &&
  $LONG

  $SP This line is indented but not a header continuation.
  EOF
  git commit -F msg ...

or something.

It might also be easier to understand what's going on if this gets its
own test. This is really just testing mailinfo. I wonder if it would
make more sense in t5100, where we would not have to deal with all the
commit/format-patch cruft.

-Peff

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

end of thread, other threads:[~2017-04-04  6:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-03  0:49 [PATCH] Fix 'git am' in-body header continuations Linus Torvalds
2017-04-03 18:00 ` Jonathan Tan
2017-04-04  6:48   ` Jeff King

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.