Skip to content

Commit 8e5dd94

Browse files
rscharfegitster
authored andcommitted
grep: -W: skip trailing empty lines at EOF, too
4aa2c47 (grep: -W: don't extend context to trailing empty lines, 2016-05-28) stopped showing empty lines at the end of function context when using -W. Do the same for trailing empty lines at the end of files, for consistency -- it doesn't matter whether a function section is ended by the next function or the end of the file. Test it by adding a trailing empty line to the file used by the test "grep -W" and leave its expected output the same. Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c2b3f2b commit 8e5dd94

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

grep.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1735,7 +1735,8 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle
17351735
peek_eol = end_of_line(peek_bol, &peek_left);
17361736
}
17371737

1738-
if (match_funcname(opt, gs, peek_bol, peek_eol))
1738+
if (peek_bol >= gs->buf + gs->size ||
1739+
match_funcname(opt, gs, peek_bol, peek_eol))
17391740
show_function = 0;
17401741
}
17411742
if (show_function ||

t/t7810-grep.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ int main(int argc, const char **argv)
3131
return 0;
3232
/* char ?? */
3333
}
34+
3435
EOF
3536

3637
test_expect_success setup '

0 commit comments

Comments
 (0)