Overview
Knit Merge is kind of merging that gives similar results to weave merge. It was introduced in bzr 0.8.
Like weave merge, it
- Uses historical information about the individual lines to determine which should appear.
- Handles criss-cross merging
- Handles cherrypicking (not currently implemented).
Unlike weave merge, it
- Uses annotation information rather than line identity
- Only requres historical information about differing lines.
- Can be applied to both Weave and Knit data files
Algorithm
Simple case
As described by Martin Pool:
- Do a two-way diff between the two versions to be merged. Within the difference regions, we need to determine whether each line is unborn, live, or killed in the other side. Taking the lines from the left-hand-side conflict region first, get the line origins. If that origin is in the merged-revisions set of the right hand side, then the line has been deleted (or moved) on the right hand side. Otherwise, it's new on the left hand side.
Extension to cherry-picks
One way to expand support for cherry-picks is as follows:
Given a cherrypick BASE, generate a second merge plan. Compare the merge plan to the first merge plan. Where the new-OTHER lines agree, they should be turned to killed-THIS. Where killed-THIS lines agree, they should be turned into new-OTHER.
Future extension
Martin Pool again:
- This can still be improved for some criss-cross merge cases by recording when the user explicitly choses a resolution to a conflict, but I think this may give comparable results to current weave merge.
I would like to see a concept of line identity added to knits, so that the initial matching can be highly accurate. We can add convergence support on top of that. --AaronBentley
Example
Result of comparison, with annotations added
My dog has <<<<<<< OTHER b fleas d and a bad attitude e and sneakers ======= c interesting habits f a skateboard >>>>>>> THIS
Ancestors of THIS: c, f, b Ancestors of OTHER: c, f, b, d, e
Plan-merge result
common My dog has
<<<<<<< OTHER
killed-THIS fleas
new-OTHER and a bad attitude
new-OTHER and sneakers
=======
killed-OTHER interesting habits
killed-OTHER a skateboard
>>>>>>> THISAfter removing killed lines:
My dog has and a bad attitude and sneakers
