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

[BUG] gitattribute macro expansion oddity

From
Jeff King <peff@peff.net>
Date
Jan 10, 2012, 07:03 UTC
Message-ID
<20120110070300.GA17086@sigill.intra.peff.net>

I'm seeing some very odd behavior with git's attribute expansion for diffs. You can see it with this repository:

  git clone git://github.com/libgit2/libgit2sharp.git
Try a diff of a non-binary file:
  $ git show 2a0f4bf7 LibGit2Sharp/Configuration.cs
  ...
  diff --git a/LibGit2Sharp/Configuration.cs b/LibGit2Sharp/Configuration.cs
  index 83cc9d6..9ab0b60 100644
  --- a/LibGit2Sharp/Configuration.cs
  +++ b/LibGit2Sharp/Configuration.cs

Looks OK. Now try a diff that also has a binary file (that is marked such via gitattributes):

  $ git show 2a0f4bf7 Lib/NativeBinaries/x86/git2.dll \
                      LibGit2Sharp/Configuration.cs
  ...
  diff --git a/Lib/NativeBinaries/x86/git2.dll b/Lib/NativeBinaries/x86/git2.dll
  index dab0d04..8de18ab 100644
  Binary files a/Lib/NativeBinaries/x86/git2.dll and b/Lib/NativeBinaries/x86/git2.dll differ
  diff --git a/LibGit2Sharp/Configuration.cs b/LibGit2Sharp/Configuration.cs
  index 83cc9d6..9ab0b60 100644
  Binary files a/LibGit2Sharp/Configuration.cs and b/LibGit2Sharp/Configuration.cs differ
Now the Configuration.cs blobs appear binary!

It has nothing to do with pathspecs; if you do a non-limited diff of 2a0f4bf7, you'll see many of the files appear as binary. Running it through the debugger, it looks like we are getting wrong diff attribute values for later paths, as if the earlier lookups are somehow polluting the attribute stack.

The gitattributes in this repository look reasonably sane, but even if they were not, nothing should make a file have different attributes based on other files that were diffed.

Bisection points to ec775c4 (attr: Expand macros immediately when encountered., 2010-04-06), but it's too late for me to dig further tonight. Cc'ing Junio as the author of the attr code and Henrik as the author of ec775c4.

-Peff
Next: Michael Haggerty
Message 1 of 13 in “[BUG] gitattribute macro expansion oddity”
  1. Jeff KingJan 10, 2012
  2. Michael HaggertyJan 10, 2012
  3. Jeff KingJan 10, 2012
  4. attr: don't confuse prefixes with leading directoriesJeff King, Jan 10, 2012
  5. Jeff KingJan 10, 2012
  6. Junio C HamanoJan 10, 2012
  7. Jeff KingJan 10, 2012
  8. Jeff KingJan 10, 2012
  9. Junio C HamanoJan 10, 2012
  10. Jeff KingJan 10, 2012
  11. Junio C HamanoJan 10, 2012
  12. Junio C HamanoJan 10, 2012
  13. Michael HaggertyJan 11, 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.