Skip to content

Commit f0070a7

Browse files
committed
Merge branch 'rs/xdiff-ignore-ws-w-func-context'
The "diff" machinery learned not to lose added/removed blank lines in the context when --ignore-blank-lines and --function-context are used at the same time. * rs/xdiff-ignore-ws-w-func-context: xdiff: unignore changes in function context
2 parents 71a7de7 + 0bb313a commit f0070a7

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

t/t4015-diff-whitespace.sh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2050,11 +2050,6 @@ test_expect_success 'compare mixed whitespace delta across moved blocks' '
20502050
test_cmp expected actual
20512051
'
20522052

2053-
# Note that the "6" in the expected hunk header below is funny, since we only
2054-
# show 5 lines (the missing one was blank and thus ignored). This is how
2055-
# --ignore-blank-lines behaves even without --function-context, and this test
2056-
# is just checking the interaction of the two features. Don't take it as an
2057-
# endorsement of that output.
20582053
test_expect_success 'combine --ignore-blank-lines with --function-context' '
20592054
test_write_lines 1 "" 2 3 4 5 >a &&
20602055
test_write_lines 1 2 3 4 >b &&
@@ -2064,6 +2059,7 @@ test_expect_success 'combine --ignore-blank-lines with --function-context' '
20642059
cat <<-\EOF >expect &&
20652060
@@ -1,6 +1,4 @@
20662061
1
2062+
-
20672063
2
20682064
3
20692065
4

xdiff/xemit.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,12 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
172172
struct func_line func_line = { 0 };
173173

174174
for (xch = xscr; xch; xch = xche->next) {
175+
xdchange_t *xchp = xch;
175176
xche = xdl_get_hunk(&xch, xecfg);
176177
if (!xch)
177178
break;
178179

180+
pre_context_calculation:
179181
s1 = XDL_MAX(xch->i1 - xecfg->ctxlen, 0);
180182
s2 = XDL_MAX(xch->i2 - xecfg->ctxlen, 0);
181183

@@ -212,6 +214,21 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
212214
if (fs1 < s1) {
213215
s2 = XDL_MAX(s2 - (s1 - fs1), 0);
214216
s1 = fs1;
217+
218+
/*
219+
* Did we extend context upwards into an
220+
* ignored change?
221+
*/
222+
while (xchp != xch &&
223+
xchp->i1 + xchp->chg1 <= s1 &&
224+
xchp->i2 + xchp->chg2 <= s2)
225+
xchp = xchp->next;
226+
227+
/* If so, show it after all. */
228+
if (xchp != xch) {
229+
xch = xchp;
230+
goto pre_context_calculation;
231+
}
215232
}
216233
}
217234

0 commit comments

Comments
 (0)