threads / patch / 4870

patchformat-patch: Generate a newline between the subject header and the message body.

Subject: [PATCH] format-patch: Generate a newline between the subject header and the message body.

## tl;dr

6 messages between Jul 13, 2006 and Jul 13, 2006. Diffs are folded; open one to read it.

replies: 5people: 3as markdown or json

Robert Shearman· Jul 13, 2006, 12:03 UTC · lore

format-patch previously didn't generate a newline after a subject. This caused the diffstat to not be displayed in messages without a blank line and the first blank line to be eaten in messages with a blank line.

This patch inserts a newline in two places - once in the loop to 
separate the subject part of the commit message from the body part of 
the commit message and another after the loop to counteract the eating 
of whitespace at the end of the message.
---
  commit.c |   14 ++++++++++++--
  1 files changed, 12 insertions(+), 2 deletions(-)
Show changes to commit.c +12 −2
diff --git a/commit.c b/commit.c
index 522a6f3..8869b0d 100644
--- a/commit.c
+++ b/commit.c
@@ -655,6 +655,9 @@ unsigned long pretty_print_commit(enum c
 			continue;
 		}
 
+		if (!subject)
+			body = 1;
+
 		if (is_empty_line(line, &linelen)) {
 			if (!body)
 				continue;
@@ -662,8 +665,6 @@ unsigned long pretty_print_commit(enum c
 				continue;
 			if (fmt == CMIT_FMT_SHORT)
 				break;
-		} else {
-			body = 1;
 		}
 
 		if (subject) {
@@ -694,6 +695,9 @@ unsigned long pretty_print_commit(enum c
 			memcpy(buf + offset, after_subject, slen);
 			offset += slen;
 			after_subject = NULL;
+		} else if (fmt == CMIT_FMT_EMAIL && subject) {
+			/* separate the headers from the body */
+			buf[offset++] = '\n';
 		}
 		subject = NULL;
 	}
@@ -702,6 +706,12 @@ unsigned long pretty_print_commit(enum c
 	/* Make sure there is an EOLN for the non-oneline case */
 	if (fmt != CMIT_FMT_ONELINE)
 		buf[offset++] = '\n';
+	/*
+	 * make sure there is another EOLN to separate the headers from whatever
+	 * body the caller appends if we haven't already written a body
+	 */
+	if (fmt == CMIT_FMT_EMAIL && !body)
+		buf[offset++] = '\n';
 	buf[offset] = '\0';
 	return offset;
 }
Jakub Narebski· Jul 13, 2006, 19:38 UTC · re: Robert Shearman · lore

Re: [PATCH] format-patch: Generate a newline between the subject header and the message body.

Robert Shearman wrote:
> 
> format-patch previously didn't generate a newline after a subject. This 
> caused the diffstat to not be displayed in messages without a blank line 
> and the first blank line to be eaten in messages with a blank line.

Does this _enforce_ separating commit message into subject+empty line+description? What about commit messages without this structire (e.g. legacy commit messages from import from other SCM, e.g. GNU ChangeLog style)?

-- 
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git
Robert Shearman· Jul 13, 2006, 20:03 UTC · re: Jakub Narebski · lore

Re: [PATCH] format-patch: Generate a newline between the subject header and the message body.

Jakub Narebski wrote:
Show 14 quoted lines
>Robert Shearman wrote:
>  
>
>>format-patch previously didn't generate a newline after a subject. This 
>>caused the diffstat to not be displayed in messages without a blank line 
>>and the first blank line to be eaten in messages with a blank line.
>>    
>>
>
>Does this _enforce_ separating commit message into subject+empty
>line+description? What about commit messages without this structire (e.g.
>legacy commit messages from import from other SCM, e.g. GNU ChangeLog
>style)?
>

It only affects commits exported into email style. It has nothing to do with the structure of GIT commit messages or those of any other SCM.

-- 
Rob Shearman
Junio C Hamano· Jul 13, 2006, 21:31 UTC · re: Robert Shearman · lore

Re: [PATCH] format-patch: Generate a newline between the subject header and the message body.

Robert Shearman <rob@codeweavers.com> writes:
> This patch inserts a newline in two places - once in the loop to
> separate the subject part of the commit message from the body part of
> the commit message and another after the loop to counteract the eating
> of whitespace at the end of the message.
Thanks.
 * Please sign your patch.
 * This breaks a handful t4013 tests, but all in a good way (in
   other words, the expected output files were wrong).
I'll fix up the t/t4013/diff.* files myself.
Junio C Hamano· Jul 13, 2006, 21:48 UTC · re: Junio C Hamano · lore

Re: [PATCH] format-patch: Generate a newline between the subject header and the message body.

Junio C Hamano <junkio@cox.net> writes:
Show 15 quoted lines
> Robert Shearman <rob@codeweavers.com> writes:
>
>> This patch inserts a newline in two places - once in the loop to
>> separate the subject part of the commit message from the body part of
>> the commit message and another after the loop to counteract the eating
>> of whitespace at the end of the message.
>
> Thanks.
>
>  * Please sign your patch.
>
>  * This breaks a handful t4013 tests, but all in a good way (in
>    other words, the expected output files were wrong).
>
> I'll fix up the t/t4013/diff.* files myself.

Actually, I take that back. This breaks normal commit log messages by adding extra blank lines. The extra LF is needed when the commit log does not have any message (just title).

I'll be tweaking a few tests in t4013 to catch future breakage of this kind.

Robert Shearman· Jul 13, 2006, 21:55 UTC · re: Junio C Hamano · lore

Re: [PATCH] format-patch: Generate a newline between the subject header and the message body.

Junio C Hamano wrote:
Show 30 quoted lines
>Junio C Hamano <junkio@cox.net> writes:
>
>  
>
>>Robert Shearman <rob@codeweavers.com> writes:
>>
>>    
>>
>>>This patch inserts a newline in two places - once in the loop to
>>>separate the subject part of the commit message from the body part of
>>>the commit message and another after the loop to counteract the eating
>>>of whitespace at the end of the message.
>>>      
>>>
>>Thanks.
>>
>> * Please sign your patch.
>>
>> * This breaks a handful t4013 tests, but all in a good way (in
>>   other words, the expected output files were wrong).
>>
>>I'll fix up the t/t4013/diff.* files myself.
>>    
>>
>
>Actually, I take that back.  This breaks normal commit log
>messages by adding extra blank lines.  The extra LF is needed
>when the commit log does not have any message (just title).
>  
>
Ok, I'll resend with that fixed.
>I'll be tweaking a few tests in t4013 to catch future breakage
>of this kind.
>
Thanks.
-- 
Rob Shearman

← back to recent threads