# [PATCH] Tweak git-diff-tree -v output further (take 2).

4 messages from 2005-05-06 to 2005-05-06. Participants: Junio C Hamano, Linus Torvalds, H. Peter Anvin.
Thread: https://gitlist.dev/t/508

## Junio C Hamano, 2005-05-06 19:37

Subject: [PATCH] Tweak git-diff-tree -v output further (take 2).
Message-ID: <7vbr7ocfj7.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vbr7ocfj7.fsf%40assigned-by-dhcp.cox.net

```
(This one is simpler than the previous one I just sent out)

The first hunk of this is a pure bugfix---it guards us against a
commit message that does not end with a newline.

This adds the full header information to git-diff-tree -v output
in addition to the log message it already produces.  It also
stops indenting the log message to match what git-export does.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---

diff-tree.c |   22 ++++++++++++----------
1 files changed, 12 insertions(+), 10 deletions(-)

# - linus-mirror: diff-tree: add "verbose header" mode
# + (working tree)
--- a/diff-tree.c
+++ b/diff-tree.c
@@ -278,7 +278,7 @@ static int get_one_line(const char *msg,
 
 	while (len--) {
 		ret++;
-		if (*msg++ == '\n')
+		if (!*msg || *msg++ == '\n')
 			break;
 	}
 	return ret;
@@ -287,12 +287,14 @@ static int get_one_line(const char *msg,
 static char *generate_header(const char *commit, const char *parent, const char *msg, unsigned long len)
 {
 	static char this_header[1000];
-	int offset;
 
-	offset = sprintf(this_header, "%s%s (from %s)\n", header_prefix, commit, parent);
-	if (verbose_header) {
+	if (!verbose_header)
+		sprintf(this_header, "%s%s (from %s)\n", header_prefix,
+			commit, parent);
+	else {
+		int offset;
 		int hdr = 1;
-
+		offset = sprintf(this_header, "Id: %s\n", commit);
 		for (;;) {
 			const char *line = msg;
 			int linelen = get_one_line(msg, len);
@@ -306,11 +308,11 @@ static char *generate_header(const char 
 			len -= linelen;
 			if (linelen == 1)
 				hdr = 0;
-			if (hdr)
-				continue;
-			memset(this_header + offset, ' ', 4);
-			memcpy(this_header + offset + 4, line, linelen);
-			offset += linelen + 4;
+			memcpy(this_header + offset, line, linelen);
+			if (hdr && !strncmp(line, "parent ", 7) &&
+			    !strncmp(line+7, parent, 40))
+				this_header[offset + 6] = '*';
+			offset += linelen;
 		}
 		this_header[offset++] = '\n';
 		this_header[offset] = 0;


```

## Linus Torvalds, 2005-05-06 21:40

Subject: Re: [PATCH] Tweak git-diff-tree -v output further (take 2).
Message-ID: <Pine.LNX.4.58.0505061440180.2233@ppc970.osdl.org>
URL: https://gitlist.dev/e/Pine.LNX.4.58.0505061440180.2233%40ppc970.osdl.org
In-Reply-To: <7vbr7ocfj7.fsf@assigned-by-dhcp.cox.net>

```


On Fri, 6 May 2005, Junio C Hamano wrote:
> 
> The first hunk of this is a pure bugfix---it guards us against a
> commit message that does not end with a newline.

Why do you think it helps anything at all?

We have a _length_ of buffer. We don't have any zero-termination.

		Linus

```

## H. Peter Anvin, 2005-05-06 21:47

Subject: Re: [PATCH] Tweak git-diff-tree -v output further (take 2).
Message-ID: <427BE5F4.3040602@zytor.com>
URL: https://gitlist.dev/e/427BE5F4.3040602%40zytor.com
In-Reply-To: <7vbr7ocfj7.fsf@assigned-by-dhcp.cox.net>

```
Junio C Hamano wrote:
> (This one is simpler than the previous one I just sent out)
> 
> The first hunk of this is a pure bugfix---it guards us against a
> commit message that does not end with a newline.

No it doesn't.  What it does is "guard" you against a commit message 
which contains a null character.  What's not entirely clear is if that's 
what you wanted to do.

	-hpa

```

## Junio C Hamano, 2005-05-06 22:05

Subject: Re: [PATCH] Tweak git-diff-tree -v output further (take 2).
Message-ID: <7v4qdgc8o5.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7v4qdgc8o5.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <Pine.LNX.4.58.0505061440180.2233@ppc970.osdl.org>

```
You are absolutely right.


```
