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

Re: --function-context shows wrong function in chunk

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 10, 2020, 21:12 UTC
Message-ID
<xmqqimevrs4o.fsf@gitster.c.googlers.com>
In-Reply-To
<CAMP9c5kzRoVKEQMMVt_tnRMrayP+yT0c+Q2xxewbrZN8piCbHQ@mail.gmail.com>
Zach Riggle <zachriggle@gmail.com> writes:
[administrivia: do not top-post]
Show 8 quoted lines
>> I think it is possible to modify the "find the line that match
>> xfuncname pattern" logic to start scanning backwards from the first
>> actual change (i.e. the blank line in the preimage of the patch
>> inside "int main() {" function in your example) and make the hunk
>> header say "int main() {" instead of "int other_routine() {".
>>
>> I however doubt that such a change makes any sense.  In fact, I find
>> the sample output above both quite logical and also even desirable.
> This happens even with -U0 which does not include the e.g. trailing
> bit of other_routine.

Sure, it does not change the equation, though. We are finding the line that matches the xfuncname pattern before the first line of the hunk, which is "int other_routine() {" in your example.

Show 10 quoted lines
> $ git diff -U0 -b --function-context
> diff --git i/example.c w/example.c
> index d87b59b..346e2a7 100644
> --- i/example.c
> +++ w/example.c
> @@ -6,3 +6,3 @@ int other_routine() {
>  int main() {
> -
> +    puts("Hello, world!");
>  }

In your updated example, the line "int main() {" is the first line of the hunk, and not a line before it.

If we said "int main() {" there, it would send a wrong signal that there is another such line before the "int main() {" we see in the hunk.

Previous: Zach Riggle
Message 4 of 4 in “--function-context shows wrong function in chunk”
  1. Zach RiggleJul 10, 2020
  2. Junio C HamanoJul 10, 2020
  3. Zach RiggleJul 10, 2020
  4. Junio C HamanoJul 10, 2020

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.