浏览代码

Fix logic for extra adds of identical files.

Additionally, add a test.
Robert Brown 10 年之前
父节点
当前提交
a34503994d
共有 2 个文件被更改,包括 13 次插入1 次删除
  1. 1 1
      dulwich/diff_tree.py
  2. 12 0
      dulwich/tests/test_diff_tree.py

+ 1 - 1
dulwich/diff_tree.py

@@ -461,7 +461,7 @@ class RenameDetector(object):
             num_extra_adds = len(sha_adds) - len(sha_deletes)
             # TODO(dborowitz): Less arbitrary way of dealing with extra copies.
             old = sha_deletes[0][0]
-            if num_extra_adds:
+            if num_extra_adds > 0:
                 for new in sha_adds[-num_extra_adds:]:
                     add_paths.add(new.path)
                     self._changes.append(TreeChange(CHANGE_COPY, old, new))

+ 12 - 0
dulwich/tests/test_diff_tree.py

@@ -752,6 +752,18 @@ class RenameDetectionTest(DiffTestCase):
            TreeChange.delete(('b', F, blob2.id))],
           self.detect_renames(tree1, tree2))
 
+    def test_content_rename_with_more_deletions(self):
+        blob1 = make_object(Blob, data='')
+        tree1 = self.commit_tree([('a', blob1), ('b', blob1), ('c', blob1), ('d', blob1)])
+        tree2 = self.commit_tree([('e', blob1), ('f', blob1), ('g', blob1)])
+        self.maxDiff = None
+        self.assertEqual(
+          [TreeChange(CHANGE_RENAME, ('a', F, blob1.id), ('e', F, blob1.id)),
+           TreeChange(CHANGE_RENAME, ('b', F, blob1.id), ('f', F, blob1.id)),
+           TreeChange(CHANGE_RENAME, ('c', F, blob1.id), ('g', F, blob1.id)),
+           TreeChange.delete(('d', F, blob1.id))],
+          self.detect_renames(tree1, tree2))
+
     def test_content_rename_gitlink(self):
         blob1 = make_object(Blob, data='blob1')
         blob2 = make_object(Blob, data='blob2')