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

misleading diff-hunk header

From
TCTim Chase <git@tim.thechases.com>
Date
Aug 21, 2012, 12:57 UTC
Message-ID
<503385D0.5070605@tim.thechases.com>

[posted originally to git-users@ but advised this would be a better forum]

diff.{type}.xfuncname seems to start searching backwards in from the beginning of the hunk, not the first differing line.

To reproduce:
  $ mkdir tmp
  $ cd tmp
  $ git init
  $ cat > foo.c <<EOF
  int call_me(int maybe)
  {
  }
  int main()
  {
  }
  EOF
  $ git add foo.c
  $ git commit -m "Initial checkin"
  $ ed foo.c
  # main() should return 0
  $i
    return 0;
  .
  wq
  $ git diff
The diff returns a header line of
  @@ -4,4 +4,5 @@ int call_me(int maybe)
   int main()
   {
  +  return 0;
   }

misleadingly suggesting that the change occurred in the call_me() function, rather than in main()

I'm running 1.7.2.5 from Debian Stable if that makes a difference.
Is this expected/proper behavior?
-tkc

FWIW, I stumbled across this tinkering with diff.{typename}.xfuncname detailed in gitattributes(5)

Next: Thomas Rast
Message 1 of 14 in “misleading diff-hunk header”
  1. Tim ChaseAug 21, 2012
  2. Thomas RastAug 21, 2012
  3. Tim ChaseAug 21, 2012
  4. Johannes SixtAug 21, 2012
  5. Junio C HamanoAug 21, 2012
  6. Junio C HamanoAug 21, 2012
  7. Jeff KingAug 24, 2012
  8. Tim ChaseAug 24, 2012
  9. Jeff KingAug 24, 2012
  10. Tim ChaseAug 25, 2012
  11. Junio C HamanoAug 25, 2012
  12. Tim ChaseAug 25, 2012
  13. Stefano LattariniAug 26, 2012
  14. Junio C HamanoAug 26, 2012

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.