]> source.dussan.org Git - jgit.git/commitdiff
Change default diff algorithm to histogram and add tests 58/1958/2
authorChristian Halstrick <christian.halstrick@sap.com>
Thu, 25 Nov 2010 23:44:05 +0000 (00:44 +0100)
committerChristian Halstrick <christian.halstrick@sap.com>
Thu, 25 Nov 2010 23:44:05 +0000 (00:44 +0100)
The referenced bug showed that JGit produced different merge results
compared to C Git. Unit test was added to reproduce the issue. The
problem can be solved by switching to histogram diff algorithm.

Bug: 331078
Change-Id: I54f30afb3a9fef1dbca365ca5f98f4cc846092e3
Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
Signed-off-by: Philipp Thun <philipp.thun@sap.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeAlgorithmTest.java
org.eclipse.jgit/src/org/eclipse/jgit/merge/MergeAlgorithm.java

index b17c5278e1bd4d27cf467ea64ae4a0b935bc6719..06d4c58e3e8932a09aab3a3addbafe46e3edfae5 100644 (file)
@@ -165,6 +165,25 @@ public class MergeAlgorithmTest extends TestCase {
                assertEquals(t("aZcYe"), merge("abcde", "aZcde", "abcYe"));
        }
 
+       /**
+        * Test merging two contents which do one similar modification and one
+        * insertion is only done by one side. Between modification and insertion is
+        * a block which is common between the two contents and the common base
+        *
+        * @throws IOException
+        */
+       public void testTwoSimilarModsAndOneInsert() throws IOException {
+               assertEquals(t("IAAJ"), merge("iA", "IA", "IAAJ"));
+               assertEquals(t("aBcDde"), merge("abcde", "aBcde", "aBcDde"));
+               assertEquals(t("IAJ"), merge("iA", "IA", "IAJ"));
+               assertEquals(t("IAAAJ"), merge("iA", "IA", "IAAAJ"));
+               assertEquals(t("IAAAJCAB"), merge("iACAB", "IACAB", "IAAAJCAB"));
+               assertEquals(t("HIAAAJCAB"), merge("HiACAB", "HIACAB", "HIAAAJCAB"));
+               assertEquals(t("AGADEFHIAAAJCAB"),
+                               merge("AGADEFHiACAB", "AGADEFHIACAB", "AGADEFHIAAAJCAB"));
+
+       }
+
        private String merge(String commonBase, String ours, String theirs) throws IOException {
                MergeResult r = new MergeAlgorithm().merge(RawTextComparator.DEFAULT,
                                T(commonBase), T(ours), T(theirs));
index 62febd62c2df224bd7d563a599d670672bab4786..e6688f5bc97a168b07d360a1b74600e899200e3a 100644 (file)
@@ -50,24 +50,24 @@ import java.util.List;
 import org.eclipse.jgit.diff.DiffAlgorithm;
 import org.eclipse.jgit.diff.Edit;
 import org.eclipse.jgit.diff.EditList;
-import org.eclipse.jgit.diff.MyersDiff;
+import org.eclipse.jgit.diff.HistogramDiff;
 import org.eclipse.jgit.diff.Sequence;
 import org.eclipse.jgit.diff.SequenceComparator;
 import org.eclipse.jgit.merge.MergeChunk.ConflictState;
 
 /**
  * Provides the merge algorithm which does a three-way merge on content provided
- * as RawText. By default {@link MyersDiff} is used as diff algorithm.
+ * as RawText. By default {@link HistogramDiff} is used as diff algorithm.
  */
 public final class MergeAlgorithm {
        private final DiffAlgorithm diffAlg;
 
        /**
-        * Creates a new MergeAlgorithm which uses {@link MyersDiff} as diff
+        * Creates a new MergeAlgorithm which uses {@link HistogramDiff} as diff
         * algorithm
         */
        public MergeAlgorithm() {
-               this(MyersDiff.INSTANCE);
+               this(new HistogramDiff());
        }
 
        /**