VCS theory - merge: recursive revrision merge or 3 revision merge?

148 views Asked by At

I have a theoretical question about possible VCS merging. I know that many VCS use 3 revision merge, which is common ancestor, "mine" and "your" revision. I know how they works.

I've thought about another alternative, recursive revision merge, haven't found this in Google. "You found America!" you might think. I know Git use recursive merge. But the reason Git is using recursive merge is for criss-cross merge

I'm talking about a normal case, non criss-cross merge.

For example, we have a common ancestor, A, and to branches, 1 and 2.

branch 1: B,  C,  D,  E,  F,  G

branch 2: B', C', D', E', F', G'

As said before, A is the common ancestor so it's the parent of B and B'.

We want to merge G and G' into branch 1. The common way that Git and Mercurial use is the diff3:

diff3(ancestor = A, mine = G, yours = G')

This will compute merge by computing 3 version only, which is O(1).

The alternative algorithm I thought about is O(n):

  1. merge the closest revisions to ancestor first.

  2. merge the result with the next closest revision from branch 1

  3. merge the result with the next closest revision from branch 2 (if remain)

  4. repeat (in loop) to step 2 if there any revision in branch 1 remain.

In the above example it looks like:

  1. merge B and B'

  2. merge the result with C

  3. merge the result with C'

  4. merge the result with D

  5. and so on...

The question I couldn't resolve is - Is there any case that my way is safer and more accurate (in non criss-cross merge) than the traditional 3 revision merge?

Can my way avoid conflicts that the traditional way cause?

Can my way create new conflicts that the tradition way doesn't cause?

Does my way conflicts are not "real" conflicts? (which the tradition way doesn't cause)

1

There are 1 answers

4
Sergey Azarkevich On BEST ANSWER

We want to merge G and G' into branch 1.

Why we want merge G into branch1? G is already in branch1. In best case we give nothing from this merge, in worst - conflict. Same for all other revisions without '

So only B' - G' need to be merged to branch1. And this is the 3-way merge.

BTW. third component of 3-way merge not 'common ancestor', but 'base'. Common ancestor can be base but not always.