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

6 messages from 2006-07-13 to 2006-07-13. Participants: Robert Shearman, Jakub Narebski, Junio C Hamano.
Thread: https://gitlist.dev/t/4870

## Robert Shearman, 2006-07-13 12:03

Subject: [PATCH] format-patch: Generate a newline between the subject header and the message body.
Message-ID: <44B6369D.6070602@codeweavers.com>
URL: https://gitlist.dev/e/44B6369D.6070602%40codeweavers.com

```

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(-)


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, 2006-07-13 19:38

Subject: Re: [PATCH] format-patch: Generate a newline between the subject header and the message body.
Message-ID: <e967en$bi6$1@sea.gmane.org>
URL: https://gitlist.dev/e/e967en%24bi6%241%40sea.gmane.org
In-Reply-To: <44B6369D.6070602@codeweavers.com>

```
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, 2006-07-13 20:03

Subject: Re: [PATCH] format-patch: Generate a newline between the subject header and the message body.
Message-ID: <44B6A70E.7060301@codeweavers.com>
URL: https://gitlist.dev/e/44B6A70E.7060301%40codeweavers.com
In-Reply-To: <e967en$bi6$1@sea.gmane.org>

```
Jakub Narebski wrote:

>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, 2006-07-13 21:31

Subject: Re: [PATCH] format-patch: Generate a newline between the subject header and the message body.
Message-ID: <7vbqrtur8q.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vbqrtur8q.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <44B6369D.6070602@codeweavers.com>

```
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, 2006-07-13 21:48

Subject: Re: [PATCH] format-patch: Generate a newline between the subject header and the message body.
Message-ID: <7v7j2huqfj.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7v7j2huqfj.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <7vbqrtur8q.fsf@assigned-by-dhcp.cox.net>

```
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).

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

```

## Robert Shearman, 2006-07-13 21:55

Subject: Re: [PATCH] format-patch: Generate a newline between the subject header and the message body.
Message-ID: <44B6C152.8000204@codeweavers.com>
URL: https://gitlist.dev/e/44B6C152.8000204%40codeweavers.com
In-Reply-To: <7v7j2huqfj.fsf@assigned-by-dhcp.cox.net>

```
Junio C Hamano wrote:

>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

```
