Skip to content

Commit 0bb313a

Browse files
rscharfegitster
authored andcommitted
xdiff: unignore changes in function context
Changes involving only blank lines are hidden with --ignore-blank-lines, unless they appear in the context lines of other changes. This is handled by xdl_get_hunk() for context added by --inter-hunk-context, -u and -U. Function context for -W and --function-context added by xdl_emit_diff() doesn't pay attention to such ignored changes; it relies fully on xdl_get_hunk() and shows just the post-image of ignored changes appearing in function context. That's inconsistent and confusing. Improve the result of using --ignore-blank-lines and --function-context together by fully showing ignored changes if they happen to fall within function context. Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5fa0f52 commit 0bb313a

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
@@ -2008,11 +2008,6 @@ test_expect_success 'compare mixed whitespace delta across moved blocks' '
20082008
test_cmp expected actual
20092009
'
20102010

2011-
# Note that the "6" in the expected hunk header below is funny, since we only
2012-
# show 5 lines (the missing one was blank and thus ignored). This is how
2013-
# --ignore-blank-lines behaves even without --function-context, and this test
2014-
# is just checking the interaction of the two features. Don't take it as an
2015-
# endorsement of that output.
20162011
test_expect_success 'combine --ignore-blank-lines with --function-context' '
20172012
test_write_lines 1 "" 2 3 4 5 >a &&
20182013
test_write_lines 1 2 3 4 >b &&
@@ -2022,6 +2017,7 @@ test_expect_success 'combine --ignore-blank-lines with --function-context' '
20222017
cat <<-\EOF >expect &&
20232018
@@ -1,6 +1,4 @@
20242019
1
2020+
-
20252021
2
20262022
3
20272023
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)