]> source.dussan.org Git - jgit.git/commitdiff
Fix NPE in RenameDetector 51/1151/1
authorShawn O. Pearce <spearce@spearce.org>
Tue, 20 Jul 2010 14:52:35 +0000 (07:52 -0700)
committerShawn O. Pearce <spearce@spearce.org>
Tue, 20 Jul 2010 14:52:35 +0000 (07:52 -0700)
If we have two adds of the same object but no deletes the detector
threw an NPE because the entry that came back from the deleted map
was null (no matching objects).  In this case we need to put the
adds all back onto the list of left over additions since they did
not match a delete.

Change-Id: Ie68fbe7426b4dc0cb571a08911c7adbffff755d5
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
CC: Jeffrey Schumacher" <jeffschu@google.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/RenameDetectorTest.java
org.eclipse.jgit/src/org/eclipse/jgit/diff/RenameDetector.java

index c32c78668fa1531fb179103d7941782fb64f5a85..bfc51b68f9382871744f3556456c6afdfba227cc 100644 (file)
@@ -83,6 +83,25 @@ public class RenameDetectorTest extends RepositoryTestCase {
                assertRename(b, a, 100, entries.get(0));
        }
 
+       public void testExactRename_DifferentObjects() throws Exception {
+               ObjectId foo = blob("foo");
+               ObjectId bar = blob("bar");
+
+               DiffEntry a = DiffEntry.add(PATH_A, foo);
+               DiffEntry h = DiffEntry.add(PATH_H, foo);
+               DiffEntry q = DiffEntry.delete(PATH_Q, bar);
+
+               rd.add(a);
+               rd.add(h);
+               rd.add(q);
+
+               List<DiffEntry> entries = rd.compute();
+               assertEquals(3, entries.size());
+               assertSame(a, entries.get(0));
+               assertSame(h, entries.get(1));
+               assertSame(q, entries.get(2));
+       }
+
        public void testExactRename_OneRenameOneModify() throws Exception {
                ObjectId foo = blob("foo");
                ObjectId bar = blob("bar");
index bc23940535fed508b0ec3a36506d7632815ab375..cf5615a1cb4e83700f869b5563818a1c0656d9c3 100644 (file)
@@ -383,7 +383,7 @@ public class RenameDetector {
                                } else {
                                        left.addAll(adds);
                                }
-                       } else {
+                       } else if (o != null) {
                                // We have many adds to many deletes: score all the adds against
                                // all the deletes by path name, take the best matches, pair
                                // them as renames, then call the rest copies
@@ -432,6 +432,8 @@ public class RenameDetector {
                                        adds.set(addIdx, null); // Claim the destination was matched.
                                        pm.update(1);
                                }
+                       } else {
+                               left.addAll(adds);
                        }
                }
                added = left;