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

Re: [PATCH v2 2/2] commit-graph: fix writing first commit-graph during fetch

From
SZEDER Gábor <szeder.dev@gmail.com>
Date
Oct 30, 2019, 14:31 UTC
Message-ID
<20191030143142.GW4348@szeder.dev>
In-Reply-To
<e2eb7b76-a29b-04c4-e698-f3a67ae56ecc@gmail.com>
On Thu, Oct 24, 2019 at 06:39:51AM -0400, Derrick Stolee wrote:
Show 43 quoted lines
> >> Instead, I finally arrived on the conclusion that I should use a flag
> >> that is not used in any other part of the code. In commit-reach.c, a
> >> number of flags were defined for commit walk algorithms. The REACHABLE
> >> flag seemed like it made the most sense, and it seems it was not
> >> actually used in the file. The REACHABLE flag was used in early versions
> >> of commit-reach.c, but was removed by 4fbcca4 (commit-reach: make
> >> can_all_from_reach... linear, 2018-07-20).
> >>
> >> Add the REACHABLE flag to commit-graph.c and use it instead of
> >> UNINTERESTING in close_reachable(). This fixes the bug in manual
> >> testing.
> > 
> > I'm inclined to agree that using a flag that is not used anywhere else
> > is the safest thing to do, and at -rcX time safest is good.  I'm not
> > sure whether it's the right thing to do in the long term, though.
> > 
> > Furthermore, calling this flag REACHABLE is misleading, because the
> > code actually means SEEN.
> > Consider the following sequence of commands:
> > 
> >   # Create a pack with two commits
> >   $ git commit --allow-empty -m one &&
> >   $ git commit --allow-empty -m two &&
> >   $ git repack -ad &&
> >   # Make one of those commits unreachable
> >   $ git reset --hard HEAD^ &&
> >   # Not even from reflogs!
> >   $ git reflog expire --expire-unreachable=now --all
> >   # Now write a commit-graph from that pack file
> >   $ git commit-graph write
> >   Computing commit graph generation numbers: 100% (2/2), done.
> > 
> > It added two commits to the commit-graph, although one of them is
> > clearly not reachable anymore, so marking it as REACHABLE while
> > enumerating all commits feels wrong.
> 
> Since you are using "git commit-graph write", the command is scanning
> all pack-files for commits to include. Even in this case, the
> close_reachable() method needs to walk to see if any commits are missing.
> (It could be that the root commit is loose for some strange reason.)
> 
> In this case, we are marking REACHABLE the commits that can be reached
> from our "starting" commits. In your example we start with every commit.

That's exactly my point. fsck already uses the REACHABLE flag to mark objects that are reachable not only from all refs (including the HEADs of all worktrees), but their reflogs and the index as well.

However, in close_unreachable() we start with a bunch of commits and then go into a loop adding their parents to an array, while marking each parent to prevent them from being added multiple times in a mergy history. We have a good couple of similar traversals in our code base, and in revision.c, builtin/describe.c, walker.c, negotiator/default.c (and at this point I stopped looking) we mark those parents as SEEN.

On a somewhat related note: 'git commit-graph write --reachable' doesn't include HEAD; should it?

Show 10 quoted lines
> If you had used `git commit-graph write --stdin-packs` and provided a
> small pack name over stdin, the concept would be similar and even more
> pronounced: the pack (perhaps downloaded via 'fetch') is not likely to
> contain every commit, so we need to walk all reachable commits from
> those included.
> 
> I'll have a v3 today with the requested fixes.
> 
> Thanks,
> -Stolee
Previous: Derrick StoleeNext: Derrick Stolee via GitGitGadget
Message 17 of 23 in “[v2.24.0-rc0 BUG] fetch.writeCommitGraph fails on first fetch”
  1. 0/1 [v2.24.0-rc0 BUG] fetch.writeCommitGraph fails on first fetchDerrick Stolee via GitGitGadget, Oct 22, 2019
  2. 1/1 commit-graph: fix writing first commit-graph during fetchDerrick Stolee via GitGitGadget, Oct 22, 2019
  3. Jeff KingOct 22, 2019
  4. Jeff KingOct 22, 2019
  5. SZEDER GáborOct 22, 2019
  6. Derrick StoleeOct 23, 2019
  7. Jeff KingOct 23, 2019
  8. Jeff KingOct 23, 2019
  9. 0/2 [v2.24.0-rc0 BUG] fetch.writeCommitGraph fails on first fetchDerrick Stolee via GitGitGadget, Oct 23, 2019
  10. 1/2 t5510-fetch.sh: demonstrate fetch.writeCommitGraph bugDerrick Stolee via GitGitGadget, Oct 23, 2019
  11. SZEDER GáborOct 23, 2019
  12. Derrick StoleeOct 23, 2019
  13. SZEDER GáborOct 24, 2019
  14. 2/2 commit-graph: fix writing first commit-graph during fetchDerrick Stolee via GitGitGadget, Oct 23, 2019
  15. SZEDER GáborOct 23, 2019
  16. Derrick StoleeOct 24, 2019
  17. SZEDER GáborOct 30, 2019
  18. 0/2 [v2.24.0-rc0 BUG] fetch.writeCommitGraph fails on first fetchDerrick Stolee via GitGitGadget, Oct 24, 2019
  19. 1/2 t5510-fetch.sh: demonstrate fetch.writeCommitGraph bugDerrick Stolee via GitGitGadget, Oct 24, 2019
  20. 2/2 commit-graph: fix writing first commit-graph during fetchDerrick Stolee via GitGitGadget, Oct 24, 2019
  21. 0/2 [v2.24.0-rc0 BUG] fetch.writeCommitGraph fails on first fetchDerrick Stolee via GitGitGadget, Oct 24, 2019
  22. 1/2 t5510-fetch.sh: demonstrate fetch.writeCommitGraph bugDerrick Stolee via GitGitGadget, Oct 24, 2019
  23. 2/2 commit-graph: fix writing first commit-graph during fetchDerrick Stolee via GitGitGadget, Oct 24, 2019

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.