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

Re: [PATCH 1/1] git-grep: improve the --show-function behaviour

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 13, 2023, 00:31 UTC
Message-ID
<xmqq1qf2lxrm.fsf@gitster.g>
In-Reply-To
<df05f761-c498-6930-bfd8-265f7e23d8ee@web.de>
René Scharfe <l.s.r@web.de> writes:
Show 19 quoted lines
>>> To me, this behaviour looks as
>>>
>>> 		Show the preceding line that contains the function name of
>>> 		the match, unless the _PREVIOUS_ matching line is a function
>>> 		name itself.
>
> To me it looks like:
>
> 		Show the preceding line that contains the function name of
> 		the match.
>
> ("Show" meaning "show once", not "show for each match again and again".)
>
> Or:
>
> 		Show the preceding line that contains the function name of
> 		the match, unless it is already shown for a different
> 		reason, e.g. as a match or as the function line of a
> 		previous match.

Wow, that was a mouthful, but matches my understanding. I naïvely thought "when showing a hit, we may add the line that matches the function header pattern before the hit even that header line does not hit the grep pattern. But if the header line does hit the grep pattern, we do not bother show the same thing twice." was a reasonable goal to have.

Show 13 quoted lines
> Indeed that matches the letter of the documentation.
>
>> 	$ ./git grep --untracked -pn xxx TEST2.c
>> 	TEST2.c:1:void func(xxx)
>> 	TEST2.c=1=void func(xxx)
>> 	TEST2.c:3:      use(xxx);
>
> That one as well.
>
>> Or I am totally confused?
>
> No, I think the documentation is wrong.  I'd simply remove the part
> after the comma, but there are probably better options.

Documentation may not match the behaviour, but do we know what the behaviour we want is? To me, the last example that shows the same line twice (one as a real hit, the other because of "-p") looks a bit counter-intuitive for the purpose of "help me locate where the grep hits are". I dunno.

Previous: René ScharfeNext: Oleg Nesterov
Message 10 of 15 in “git-grep: improve the --show-function behaviour”
  1. 0/1 git-grep: improve the --show-function behaviourOleg Nesterov, Sep 11, 2023
  2. 1/1 git-grep: improve the --show-function behaviourOleg Nesterov, Sep 11, 2023
  3. René ScharfeSep 11, 2023
  4. Oleg NesterovSep 11, 2023
  5. Junio C HamanoSep 11, 2023
  6. Oleg NesterovSep 11, 2023
  7. Oleg NesterovSep 12, 2023
  8. Oleg NesterovSep 12, 2023
  9. René ScharfeSep 12, 2023
  10. Junio C HamanoSep 13, 2023
  11. Oleg NesterovSep 13, 2023
  12. René ScharfeSep 14, 2023
  13. Oleg NesterovSep 17, 2023
  14. René ScharfeSep 14, 2023
  15. Oleg NesterovSep 13, 2023

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.