-
Notifications
You must be signed in to change notification settings - Fork 35
Merging branches
- Merge
- Rebase
- Forward Merge
- With conflict detection (default, slower)
- Without conflict detection (using
--force
)
Due to its nature, there are no conflicts on a forward merge. So no conflict detection is used.
PRAGMA branch_merge [--check|--force] {source} [{dest}]
PRAGMA branch_rebase [--check|--force] [{to_rebase}] {new_base} [{new_branch}]
Where to_rebase
can be:
- a branch name
- a single commit, like
branch.commit
- a commit range, like
branch.start-
If to_rebase
is omited then it rebases the current branch
When rebasing a single commit or a range of commits to an internal commit we must supply the name for the new_branch
that will be created.
We can also rebase them to the end of a branch. In this case if no new_branch
name is supplied, the commit(s) will be rebased onto the destination branch.
PRAGMA branch_merge --forward {parent} {child} {num_commits}
PRAGMA branch_merge --forward {parent} {child.commit}
Merging the test branch into the master branch:
PRAGMA branch=master
PRAGMA branch_merge test
Merging the test branch up to commit 25 into the master branch:
PRAGMA branch=master
PRAGMA branch_merge test.25
Rebasing the test branch onto the end of the master branch:
PRAGMA branch=test
PRAGMA branch_rebase master
Rebasing the test branch onto commit 20 of the master branch:
PRAGMA branch=test
PRAGMA branch_rebase master.20
Advancing the master branch 3 commits in the direction of the test branch:
PRAGMA branch_merge --forward master test 3
Advancing the master branch in the direction of the test branch up to commit 25:
PRAGMA branch_merge --forward master test.25
LiteTree performs will perform conflict detection by default on merge and rebase operations.
If you want to omit it, use the --force
parameter, like this:
PRAGMA branch=master
PRAGMA branch_merge --force test
PRAGMA branch=test
PRAGMA branch_rebase --force master
If you want to perform just a conflict detection you can use the --check
parameter on both merge and rebase operations. eg:
PRAGMA branch=master
PRAGMA branch_merge --check test
PRAGMA branch=test
PRAGMA branch_rebase --check master
On these cases no merge or rebase is performed.
Use the stored SQL commands from the source branch and run them in the destination branch.
Problem: if a previous merge was already done (from previous or the same commit)
Solution 1: use the SQL commands starting at the last merge
This implies storing merge info/history.
- Easy to implement
- No conflict detection
- Merging can take a long time to be processed if the SQL commands are complex (because they are re-executed)
Compare all the rows from source and destination branches.
Detect duplicated and modified rows as conflicts that must be resolved in some way.
- Conflict detection
- Maybe faster at the merge stage
- Maybe slower at the scan stage
Rows that exist on source but not on the destination can be due to:
- They were inserted in the source
- They were deleted in the destination
How to detect the difference?
Use the Session / Changeset feature
- Conflict detection
- Does not deal with schema differences
Use a modified Session / Changeset feature with these changes:
-
Detect schema differences
-
Copy rows directly instead of generating SQL commands
- Conflict detection
- Deals with schema differences
- Maybe hard to implement
Just like option 4 but automatically choosing the best / faster merge approach (run SQL or copy rows directly)
- Conflict detection
- Deals with schema differences
- Maybe hard to implement
Either by:
-
Using our code in C
-
Using the SQLite VDBE
Notice that the SQL commands from option 1 come from the log / history and the others are generated by code. So the complexity and speed of execution may vary a lot.
(you can add your notes here bellow or participate in the discussion here)