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

Re: Bug in "git am" when the body starts with spaces

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Apr 1, 2017, 19:03 UTC
Message-ID
<CA+55aFwmNuvh_ABtnd_uxXv5HjEjN-+HMZGh_u1OjOCa4dbpmg@mail.gmail.com>
In-Reply-To
<CA+55aFwcQuxwhQ+LABmev2XRHgOqsbRm7YDYn3FDDXKMYcF-CA@mail.gmail.com>

On Fri, Mar 31, 2017 at 5:52 PM, Linus Torvalds <torvalds@linux-foundation.org> wrote:

>
> The continuation logic is oddly complex, and I can't follow the logic.
> But it is completely broken in how it thinks empty lines are somehow
> "continuations".
The attached patch seems to work for me. Comments?

The logic is fairly simple: if we encounter an empty line, and we have pending in-body headers, we flush the pending headers, and mark us as no longer in header mode.

The code used to just ignore empty lines when in header mode, which is garbage, exactly because it would happily continue accumulating more headers.

There may be other cases this misses, but this at least seems to fix the case I encountered.

                    Linus
 mailinfo.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
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) {
Previous: Jeff KingNext: Jeff King
Message 4 of 8 in “Bug in "git am" when the body starts with spaces”
  1. Linus TorvaldsApr 1, 2017
  2. Linus TorvaldsApr 1, 2017
  3. Jeff KingApr 1, 2017
  4. Linus TorvaldsApr 1, 2017
  5. Jeff KingApr 2, 2017
  6. Jonathan TanApr 3, 2017
  7. Jeff KingApr 4, 2017
  8. Junio C HamanoApr 2, 2017

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.