Git development
 help / color / mirror / Atom feed
* [PATCH] git-diff: don't add trailing blanks (i.e., do what GNU diff -u now does)
@ 2006-12-17 19:32 Jim Meyering
  2006-12-17 20:00 ` Linus Torvalds
  0 siblings, 1 reply; 6+ messages in thread
From: Jim Meyering @ 2006-12-17 19:32 UTC (permalink / raw)
  To: git

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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2006-12-18 12:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-12-17 19:32 [PATCH] git-diff: don't add trailing blanks (i.e., do what GNU diff -u now does) Jim Meyering
2006-12-17 20:00 ` Linus Torvalds
2006-12-17 20:09   ` Junio C Hamano
2006-12-17 20:36     ` Jim Meyering
2006-12-17 20:54     ` Jakub Narebski
2006-12-18 12:06       ` Johannes Schindelin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox