git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] grep: -W: skip trailing empty lines at EOF, too

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 30, 2024, 16:58 UTC
Message-ID
<xmqqle1ierzq.fsf@gitster.g>
In-Reply-To
<8b90e0ec-251f-46b3-8777-96efd58e227b@web.de>
René Scharfe <l.s.r@web.de> writes:
Show 5 quoted lines
> 4aa2c4753d (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.
Nice, and the implementation reflects the above logic.
Show 37 quoted lines
> 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 <l.s.r@web.de>
> ---
>  grep.c          | 3 ++-
>  t/t7810-grep.sh | 1 +
>  2 files changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/grep.c b/grep.c
> index ac34bfeafb..2f8b9553df 100644
> --- a/grep.c
> +++ b/grep.c
> @@ -1735,7 +1735,8 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle
>  				peek_eol = end_of_line(peek_bol, &peek_left);
>  			}
>
> -			if (match_funcname(opt, gs, peek_bol, peek_eol))
> +			if (peek_bol >= gs->buf + gs->size ||
> +			    match_funcname(opt, gs, peek_bol, peek_eol))
>  				show_function = 0;
>  		}
>  		if (show_function ||
> diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh
> index 875dcfd98f..af2cf2f78a 100755
> --- a/t/t7810-grep.sh
> +++ b/t/t7810-grep.sh
> @@ -31,6 +31,7 @@ int main(int argc, const char **argv)
>  	return 0;
>  	/* char ?? */
>  }
> +
>  EOF
>
>  test_expect_success setup '
> --
> 2.46.0
Previous: René Scharfe
Message 2 of 2 in “grep: -W: skip trailing empty lines at EOF, too”
  1. grep: -W: skip trailing empty lines at EOF, tooRené Scharfe, Jul 30, 2024
  2. Junio C HamanoJul 30, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.