commit-reach: fix !FIND_ALL early exit with v1 commit graph#2162
Open
spkrka wants to merge 2 commits into
Open
commit-reach: fix !FIND_ALL early exit with v1 commit graph#2162spkrka wants to merge 2 commits into
spkrka wants to merge 2 commits into
Conversation
Add a topology where the correct merge base (M2) has a lower committer date than its ancestor (M1) due to clock skew. With a v1 commit graph (topological levels only, no corrected commit dates), paint_down_to_common() falls back to commit-date ordering. In that mode, M1 pops before M2, acquires both paint sides, and the !FIND_ALL early exit fires -- returning the wrong merge base. Mark the test as test_expect_failure to document the bug; the next commit will fix it. Signed-off-by: Kristofer Karlsson <krka@spotify.com>
When paint_down_to_common() falls back to commit-date ordering (for v1 commit graphs without corrected commit dates), the !FIND_ALL early exit incorrectly fires. The exit assumes the queue is generation- ordered, so the first RESULT commit found must be the shallowest. With date ordering this is not guaranteed: a closer merge base with a lower committer date (clock skew) may still be in the queue behind deeper commits. Add a gen_ordered flag that is cleared when the date fallback fires, and require it for the early exit. Update the test from the previous commit to test_expect_success. Signed-off-by: Kristofer Karlsson <krka@spotify.com>
Author
|
/submit |
|
Submitted as pull.2162.git.1782739162.gitgitgadget@gmail.com To fetch this version into To fetch this version to local tag |
|
This branch is now known as |
|
This patch series was integrated into seen via git@a560473. |
|
Junio C Hamano wrote on the Git mailing list (how to reply to this email): "Kristofer Karlsson via GitGitGadget" <gitgitgadget@gmail.com>
writes:
> Fixes a bug introduced by 93e5b1680e (commit-reach: early exit
> paint_down_to_common for single merge-base, 2025-04-10) where git merge-base
> can return the wrong result.
>
> The bug requires all of the following to trigger:
>
> 1. A v1 commit graph (topological levels only, no corrected commit dates).
> Generation v2 with corrected commit dates has been the default since
> 2021, so only repos that have not rewritten their commit graph in over
> four years would be affected.
> 2. git merge-base without --all (the common case, but --all is unaffected
> because it disables the early exit).
> 3. A topology with clock skew: the correct merge base has a lower committer
> date than one of its ancestors that is also a common ancestor. With date
> ordering, the deeper ancestor pops first and the early exit fires before
> the correct result is found.
>
> This two-patch series:
>
> 1. Adds a test demonstrating the bug (clock-skew topology where the correct
> merge base has a lower date than its ancestor)
> 2. Fixes it by tracking whether the queue is generation-ordered and gating
> the early exit on that flag
Where should this new "gen_ordered" flag go in the world with
kk/merge-base-exhaustion topic merged in? Does it also belong
to the paint_state struct or can it be on-stack independent variable
to the function?
|
|
Kristofer Karlsson wrote on the Git mailing list (how to reply to this email): On Mon, 29 Jun 2026 at 19:50, Junio C Hamano <gitster@pobox.com> wrote:
>
> Where should this new "gen_ordered" flag go in the world with
> kk/merge-base-exhaustion topic merged in? Does it also belong
> to the paint_state struct or can it be on-stack independent variable
> to the function?
I don't think kk/merge-base-exhaustion is ready to be merged as-is
and you are right that these two topics would conflict.
I will need to reroll v5 and exactly how/when I do that
depends on what we do here.
I wanted to quickly share this small patch as a bugfix
since the related code is already merged. I think the bug
itself might be a very unlikely edge case but I can't really be
sure.
My preference would be to merge this as-is, and then I can rework
v5 of kk/merge-base-exhaustion on top of it later - it will
add some delay but I don't want to rush it since it's a non-trivial
change.
The other option is to drop this topic if the risk is deemed low
enough, and then I will rework v5 to either apply a similar
gen_ordered flag or eliminate that different ordering entirely -
I see that as a good long-term goal that simplifies the code while
retaining or improving the performance.
I realize the timing is terrible, I wish I had spotted this a week
ago instead of right at the 2.55 finalization period.
Thanks,
Kristofer |
|
User |
|
Junio C Hamano wrote on the Git mailing list (how to reply to this email): Kristofer Karlsson <krka@spotify.com> writes:
> My preference would be to merge this as-is, and then I can rework
> v5 of kk/merge-base-exhaustion on top of it later - it will
> add some delay but I don't want to rush it since it's a non-trivial
> change.
That sounds very sensible. Let's do that.
I've taken a look at both of these two patches and found the
solution quite sensible, but I'd prefer a second set of eyes
to confirm.
Thanks. |
|
There was a status update in the "New Topics" section about the branch The early-exit optimization in paint_down_to_common() has been gated on the queue being generation-ordered. This fixes a bug where git merge-base (without --all) could return incorrect results on repositories with v1 commit graphs and clock skew. Comments? cf. <xmqqa4sdw55v.fsf@gitster.g> source: <pull.2162.git.1782739162.gitgitgadget@gmail.com> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes a bug introduced by 93e5b16 (commit-reach: early exit
paint_down_to_common for single merge-base, 2025-04-10) where
git merge-basecan return the wrong result.The bug requires all of the following to trigger:
dates). Generation v2 with corrected commit dates has been the
default since 2021, so only repos that have not rewritten their
commit graph in over four years would be affected.
git merge-basewithout--all(the common case, but--allis unaffected because it disables the early exit).
committer date than one of its ancestors that is also a common
ancestor. With date ordering, the deeper ancestor pops first
and the early exit fires before the correct result is found.
This two-patch series:
correct merge base has a lower date than its ancestor)
gating the early exit on that flag
cc: Junio C Hamano gitster@pobox.com
cc: Derrick Stolee stolee@gmail.com
cc: Kristofer Karlsson krka@spotify.com