# Re: [PATCH] git-diff: don't add trailing blanks (i.e., do what GNU diff -u now does)

6 messages from 2006-12-17 to 2006-12-18. Participants: Jakub Narebski, Junio C Hamano, Jim Meyering, Johannes Schindelin, Linus Torvalds.
Thread: https://gitlist.dev/t/43447

## Jim Meyering, 2006-12-17 19:32

Subject: [PATCH] git-diff: don't add trailing blanks (i.e., do what GNU diff -u now does)
Message-ID: <87y7p6nwsh.fsf@rho.meyering.net>
URL: https://gitlist.dev/e/87y7p6nwsh.fsf%40rho.meyering.net

```
You may recall that GNU diff -u changed recently so that it no
longer outputs any trailing space unless the input data has it.
This means that blank context lines are now blank also in diff -u output.
Before, they would have a single trailing space.

Then, git was changed to allow that new diff output format.
Now that git-diff generates output using its internal diff, its
output is no longer identical to what you get when using GNU diff.

This patch makes the output of git-diff the same as GNU diff's.

Signed-off-by: Jim Meyering <jim@meyering.net>
---
 t/t4016-diff-trailing-space.sh |   31 +++++++++++++++++++++++++++++++
 xdiff/xutils.c                 |    3 +++
 2 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/t/t4016-diff-trailing-space.sh b/t/t4016-diff-trailing-space.sh
new file mode 100755
index 0000000..95c4674
--- /dev/null
+++ b/t/t4016-diff-trailing-space.sh
@@ -0,0 +1,31 @@
+#!/bin/bash
+#
+# Copyright (c) Jim Meyering
+#
+test_description='diff does not add trailing spaces'
+
+. ./test-lib.sh
+
+cat <<\EOF > exp ||
+diff --git a/f b/f
+index 5f6a263..8cb8bae 100644
+--- a/f
++++ b/f
+@@ -1,2 +1,2 @@
+
+-x
++y
+EOF
+exit 1
+
+test_expect_success \
+    "$test_description" \
+    '(echo; echo x) > f &&
+     git-add f &&
+     git-commit -q -m. f &&
+     (echo; echo y) > f &&
+     git-diff f > actual &&
+     cmp exp actual
+     '
+
+test_done
diff --git a/xdiff/xutils.c b/xdiff/xutils.c
index 1b899f3..8b7380a 100644
--- a/xdiff/xutils.c
+++ b/xdiff/xutils.c
@@ -51,6 +51,9 @@ int xdl_emit_diffrec(char const *rec, long size, char const *pre, long psize,
 	mb[0].size = psize;
 	mb[1].ptr = (char *) rec;
 	mb[1].size = size;
+	/* Don't emit a trailing space for an empty context line.  */
+	if (size == 1 && rec[0] == '\n' && psize == 1 && *pre == ' ')
+		mb[0].size = 0;
 	if (size > 0 && rec[size - 1] != '\n') {
 		mb[2].ptr = (char *) "\n\\ No newline at end of file\n";
 		mb[2].size = strlen(mb[2].ptr);
--

```

## Linus Torvalds, 2006-12-17 20:00

Subject: Re: [PATCH] git-diff: don't add trailing blanks (i.e., do what GNU diff -u now does)
Message-ID: <Pine.LNX.4.64.0612171200290.3479@woody.osdl.org>
URL: https://gitlist.dev/e/Pine.LNX.4.64.0612171200290.3479%40woody.osdl.org
In-Reply-To: <87y7p6nwsh.fsf@rho.meyering.net>

```


On Sun, 17 Dec 2006, Jim Meyering wrote:
>
> You may recall that GNU diff -u changed recently so that it no
> longer outputs any trailing space unless the input data has it.

I still consider that to be a bug in GNU "diff -u".

We work around that bug when applying patches, but I don't think we should 
replicate it.


```

## Junio C Hamano, 2006-12-17 20:09

Subject: Re: [PATCH] git-diff: don't add trailing blanks (i.e., do what GNU diff -u now does)
Message-ID: <7vtzzu5lp1.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vtzzu5lp1.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <Pine.LNX.4.64.0612171200290.3479@woody.osdl.org>

```
Linus Torvalds <torvalds@osdl.org> writes:

> On Sun, 17 Dec 2006, Jim Meyering wrote:
>>
>> You may recall that GNU diff -u changed recently so that it no
>> longer outputs any trailing space unless the input data has it.
>
> I still consider that to be a bug in GNU "diff -u".
>
> We work around that bug when applying patches, but I don't think we should 
> replicate it.

Me neither.

```

## Jim Meyering, 2006-12-17 20:36

Subject: Re: [PATCH] git-diff: don't add trailing blanks (i.e., do what GNU diff -u now does)
Message-ID: <87psainttt.fsf@rho.meyering.net>
URL: https://gitlist.dev/e/87psainttt.fsf%40rho.meyering.net
In-Reply-To: <7vtzzu5lp1.fsf@assigned-by-dhcp.cox.net>

```
Junio C Hamano <junkio@cox.net> wrote:
> Linus Torvalds <torvalds@osdl.org> writes:
>> On Sun, 17 Dec 2006, Jim Meyering wrote:
>>> You may recall that GNU diff -u changed recently so that it no
>>> longer outputs any trailing space unless the input data has it.
>>
>> I still consider that to be a bug in GNU "diff -u".
>>
>> We work around that bug when applying patches, but I don't think we should
>> replicate it.
>
> Me neither.

I can't say I didn't expect this.

```

## Jakub Narebski, 2006-12-17 20:54

Subject: Re: [PATCH] git-diff: don't add trailing blanks (i.e., do what GNU diff -u now does)
Message-ID: <em4all$b2c$1@sea.gmane.org>
URL: https://gitlist.dev/e/em4all%24b2c%241%40sea.gmane.org
In-Reply-To: <7vtzzu5lp1.fsf@assigned-by-dhcp.cox.net>

```
Junio C Hamano wrote:

> Linus Torvalds <torvalds@osdl.org> writes:
> 
>> On Sun, 17 Dec 2006, Jim Meyering wrote:
>>>
>>> You may recall that GNU diff -u changed recently so that it no
>>> longer outputs any trailing space unless the input data has it.
>>
>> I still consider that to be a bug in GNU "diff -u".
>>
>> We work around that bug when applying patches, but I don't think we should 
>> replicate it.
> 
> Me neither.

Perhaps with --gnu-diff-compatibility then? 

-- 
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git


```

## Johannes Schindelin, 2006-12-18 12:06

Subject: Re: [PATCH] git-diff: don't add trailing blanks (i.e., do what GNU diff -u now does)
Message-ID: <Pine.LNX.4.63.0612181305500.3635@wbgn013.biozentrum.uni-wuerzburg.de>
URL: https://gitlist.dev/e/Pine.LNX.4.63.0612181305500.3635%40wbgn013.biozentrum.uni-wuerzburg.de
In-Reply-To: <em4all$b2c$1@sea.gmane.org>

```
Hi,

On Sun, 17 Dec 2006, Jakub Narebski wrote:

> Junio C Hamano wrote:
> 
> > Linus Torvalds <torvalds@osdl.org> writes:
> > 
> >> On Sun, 17 Dec 2006, Jim Meyering wrote:
> >>>
> >>> You may recall that GNU diff -u changed recently so that it no
> >>> longer outputs any trailing space unless the input data has it.
> >>
> >> I still consider that to be a bug in GNU "diff -u".
> >>
> >> We work around that bug when applying patches, but I don't think we should 
> >> replicate it.
> > 
> > Me neither.
> 
> Perhaps with --gnu-diff-compatibility then? 

Rather --braindead-gnu-bug-compatibility.

Ciao,
Dscho

```
