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

[PATCH] commit: fix too generous RFC-2822 footer handling

From
SZEDER Gábor <szeder@ira.uka.de>
Date
Nov 4, 2009, 03:09 UTC
Message-ID
<1257304146-15543-1-git-send-email-szeder@ira.uka.de>
In-Reply-To
<20091103165951.GA2241@neumann>

Since commit c1e01b0c (commit: More generous accepting of RFC-2822 footer lines, 2009-10-28) RFC-2822-looking lines at the end of the message are considered part of the footer and 'git commit -s -m' doesn't add a newline between that footer and the new S-O-B line. This new behaviour causes problems with subject-only commit messages which happens to look like an RFC-2822 header (e.g. 'git commit -s -m "subsystem: coolest feature ever"'). In such cases there won't be any newline between the subject and the S-O-B line, and the S-O-B line will show up at places where it should not (e.g. in the output of 'git shortlog').

With this patch the newline will be always added if a commit message has only a single line, even if it looks like an RFC-2822 header.

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---
 Maybe something like this?  Be careful when reviewing, it's 4AM
 here...
 builtin-commit.c  |    8 ++++++++
 t/t7501-commit.sh |    4 ++--
 2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/builtin-commit.c b/builtin-commit.c
index beddf01..4971156 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -429,6 +429,14 @@ static int ends_rfc2822_footer(struct strbuf *sb)
 		hit = (buf[i] == '\n');
 	}
 
+	for (j = i-1; j > 0; j--)
+		if (buf[j] == '\n') {
+			hit = 1;
+			break;
+		}
+	if (!hit)	/* one-line message */
+		return 0;
+
 	while (i < len - 1 && buf[i] == '\n')
 		i++;
 
diff --git a/t/t7501-commit.sh b/t/t7501-commit.sh
index d2de576..aaeedda 100755
--- a/t/t7501-commit.sh
+++ b/t/t7501-commit.sh
@@ -215,10 +215,10 @@ test_expect_success 'sign off (1)' '
 
 	echo 1 >positive &&
 	git add positive &&
-	git commit -s -m "thank you" &&
+	git commit -s -m "subsystem: coolest feature ever" &&
 	git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
 	(
-		echo thank you
+		echo subsystem: coolest feature ever
 		echo
 		git var GIT_COMMITTER_IDENT |
 		sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
-- 
1.6.5.2.201.g0f47
Previous: SZEDER GáborNext: Junio C Hamano
Message 9 of 11 in “commit: More generous accepting of RFC-2822 footer lines.”
  1. commit: More generous accepting of RFC-2822 footer lines.David Brown, Oct 27, 2009
  2. Shawn O. PearceOct 28, 2009
  3. Junio C HamanoOct 28, 2009
  4. David BrownOct 28, 2009
  5. commit: More generous accepting of RFC-2822 footer lines.David Brown, Oct 28, 2009
  6. Junio C HamanoOct 28, 2009
  7. David BrownOct 28, 2009
  8. SZEDER GáborNov 3, 2009
  9. commit: fix too generous RFC-2822 footer handlingSZEDER Gábor, Nov 4, 2009
  10. Junio C HamanoNov 4, 2009
  11. SZEDER GáborNov 4, 2009

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.