Skip to content

Commit 5c3ed90

Browse files
rscharfegitster
authored andcommitted
xdiff: show non-empty lines before functions with -W
Non-empty lines before a function definition are most likely comments for that function and thus relevant. Include them in function context. Such a non-empty line might also belong to the preceeding function if there is no separating blank line. Stop extending the context upwards also at the next function line to make sure only one extra function body is shown at most. Original-patch-by: Vegard Nossum <[email protected]> Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cde32bf commit 5c3ed90

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

t/t4051-diff-function-context.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ test_expect_success 'setup' '
8585

8686
check_diff changed_hello 'changed function'
8787

88-
test_expect_failure ' context includes comment' '
88+
test_expect_success ' context includes comment' '
8989
grep "^ .*Hello comment" changed_hello.diff
9090
'
9191

xdiff/xemit.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
204204
}
205205

206206
fs1 = get_func_line(xe, xecfg, NULL, i1, -1);
207+
while (fs1 > 0 && !is_empty_rec(&xe->xdf1, fs1 - 1) &&
208+
!is_func_rec(&xe->xdf1, xecfg, fs1 - 1))
209+
fs1--;
207210
if (fs1 < 0)
208211
fs1 = 0;
209212
if (fs1 < s1) {

0 commit comments

Comments
 (0)