summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorChristian Halstrick <christian.halstrick@sap.com>2011-05-17 10:59:17 +0200
committerChristian Halstrick <christian.halstrick@sap.com>2011-05-17 10:59:17 +0200
commit0461ff4f0c7ef505c818dac95286fa852f16eef7 (patch)
tree05630af9e3e5f4d88bf82aa30e8bb62f6a0d765f /org.eclipse.jgit.test
parent4e7c2f807dea99dfa968d42f221921fc79e41526 (diff)
downloadjgit-0461ff4f0c7ef505c818dac95286fa852f16eef7.tar.gz
jgit-0461ff4f0c7ef505c818dac95286fa852f16eef7.zip
Optimize MergeAlgorithm if ours or theirs is empty
Previously when merging two contents with a non-empty base and one of the contents was empty (size == 0) and the other was modified there was a potentially expensive calculation until we finally always come to the same result -> the complete non-deleted content should collide with the empty content. This proposal adds an optimization to detect empty input content and to produce the appropriate result immediatly. Change-Id: Ie6a837260c19d808f0e99173f570ff96dd22acd3 Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeAlgorithmTest.java20
1 files changed, 19 insertions, 1 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeAlgorithmTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeAlgorithmTest.java
index aa8f8281e4..8a33425b1d 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeAlgorithmTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeAlgorithmTest.java
@@ -198,6 +198,25 @@ public class MergeAlgorithmTest {
}
+ /**
+ * Test situations where (at least) one input value is the empty text
+ *
+ * @throws IOException
+ */
+ @Test
+ public void testEmptyTexts() throws IOException {
+ // test modification against deletion
+ assertEquals(t("<AB=>"), merge("A", "AB", ""));
+ assertEquals(t("<=AB>"), merge("A", "", "AB"));
+
+ // test unmodified against deletion
+ assertEquals(t(""), merge("AB", "AB", ""));
+ assertEquals(t(""), merge("AB", "", "AB"));
+
+ // test deletion against deletion
+ assertEquals(t(""), merge("AB", "", ""));
+ }
+
private String merge(String commonBase, String ours, String theirs) throws IOException {
MergeResult r = new MergeAlgorithm().merge(RawTextComparator.DEFAULT,
T(commonBase), T(ours), T(theirs));
@@ -231,5 +250,4 @@ public class MergeAlgorithmTest {
public static RawText T(String text) {
return new RawText(Constants.encode(t(text)));
}
-
}