@matheusbsbs / matheus-bagliano / commits / 0bb313a552
Fork 0

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 <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Dec 5, 2019 at 17:15 UTC 0bb313a5529390276cf5c415891c804dea44fa34
2 files changed +18 -5
t/t4015-diff-whitespace.sh
+1 -5
@@ -2008,11 +2008,6 @@ test_expect_success 'compare mixed whitespace delta across moved blocks' '
2008 test_cmp expected actual
2009 '
2010
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.
2011 test_expect_success 'combine --ignore-blank-lines with --function-context' '
2012 test_write_lines 1 "" 2 3 4 5 >a &&
2013 test_write_lines 1 2 3 4 >b &&
@@ -2022,6 +2017,7 @@ test_expect_success 'combine --ignore-blank-lines with --function-context' '
2017 cat <<-\EOF >expect &&
2018 @@ -1,6 +1,4 @@
2019 1
2020 + -
2021 2
2022 3
2023 4
xdiff/xemit.c
+17
@@ -172,10 +172,12 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
172 struct func_line func_line = { 0 };
173
174 for (xch = xscr; xch; xch = xche->next) {
175 + xdchange_t *xchp = xch;
176 xche = xdl_get_hunk(&xch, xecfg);
177 if (!xch)
178 break;
179
180 +pre_context_calculation:
181 s1 = XDL_MAX(xch->i1 - xecfg->ctxlen, 0);
182 s2 = XDL_MAX(xch->i2 - xecfg->ctxlen, 0);
183
@@ -212,6 +214,21 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
214 if (fs1 < s1) {
215 s2 = XDL_MAX(s2 - (s1 - fs1), 0);
216 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 + }
232 }
233 }
234