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.