From: Zach Riggle <zachriggle@gmail.com>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org
Subject: Re: git grep --show-function treats GOTO labels as function names
Date: Wed, 27 May 2020 18:05:14 -0500 [thread overview]
Message-ID: <CAMP9c5nROh5DxbfwgKL3vNWsr=RYYgkEHCeaEMVN3gq1xkPkLA@mail.gmail.com> (raw)
In-Reply-To: <CAMP9c5m65hBXKgP76iUCGe79c_s5p106K6iwzJyPmm7fCsc7LA@mail.gmail.com>
I made a mistake copy-pasting; things work correctly when the
attribute is on the same line, but not when it is split:
$ cat attr.cpp
int main()
__attribute__ ( (no_sanitize("alignment")) )
{
FOO
}
Zach Riggle
On Wed, May 27, 2020 at 6:04 PM Zach Riggle <zachriggle@gmail.com> wrote:
>
> It looks like that does the trick for "goto" labels, but there are
> also some issue on function name parsing with attributes when they are
> split onto a second line.
>
> $ cat attr.cpp
> int main() __attribute__ ( (no_sanitize("alignment")) )
> {
> FOO
> }
> $ git grep --no-index --show-function -e FOO attr.cpp
> attr.cpp=2=__attribute__ ( (no_sanitize("alignment")) )
> attr.cpp:4: FOO
>
> Zach Riggle
>
> On Wed, May 27, 2020 at 5:54 PM Zach Riggle <zachriggle@gmail.com> wrote:
> >
> > Awesome, thanks!
> >
> >
> > Zach Riggle
> >
> > On Wed, May 27, 2020 at 5:48 PM Jeff King <peff@peff.net> wrote:
> > >
> > > On Wed, May 27, 2020 at 05:29:08PM -0500, Zach Riggle wrote:
> > >
> > > > It looks like there is an issue with how the parser handles "goto"
> > > > labels, as it treats them the same as a function name.
> > >
> > > By default, the function-finding isn't aware of the specific content in
> > > the file. But you can associate extensions with particular types, like:
> > >
> > > $ echo '*.cpp diff=cpp' >~/.gitattributes
> > > $ git config --global core.attributesFile ~/.gitattributes
> > > $ git grep --no-index --show-function -e FOO test2.cpp
> > > test2.cpp=int main() {
> > > test2.cpp: FOO
> > > test2.cpp: FOO
> > >
> > > Usually this is done in-repo, but since your example used --no-index, I
> > > showed how to set up a per-user attribute file. The "diff" attribute
> > > covers both diff and grep (for diff, the hunk headers will also show the
> > > function).
> > >
> > > The "cpp" diff regexes are built-in to the git binary. We just don't
> > > associate any filenames by default. You can also add your own; see the
> > > section "Defining a custom hunk-header" from "git help attributes".
> > >
> > > -Peff
next prev parent reply other threads:[~2020-05-27 23:05 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-27 22:29 git grep --show-function treats GOTO labels as function names Zach Riggle
2020-05-27 22:48 ` Jeff King
2020-05-27 22:54 ` Zach Riggle
2020-05-27 23:04 ` Zach Riggle
2020-05-27 23:05 ` Zach Riggle [this message]
2020-05-27 23:16 ` Jeff King
2020-05-28 19:01 ` Johannes Sixt
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAMP9c5nROh5DxbfwgKL3vNWsr=RYYgkEHCeaEMVN3gq1xkPkLA@mail.gmail.com' \
--to=zachriggle@gmail.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).