summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorRobin Rosenberg <robin.rosenberg@dewire.com>2011-05-17 08:54:18 -0400
committerCode Review <codereview-daemon@eclipse.org>2011-05-17 08:54:18 -0400
commitd781554b79b50e5c3fe468373e87edf8957d7578 (patch)
tree319c8f4409ac53987b7aba8cdc3813aff1c9f6a9 /org.eclipse.jgit
parentb13ca9121b8f2c6a0ebca1a2a12c4af7e75dfd20 (diff)
parent0461ff4f0c7ef505c818dac95286fa852f16eef7 (diff)
downloadjgit-d781554b79b50e5c3fe468373e87edf8957d7578.tar.gz
jgit-d781554b79b50e5c3fe468373e87edf8957d7578.zip
Merge "Optimize MergeAlgorithm if ours or theirs is empty"
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/merge/MergeAlgorithm.java31
1 files changed, 31 insertions, 0 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 e6688f5bc9..112550a1de 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/merge/MergeAlgorithm.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/merge/MergeAlgorithm.java
@@ -103,6 +103,37 @@ public final class MergeAlgorithm {
sequences.add(ours);
sequences.add(theirs);
MergeResult<S> result = new MergeResult<S>(sequences);
+
+ if (ours.size() == 0) {
+ if (theirs.size() != 0) {
+ EditList theirsEdits = diffAlg.diff(cmp, base, theirs);
+ if (!theirsEdits.isEmpty()) {
+ // we deleted, they modified -> Let their complete content
+ // conflict with empty text
+ result.add(1, 0, 0, ConflictState.FIRST_CONFLICTING_RANGE);
+ result.add(2, 0, theirs.size(),
+ ConflictState.NEXT_CONFLICTING_RANGE);
+ } else
+ // we deleted, they didn't modify -> Let our deletion win
+ result.add(1, 0, 0, ConflictState.NO_CONFLICT);
+ } else
+ // we and they deleted -> return a single chunk of nothing
+ result.add(1, 0, 0, ConflictState.NO_CONFLICT);
+ return result;
+ } else if (theirs.size() == 0) {
+ EditList oursEdits = diffAlg.diff(cmp, base, ours);
+ if (!oursEdits.isEmpty()) {
+ // we modified, they deleted -> Let our complete content
+ // conflict with empty text
+ result.add(1, 0, ours.size(),
+ ConflictState.FIRST_CONFLICTING_RANGE);
+ result.add(2, 0, 0, ConflictState.NEXT_CONFLICTING_RANGE);
+ } else
+ // they deleted, we didn't modify -> Let their deletion win
+ result.add(2, 0, 0, ConflictState.NO_CONFLICT);
+ return result;
+ }
+
EditList oursEdits = diffAlg.diff(cmp, base, ours);
Iterator<Edit> baseToOurs = oursEdits.iterator();
EditList theirsEdits = diffAlg.diff(cmp, base, theirs);