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

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

From
Zach Riggle <zachriggle@gmail.com>
Date
May 27, 2020, 22:29 UTC
Message-ID
<CAMP9c5k=Ci8eQyOdzW7a-sssgp9g9TJ+rxAAPF3YLDCr7t6wrg@mail.gmail.com>

Git grep is an amazing tool, and --show-function makes it very easy to create reports that contain not only line information, but the containing function as well.

It looks like there is an issue with how the parser handles "goto" labels, as it treats them the same as a function name.

In the example below, there is only one function, with two matches, but using --show-function indicates there are two function names.

$ cat test2.cpp
int main() {
    FOO
exit:
    FOO
}

$ git --version git version 2.26.2

$ git grep --no-index --show-function -e FOO test2.cpp test2.cpp=1=int main() { test2.cpp:2: FOO test2.cpp=3=exit: test2.cpp:4: FOO

Zach Riggle
Next: Jeff King
Message 1 of 7 in “git grep --show-function treats GOTO labels as function names”
  1. Zach RiggleMay 27, 2020
  2. Jeff KingMay 27, 2020
  3. Zach RiggleMay 27, 2020
  4. Zach RiggleMay 27, 2020
  5. Zach RiggleMay 27, 2020
  6. Jeff KingMay 27, 2020
  7. Johannes SixtMay 28, 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.