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

[RFH] bug in unpack_trees

From
Jeff King <peff@peff.net>
Date
Mar 4, 2008, 11:59 UTC
Message-ID
<20080304115940.GA5260@sigill.intra.peff.net>

I am tracking down a bug in unpack_trees, but I can't seem to find the exact problem; I'm hoping to get help from people who have touched this code a bit more than I have.

You can see the problem with this script:
  # make a repo
  mkdir repo && cd repo && git init
  # make a directory which will become a df conflict
  mkdir df
  echo content >df/file
  git add df/file
  git commit -m one
  # and save a copy of the index
  git ls-files >index1
  # now make a new commit that has the df conflict and
  # a newly added file
  rm -rf df
  echo content >df
  git add df
  echo content >new
  git add new
  git commit -m two
  # now this should put our index exactly back to 'one'
  git reset --hard HEAD^
  # but it doesn't
  git ls-files >index2
  diff -u index1 index2

The 'new' file is still in the index, and it shouldn't be. It's actually not git-reset to blame, but the "git read-tree -u --reset HEAD^" that it calls. The problem reproduces with every version of git I tried, so I suspect it is as old as unpack_trees.

As far as I can tell, the D/F conflict somehow gets the list merge out of sync. In unpack_trees_rec, every cache entry we look up gets compared to the first tree entry, but because we are out of sync, the tree entry will always become the new "first" (it looks like this test is supposed to be for processing foo/ before foo/bar, and shouldn't otherwise trigger). Because "first" and "cache_name" don't match, we don't realize we haven't found an entry missing from the tree, and we don't trigger the removal code.

So where I need help is figuring out how the traversal is _supposed_ to work. I.e., why does it get out of sync on the D/F case? I'm sure it's probably a one-liner fix, but I just don't see it.

-Peff
Next: Linus Torvalds
Message 1 of 9 in “[RFH] bug in unpack_trees”
  1. Jeff KingMar 4, 2008
  2. Linus TorvaldsMar 4, 2008
  3. Daniel BarkalowMar 5, 2008
  4. Linus TorvaldsMar 5, 2008
  5. Linus TorvaldsMar 6, 2008
  6. Linus TorvaldsMar 8, 2008
  7. Daniel BarkalowMar 8, 2008
  8. Jeff KingMar 13, 2008
  9. John GoerzenMar 14, 2008

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.