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 bfc51b68f..6024c7699 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 d5a31d604..b460d498c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java @@ -172,7 +172,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;