diff options
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/merge/MergeAlgorithm.java')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/merge/MergeAlgorithm.java | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/merge/MergeAlgorithm.java b/org.eclipse.jgit/src/org/eclipse/jgit/merge/MergeAlgorithm.java index 80607351ae..d0d4d367b9 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/merge/MergeAlgorithm.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/merge/MergeAlgorithm.java @@ -90,10 +90,16 @@ public final class MergeAlgorithm { /** * Does the three way merge between a common base and two sequences. * - * @param cmp comparison method for this execution. - * @param base the common base sequence - * @param ours the first sequence to be merged - * @param theirs the second sequence to be merged + * @param <S> + * type of the sequences + * @param cmp + * comparison method for this execution. + * @param base + * the common base sequence + * @param ours + * the first sequence to be merged + * @param theirs + * the second sequence to be merged * @return the resulting content */ public <S extends Sequence> MergeResult<S> merge( @@ -114,6 +120,7 @@ public final class MergeAlgorithm { result.add(1, 0, 0, ConflictState.NO_CONFLICT); break; case THEIRS: + case UNION: result.add(2, 0, theirs.size(), ConflictState.NO_CONFLICT); break; @@ -121,6 +128,8 @@ public final class MergeAlgorithm { // Let their complete content conflict with empty text result.add(1, 0, 0, ConflictState.FIRST_CONFLICTING_RANGE); + result.add(0, 0, base.size(), + ConflictState.BASE_CONFLICTING_RANGE); result.add(2, 0, theirs.size(), ConflictState.NEXT_CONFLICTING_RANGE); break; @@ -140,6 +149,7 @@ public final class MergeAlgorithm { // we modified, they deleted switch (strategy) { case OURS: + case UNION: result.add(1, 0, ours.size(), ConflictState.NO_CONFLICT); break; case THEIRS: @@ -149,6 +159,8 @@ public final class MergeAlgorithm { // Let our complete content conflict with empty text result.add(1, 0, ours.size(), ConflictState.FIRST_CONFLICTING_RANGE); + result.add(0, 0, base.size(), + ConflictState.BASE_CONFLICTING_RANGE); result.add(2, 0, 0, ConflictState.NEXT_CONFLICTING_RANGE); break; } @@ -208,13 +220,18 @@ public final class MergeAlgorithm { // set some initial values for the ranges in A and B which we // want to handle + int oursBeginA = oursEdit.getBeginA(); + int theirsBeginA = theirsEdit.getBeginA(); int oursBeginB = oursEdit.getBeginB(); int theirsBeginB = theirsEdit.getBeginB(); // harmonize the start of the ranges in A and B if (oursEdit.getBeginA() < theirsEdit.getBeginA()) { + theirsBeginA -= theirsEdit.getBeginA() + - oursEdit.getBeginA(); theirsBeginB -= theirsEdit.getBeginA() - oursEdit.getBeginA(); } else { + oursBeginA -= oursEdit.getBeginA() - theirsEdit.getBeginA(); oursBeginB -= oursEdit.getBeginA() - theirsEdit.getBeginA(); } @@ -260,11 +277,15 @@ public final class MergeAlgorithm { } // harmonize the end of the ranges in A and B + int oursEndA = oursEdit.getEndA(); + int theirsEndA = theirsEdit.getEndA(); int oursEndB = oursEdit.getEndB(); int theirsEndB = theirsEdit.getEndB(); if (oursEdit.getEndA() < theirsEdit.getEndA()) { + oursEndA += theirsEdit.getEndA() - oursEdit.getEndA(); oursEndB += theirsEdit.getEndA() - oursEdit.getEndA(); } else { + theirsEndA += oursEdit.getEndA() - theirsEdit.getEndA(); theirsEndB += oursEdit.getEndA() - theirsEdit.getEndA(); } @@ -314,10 +335,27 @@ public final class MergeAlgorithm { theirsEndB - commonSuffix, ConflictState.NO_CONFLICT); break; + case UNION: + result.add(1, oursBeginB + commonPrefix, + oursEndB - commonSuffix, + ConflictState.NO_CONFLICT); + + result.add(2, theirsBeginB + commonPrefix, + theirsEndB - commonSuffix, + ConflictState.NO_CONFLICT); + break; default: result.add(1, oursBeginB + commonPrefix, oursEndB - commonSuffix, ConflictState.FIRST_CONFLICTING_RANGE); + + int baseBegin = Math.min(oursBeginA, theirsBeginA) + + commonPrefix; + int baseEnd = Math.min(base.size(), + Math.max(oursEndA, theirsEndA)) - commonSuffix; + result.add(0, baseBegin, baseEnd, + ConflictState.BASE_CONFLICTING_RANGE); + result.add(2, theirsBeginB + commonPrefix, theirsEndB - commonSuffix, ConflictState.NEXT_CONFLICTING_RANGE); |