xdiff: print post-image for common records instead of pre-image

Normally it doesn't matter if we show the pre-image or th post-image for the common parts of a diff because they are the same. If white-space changes are ignored they can differ, though. The new text after applying the diff is more interesting in that case, so show that instead of the old contents. Note: GNU diff shows the pre-image. Suggested-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Jan 6, 2012 at 18:13 UTC baf5aaa33383af656a34b7ba9039e9eb3c9e678c
2 files changed +13 -13
t/t4015-diff-whitespace.sh
+7 -7
@@ -103,7 +103,7 @@ test_expect_success 'another test, with -w --ignore-space-at-eol' 'test_cmp expe
103 git diff -w -b --ignore-space-at-eol > out
104 test_expect_success 'another test, with -w -b --ignore-space-at-eol' 'test_cmp expect out'
105
106 -tr 'Q' '\015' << EOF > expect
106 +tr 'Q_' '\015 ' << EOF > expect
107 diff --git a/x b/x
108 index d99af23..8b32fb5 100644
109 --- a/x
@@ -111,19 +111,19 @@ index d99af23..8b32fb5 100644
111 @@ -1,6 +1,6 @@
112 -whitespace at beginning
113 + whitespace at beginning
114 - whitespace change
114 + whitespace change
115 -whitespace in the middle
116 +white space in the middle
117 - whitespace at end
117 + whitespace at end__
118 unchanged line
119 - CR at endQ
119 + CR at end
120 EOF
121 git diff -b > out
122 test_expect_success 'another test, with -b' 'test_cmp expect out'
123 git diff -b --ignore-space-at-eol > out
124 test_expect_success 'another test, with -b --ignore-space-at-eol' 'test_cmp expect out'
125
126 -tr 'Q' '\015' << EOF > expect
126 +tr 'Q_' '\015 ' << EOF > expect
127 diff --git a/x b/x
128 index d99af23..8b32fb5 100644
129 --- a/x
@@ -135,9 +135,9 @@ index d99af23..8b32fb5 100644
135 + whitespace at beginning
136 +whitespace change
137 +white space in the middle
138 - whitespace at end
138 + whitespace at end__
139 unchanged line
140 - CR at endQ
140 + CR at end
141 EOF
142 git diff --ignore-space-at-eol > out
143 test_expect_success 'another test, with --ignore-space-at-eol' 'test_cmp expect out'
xdiff/xemit.c
+6 -6
@@ -87,7 +87,7 @@ static long def_ff(const char *rec, long len, char *buf, long sz, void *priv)
87
88 static int xdl_emit_common(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
89 xdemitconf_t const *xecfg) {
90 - xdfile_t *xdf = &xe->xdf1;
90 + xdfile_t *xdf = &xe->xdf2;
91 const char *rchg = xdf->rchg;
92 long ix;
93
@@ -151,8 +151,8 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
151 /*
152 * Emit pre-context.
153 */
154 - for (; s1 < xch->i1; s1++)
155 - if (xdl_emit_record(&xe->xdf1, s1, " ", ecb) < 0)
154 + for (; s2 < xch->i2; s2++)
155 + if (xdl_emit_record(&xe->xdf2, s2, " ", ecb) < 0)
156 return -1;
157
158 for (s1 = xch->i1, s2 = xch->i2;; xch = xch->next) {
@@ -160,7 +160,7 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
160 * Merge previous with current change atom.
161 */
162 for (; s1 < xch->i1 && s2 < xch->i2; s1++, s2++)
163 - if (xdl_emit_record(&xe->xdf1, s1, " ", ecb) < 0)
163 + if (xdl_emit_record(&xe->xdf2, s2, " ", ecb) < 0)
164 return -1;
165
166 /*
@@ -186,8 +186,8 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
186 /*
187 * Emit post-context.
188 */
189 - for (s1 = xche->i1 + xche->chg1; s1 < e1; s1++)
190 - if (xdl_emit_record(&xe->xdf1, s1, " ", ecb) < 0)
189 + for (s2 = xche->i2 + xche->chg2; s2 < e2; s2++)
190 + if (xdl_emit_record(&xe->xdf2, s2, " ", ecb) < 0)
191 return -1;
192 }
193