Repository navigation
[kyo-sql-dolt] stageMerge: a merge left staged for the caller to commit once - #2007
Merged
Merged
Conversation
…it once ## Problem `Dolt.merge` either fast-forwards or commits the merge itself, so a caller cannot add its own rows to the merge commit. A caller that must write an anchor row into every commit on a branch has no way to do it for merges: a fast-forward puts the other branch's commits on it untouched, and a merge commit is already recorded before the caller can write. Two DoltLite defects surfaced while testing it: - A conflicting `merge` or `pull` raised the engine's error instead of answering `Dolt.Merge.Conflicted`. The engine rolls a conflicting merge back under autocommit before anything can read the conflicts. - `log(ref)` read the bare `dolt_log`, which lists only the current branch, so a commit that exists only on another branch was missing from that branch's log, and `commitAt` could not find it. ## Solution `Dolt.stageMerge(from)` is `git merge --no-ff --no-commit` on both engines. A clean merge answers `Dolt.Merge.Staged` and leaves the merged changes in the working set; the caller writes more and its next `commit` records one commit with both parents, holding the merged changes and the caller's writes. It never fast-forwards. `Dolt.Merge` becomes a sealed trait, and a new sealed `Dolt.StagedMerge` is what `stageMerge` answers: `UpToDate`, `Conflicted` or `Staged`. Each operation's answer type holds exactly the outcomes it can produce, so `merge` never answers `Staged` and `stageMerge` never answers `FastForward` or `Merged`. Both engines answer a staged merge like an up-to-date one, so `dolt_merge_status.is_merging` tells them apart. On DoltLite, a conflicting `merge`, `stageMerge` or `pull` now runs under autocommit and, when it fails, replays the call inside a transaction on one pinned session, reads the conflicts, and rolls back. It answers `Conflicted` and leaves the branch as it was. `log(ref)` and `commitAt` read `dolt_log(revision)`. ## Notes - Conflicts diverge between the engines, and the divergence is declared on `Dolt.merge` and `Dolt.Merge.Conflicted`: the server keeps a conflicted merge in the working set to resolve, while DoltLite never keeps conflicts past a transaction, so it reports them and rolls back. Tests assert both sides. - Why a separate method rather than a flag or a new `merge` case is recorded in `kyo-sql/CONTRIBUTING.md`. - Tests: `DoltLiteClientTest` 18 passed, 1 cancelled (the engine-absent leaf) on JVM, JS, Wasm and Native. `SqlDoltOnlyTest` against a Dolt 2.3.4 server in podman: 22 passed on JVM, JS, Wasm and Native. Both cover the fast-forward-possible case (two parents, the caller's rows in the same commit, the branch unmoved until commit), diverged branches, up to date, and conflicts.
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.
Problem
Dolt.mergeeither fast-forwards or commits the merge itself, so a caller cannot add its own rows to the merge commit. A caller that must write an anchor row into every commit on a branch has no way to do it for merges: a fast-forward puts the other branch's commits on it untouched, and a merge commit is already recorded before the caller can write.Two DoltLite defects surfaced while testing it:
mergeorpullraised the engine's error instead of answeringDolt.Merge.Conflicted. The engine rolls a conflicting merge back under autocommit before anything can read the conflicts.log(ref)read the baredolt_log, which lists only the current branch, so a commit that exists only on another branch was missing from that branch's log, andcommitAtcould not find it.Solution
Dolt.stageMerge(from)isgit merge --no-ff --no-commiton both engines. A clean merge answersDolt.Merge.Stagedand leaves the merged changes in the working set; the caller writes more and its nextcommitrecords one commit with both parents, holding the merged changes and the caller's writes. It never fast-forwards.Dolt.Mergebecomes a sealed trait, and a new sealedDolt.StagedMergeis whatstageMergeanswers:UpToDate,ConflictedorStaged. Each operation's answer type holds exactly the outcomes it can produce, somergenever answersStagedandstageMergenever answersFastForwardorMerged. Both engines answer a staged merge like an up-to-date one, sodolt_merge_status.is_mergingtells them apart.On DoltLite, a conflicting
merge,stageMergeorpullnow runs under autocommit and, when it fails, replays the call inside a transaction on one pinned session, reads the conflicts, and rolls back. It answersConflictedand leaves the branch as it was.log(ref)andcommitAtreaddolt_log(revision).Notes
Dolt.mergeandDolt.Merge.Conflicted: the server keeps a conflicted merge in the working set to resolve, while DoltLite never keeps conflicts past a transaction, so it reports them and rolls back. Tests assert both sides.mergecase is recorded inkyo-sql/CONTRIBUTING.md.DoltLiteClientTest18 passed, 1 cancelled (the engine-absent leaf) on JVM, JS, Wasm and Native.SqlDoltOnlyTestagainst a Dolt 2.3.4 server in podman: 22 passed on JVM, JS, Wasm and Native. Both cover the fast-forward-possible case (two parents, the caller's rows in the same commit, the branch unmoved until commit), diverged branches, up to date, and conflicts.