Skip to content

Commit 9e6a4cf

Browse files
rscharfegitster
authored andcommitted
xdiff: -W: don't include common trailing empty lines in context
Empty lines between functions are shown by diff -W, as it considers them to be part of the function preceding them. They are not interesting in most languages. The previous patch stopped showing them in the special case of a function added at the end of a file. Stop extending context to those empty lines by skipping back over them from the start of the next function. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 392f6d3 commit 9e6a4cf

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

t/t4051-diff-function-context.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ test_expect_success ' context does not include preceding empty lines' '
8585
test "$(first_context_line <changed_hello.diff)" != " "
8686
'
8787

88-
test_expect_failure ' context does not include trailing empty lines' '
88+
test_expect_success ' context does not include trailing empty lines' '
8989
test "$(last_context_line <changed_hello.diff)" != " "
9090
'
9191

@@ -103,7 +103,7 @@ test_expect_success ' context does not include other functions' '
103103
test $(grep -c "^[ +-].*Begin" changed_includes.diff) -le 1
104104
'
105105

106-
test_expect_failure ' context does not include trailing empty lines' '
106+
test_expect_success ' context does not include trailing empty lines' '
107107
test "$(last_context_line <changed_includes.diff)" != " "
108108
'
109109

xdiff/xemit.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
231231
long fe1 = get_func_line(xe, xecfg, NULL,
232232
xche->i1 + xche->chg1,
233233
xe->xdf1.nrec);
234+
while (fe1 > 0 && is_empty_rec(&xe->xdf1, fe1 - 1))
235+
fe1--;
234236
if (fe1 < 0)
235237
fe1 = xe->xdf1.nrec;
236238
if (fe1 > e1) {

0 commit comments

Comments
 (0)