Re: git grep --show-function treats GOTO labels as function names

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux