aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Schumacher2010-08-03 19:59:30 (EDT)
committerShawn O. Pearce2010-08-04 13:56:19 (EDT)
commite64cb0306507ce8a33d5f638cb4aa0ec9c1327ff (patch)
treebe57a49fff37fcad8a6ceaf48e97f87e6e584b80
parent395d2360582e2c11c9d4418f925860b5484d7a98 (diff)
downloadjgit-e64cb0306507ce8a33d5f638cb4aa0ec9c1327ff.zip
jgit-e64cb0306507ce8a33d5f638cb4aa0ec9c1327ff.tar.gz
jgit-e64cb0306507ce8a33d5f638cb4aa0ec9c1327ff.tar.bz2
Fixed bug in scoring mechanism for rename detectionrefs/changes/32/1232/2
A bug in rename detection would cause file scores to be wrong. The bug was due to the way rename detection would judge the similarity between files. If file A has three lines containing 'foo', and file B has 5 lines containing 'foo', the rename detection phase should record that A and B have three lines in common (the minimum of the number of times that line appears in both files). Instead, it would choose the the number of times the line appeared in the destination file, in this case file B. I fixed the bug by having the SimilarityIndex instead choose the minimum number, as it should. I also added a test case to verify that the bug had been fixed. Change-Id: Ic75272a2d6e512a361f88eec91e1b8a7c2298d6b
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RenameDetectorTest.java15
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityIndex.java3
2 files changed, 17 insertions, 1 deletions
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 bfc51b6..6024c76 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<DiffEntry> 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 d5a31d6..b460d49 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;