From: Junio C Hamano <gitster@pobox.com>
To: Zach Riggle <zachriggle@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: --function-context shows wrong function in chunk
Date: Fri, 10 Jul 2020 13:12:56 -0700 [thread overview]
Message-ID: <xmqqk0zbt9h3.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <CAMP9c5k5kLSqhCh9400iLdZ=+-nKonavOYpBSs_NHdaVVJ_ycQ@mail.gmail.com> (Zach Riggle's message of "Fri, 10 Jul 2020 13:38:30 -0500")
Zach Riggle <zachriggle@gmail.com> writes:
> When using --function-context, the function that is claimed at the top
> of the diff does not match the actual function.
>
> Note that the change exists in main, but the hunk header
> (terminology?) shows other_routine.
>
> $ git --version
> git version 2.27.0
>
> $ git diff -b --function-context
> diff --git i/example.c w/example.c
> index d87b59b..346e2a7 100644
> --- i/example.c
> +++ w/example.c
> @@ -4,5 +4,5 @@ int other_routine() {
> }
>
> int main() {
> -
> + puts("Hello, world!");
> }
>
> Zach Riggle
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.
It is logical because the first thing we see in the hunk, "}", is at
the end of "int other_routine() {" function; it does not conclude
the "int main() {" function. Saying "int main() {" there on the
hunk header line would be misleading and confusing. It sends a
wrong signal that there was such a line _before_ the first line we
see in this hunk, which is definitely not.
It is desirable because it gives more information than saying the
illogical "main". The reader can see what the routine before the
beginning of main function we see in the hunk is. In the above
example it may not matter, but if we see "return -1;" at the end of
that function and a call to other_routine() from main(), e.g.
@@ ... @@ int other_routine() {
return -1;
}
int main() {
- int i = other_routine();
+ int i = other_routine() ? 1 : 0;
printf("%d\n", i);
}
it would be more informative than having "int main() {" there.
next prev parent reply other threads:[~2020-07-10 20:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-10 18:38 --function-context shows wrong function in chunk Zach Riggle
2020-07-10 20:12 ` Junio C Hamano [this message]
2020-07-10 20:14 ` Zach Riggle
2020-07-10 21:12 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqk0zbt9h3.fsf@gitster.c.googlers.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=zachriggle@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).