diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RenameDetectorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RenameDetectorTest.java index eb965cf60..37c9d2fb7 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RenameDetectorTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RenameDetectorTest.java @@ -275,6 +275,21 @@ public class RenameDetectorTest extends RepositoryTestCase { assertRename(b, a, 74, entries.get(0)); } + public void testInexactRename_SameContentMultipleTimes() throws Exception { + ObjectId aId = blob("a\na\na\na\n"); + ObjectId bId = blob("a\na\na\n"); + + DiffEntry a = DiffEntry.add(PATH_A, aId); + DiffEntry b = DiffEntry.delete(PATH_Q, bId); + + rd.add(a); + rd.add(b); + + List entries = rd.compute(); + assertEquals(1, entries.size()); + assertRename(b, a, 74, entries.get(0)); + } + public void testInexactRenames_OnePair2() throws Exception { ObjectId aId = blob("ab\nab\nab\nac\nad\nae\n"); ObjectId bId = blob("ac\nab\nab\nab\naa\na0\na1\n"); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java index 22b74f461..39bcebb4c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java @@ -216,7 +216,8 @@ class SimilarityIndex { for (;;) { if (srcKey == dstKey) { - common += countOf(dstHash[dstIdx]); + common += Math.min(countOf(srcHash[srcIdx]), + countOf(dstHash[dstIdx])); if (++srcIdx == srcHash.length) break;