Skip to content

commit-reach: stop single-result walk at the topo ceiling - #2341

Open
spkrka wants to merge 1 commit into
gitgitgadget:masterfrom
spkrka:mb-single-ceiling
Open

spkrka wants to merge 1 commit into
gitgitgadget:masterfrom
spkrka:mb-single-ceiling

Conversation

@spkrka

@spkrka spkrka commented Nov 30, 2026 •

Copy link
Copy Markdown

This is a small cleanup follow-up to my previous work on fast-exit
merge-base. It's not really less code, but it generalize the fast-exit
rule to apply to slightly more scenarios, though they are somewhat
unlikely to trigger in practice.

So the main value here is not any type of practical performance
boost, it's rather somewhat of a code hygiene fix.

That said, if this just feels like churning the code
for no reason, I don't mind dropping it instead.

"git merge-base" without --all stops the walk early when it finds a
merge base in the generation-ordered region of the commit-graph.
This optimization does not apply when the merge base is found
outside that region, e.g. among commits not yet in the commit-graph.

Generalize it to stop once a merge base has been found and the next
queued commit is in the ordered region, wherever the merge base was
found.  This is safe because no remaining commit can be a descendant
of a candidate found so far: no commit in the ordered region can
descend from one outside it, and descendants of a candidate inside it
were visited first.  Any redundancy among the candidates already
found is handled by remove_redundant().

The main benefit is simpler and broader logic.  The scenario is
unlikely to matter much in practice, so no benchmark is included.

Add a test with the merge base just outside the commit-graph.  Walk
steps in that test, before and after this change:

  commit-graph   before   after
  none               21      21
  full               11       3
  half               15      11
  no-gdat            18       3

No further tests are added, as the ways this exit condition can go
wrong are already well covered.  This was verified with simple
mutation testing:

 - Stopping at the first result even outside the ordered region,
   before a descendant candidate is found: the "clock skew, v1
   commit-graph" test in t6600, and "merge-base G H" and
   "unsynchronized clocks" in t6010.

 - Stopping at the ceiling without a result: t5318, t6099 and t6600.

 - Stopping early when --all is given: t5318 and t6600.

 - Not stopping at all: the new test, through its step counts.

Signed-off-by: Kristofer Karlsson <krka@spotify.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant