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

[PATCH 2/4] Fix format.headers not ending with a newline

From
Daniel Barkalow <barkalow@iabervon.org>
Date
Feb 19, 2008, 07:40 UTC
Message-ID
<alpine.LNX.1.00.0802190239440.5816@iabervon.org>

Now each value of format.headers will always be treated as a single valid header, and newlines will be inserted between them as needed.

Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
---
 builtin-log.c           |    8 ++++++--
 t/t4014-format-patch.sh |    2 +-
 2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/builtin-log.c b/builtin-log.c
index a67b463..73b6d53 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -425,10 +425,14 @@ static int git_format_config(const char *var, const char *value)
 		if (!value)
 			die("format.headers without value");
 		len = strlen(value);
-		extra_headers_size += len + 1;
+		while (value[len - 1] == '\n')
+			len--;
+		extra_headers_size += len + 2;
 		extra_headers = xrealloc(extra_headers, extra_headers_size);
-		extra_headers[extra_headers_size - len - 1] = 0;
+		extra_headers[extra_headers_size - len - 2] = 0;
 		strcat(extra_headers, value);
+		extra_headers[extra_headers_size - 2] = '\n';
+		extra_headers[extra_headers_size - 1] = 0;
 		return 0;
 	}
 	if (!strcmp(var, "format.suffix")) {
diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh
index 28ab7b9..755fe6d 100755
--- a/t/t4014-format-patch.sh
+++ b/t/t4014-format-patch.sh
@@ -101,7 +101,7 @@ test_expect_success 'extra headers' '
 	
 '
 
-test_expect_failure 'extra headers without newlines' '
+test_expect_success 'extra headers without newlines' '
 
 	git config --replace-all format.headers "To: R. E. Cipient <rcipient@example.com>" &&
 	git config --add format.headers "Cc: S. E. Cipient <scipient@example.com>" &&
-- 
1.5.4.1.192.g8ea3a
Message 1 of 1 in “Fix format.headers not ending with a newline”
  1. 2/4 Fix format.headers not ending with a newlineDaniel Barkalow, Feb 19, 2008

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.