Skip to content

Commit

Permalink
xdiff: print post-image for common records instead of pre-image
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
René Scharfe authored and gitster committed Jan 6, 2012
1 parent 7ed863a commit baf5aaa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
14 changes: 7 additions & 7 deletions t/t4015-diff-whitespace.sh
Expand Up @@ -103,27 +103,27 @@ test_expect_success 'another test, with -w --ignore-space-at-eol' 'test_cmp expe
git diff -w -b --ignore-space-at-eol > out git diff -w -b --ignore-space-at-eol > out
test_expect_success 'another test, with -w -b --ignore-space-at-eol' 'test_cmp expect out' test_expect_success 'another test, with -w -b --ignore-space-at-eol' 'test_cmp expect out'


tr 'Q' '\015' << EOF > expect tr 'Q_' '\015 ' << EOF > expect
diff --git a/x b/x diff --git a/x b/x
index d99af23..8b32fb5 100644 index d99af23..8b32fb5 100644
--- a/x --- a/x
+++ b/x +++ b/x
@@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
-whitespace at beginning -whitespace at beginning
+ whitespace at beginning + whitespace at beginning
whitespace change whitespace change
-whitespace in the middle -whitespace in the middle
+white space in the middle +white space in the middle
whitespace at end whitespace at end__
unchanged line unchanged line
CR at endQ CR at end
EOF EOF
git diff -b > out git diff -b > out
test_expect_success 'another test, with -b' 'test_cmp expect out' test_expect_success 'another test, with -b' 'test_cmp expect out'
git diff -b --ignore-space-at-eol > out git diff -b --ignore-space-at-eol > out
test_expect_success 'another test, with -b --ignore-space-at-eol' 'test_cmp expect out' test_expect_success 'another test, with -b --ignore-space-at-eol' 'test_cmp expect out'


tr 'Q' '\015' << EOF > expect tr 'Q_' '\015 ' << EOF > expect
diff --git a/x b/x diff --git a/x b/x
index d99af23..8b32fb5 100644 index d99af23..8b32fb5 100644
--- a/x --- a/x
Expand All @@ -135,9 +135,9 @@ index d99af23..8b32fb5 100644
+ whitespace at beginning + whitespace at beginning
+whitespace change +whitespace change
+white space in the middle +white space in the middle
whitespace at end whitespace at end__
unchanged line unchanged line
CR at endQ CR at end
EOF EOF
git diff --ignore-space-at-eol > out git diff --ignore-space-at-eol > out
test_expect_success 'another test, with --ignore-space-at-eol' 'test_cmp expect out' test_expect_success 'another test, with --ignore-space-at-eol' 'test_cmp expect out'
Expand Down
12 changes: 6 additions & 6 deletions xdiff/xemit.c
Expand Up @@ -87,7 +87,7 @@ static long def_ff(const char *rec, long len, char *buf, long sz, void *priv)


static int xdl_emit_common(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb, static int xdl_emit_common(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
xdemitconf_t const *xecfg) { xdemitconf_t const *xecfg) {
xdfile_t *xdf = &xe->xdf1; xdfile_t *xdf = &xe->xdf2;
const char *rchg = xdf->rchg; const char *rchg = xdf->rchg;
long ix; long ix;


Expand Down Expand Up @@ -151,16 +151,16 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
/* /*
* Emit pre-context. * Emit pre-context.
*/ */
for (; s1 < xch->i1; s1++) for (; s2 < xch->i2; s2++)
if (xdl_emit_record(&xe->xdf1, s1, " ", ecb) < 0) if (xdl_emit_record(&xe->xdf2, s2, " ", ecb) < 0)
return -1; return -1;


for (s1 = xch->i1, s2 = xch->i2;; xch = xch->next) { for (s1 = xch->i1, s2 = xch->i2;; xch = xch->next) {
/* /*
* Merge previous with current change atom. * Merge previous with current change atom.
*/ */
for (; s1 < xch->i1 && s2 < xch->i2; s1++, s2++) for (; s1 < xch->i1 && s2 < xch->i2; s1++, s2++)
if (xdl_emit_record(&xe->xdf1, s1, " ", ecb) < 0) if (xdl_emit_record(&xe->xdf2, s2, " ", ecb) < 0)
return -1; return -1;


/* /*
Expand All @@ -186,8 +186,8 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
/* /*
* Emit post-context. * Emit post-context.
*/ */
for (s1 = xche->i1 + xche->chg1; s1 < e1; s1++) for (s2 = xche->i2 + xche->chg2; s2 < e2; s2++)
if (xdl_emit_record(&xe->xdf1, s1, " ", ecb) < 0) if (xdl_emit_record(&xe->xdf2, s2, " ", ecb) < 0)
return -1; return -1;
} }


Expand Down

0 comments on commit baf5aaa

Please sign in to comment.