Thread (5 messages) flat view 5 messages, 3 authors, 2023-09-17

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

From: Junio C Hamano <hidden>
Date: 2023-09-13 00:31:16

Possibly related (same subject, not in this thread)

René Scharfe [off-list ref] writes:
quoted
quoted
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.
Indeed that matches the letter of the documentation.
quoted
	$ ./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.
quoted
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.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help