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
ONOleg Nesterov <oleg@redhat.com>
Date
Sep 12, 2023, 13:04 UTC
Message-ID
<20230912130429.GA9982@redhat.com>
In-Reply-To
<20230911231756.GA2840@redhat.com>
René, Junio,

I don't like the fact we can't understand each other ;) Could you please explain why do you think this patch should update the docs?

Please forget about my patch for the moment. Lets start from the very beginning:

	-p::
	--show-function::
		Show the preceding line that contains the function name of
		the match, unless the matching line is a function name itself.

and in my opinion, it is the current behaviour that doesn't match the documentation.

-------------------------------------------------------------------------
	$ cat TEST1.c
	void func1()
	{
	}
	void func2()
	{
	}
	$ git grep --untracked -pn func2 TEST1.c
	TEST1.c=1=void func1()
	TEST1.c:4:void func2()

in this case the matching line is "void func2()" and it is also a function name itself, in this case git-grep should not show "=void func1()" which is "the preceding line that contains the function name of the match.

But it does. So perhaps git-grep needs another change, something like
	if (match_funcname(opt, gs, bol, end_of_line(...)))
		return;

at the start of show_funcname_line(), but my patch does not change this behaviour.

--------------------------------------------------------------------------
	$ cat TEST2.c
	void func(xxx)
	{
		use(xxx);
	}
	$ git grep --untracked -pn xxx TEST2.c
	TEST2.c:1:void func(xxx)
	TEST2.c:3:      use(xxx)

the 2nd match is use(xxx) and it is not a function name itself, in this case git-grep should "Show the preceding line that contains the function name of the match.

But it doesn't. 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.
Now, with my patch we have
	$ ./git grep --untracked -pn xxx TEST2.c
	TEST2.c:1:void func(xxx)
	TEST2.c=1=void func(xxx)
	TEST2.c:3:      use(xxx);
and unless I am totatlly confused this does match the documentation.
Oleg.
Previous: Oleg NesterovNext: Oleg Nesterov
Message 7 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.