瀏覽代碼

diff_tree: Add rename_detector to tree_changes_for_merge.

Change-Id: I8f7cd2eaa055459c536f9cd8a80a62d71f047e2a
Dave Borowitz 13 年之前
父節點
當前提交
b005326623
共有 2 個文件被更改,包括 31 次插入2 次删除
  1. 5 2
      dulwich/diff_tree.py
  2. 26 0
      dulwich/tests/test_diff_tree.py

+ 5 - 2
dulwich/diff_tree.py

@@ -242,12 +242,14 @@ def _matches_any_parent(store, parent_tree_ids, changes):
     return False
     return False
 
 
 
 
-def tree_changes_for_merge(store, parent_tree_ids, tree_id):
+def tree_changes_for_merge(store, parent_tree_ids, tree_id,
+                           rename_detector=None):
     """Get the tree changes for a merge tree relative to all its parents.
     """Get the tree changes for a merge tree relative to all its parents.
 
 
     :param store: An ObjectStore for looking up objects.
     :param store: An ObjectStore for looking up objects.
     :param parent_tree_ids: An iterable of the SHAs of the parent trees.
     :param parent_tree_ids: An iterable of the SHAs of the parent trees.
     :param tree_id: The SHA of the merge tree.
     :param tree_id: The SHA of the merge tree.
+    :param rename_detector: RenameDetector object for detecting renames.
 
 
     :yield: Lists of TreeChange objects, one per conflicted path in the merge.
     :yield: Lists of TreeChange objects, one per conflicted path in the merge.
 
 
@@ -259,7 +261,8 @@ def tree_changes_for_merge(store, parent_tree_ids, tree_id):
         in the merge tree is not found in any of the parents, or in the case of
         in the merge tree is not found in any of the parents, or in the case of
         deletes, if not all of the old SHAs match.
         deletes, if not all of the old SHAs match.
     """
     """
-    all_parent_changes = [tree_changes(store, t, tree_id)
+    all_parent_changes = [tree_changes(store, t, tree_id,
+                                       rename_detector=rename_detector)
                           for t in parent_tree_ids]
                           for t in parent_tree_ids]
     num_parents = len(parent_tree_ids)
     num_parents = len(parent_tree_ids)
     changes_by_path = defaultdict(lambda: [None] * num_parents)
     changes_by_path = defaultdict(lambda: [None] * num_parents)

+ 26 - 0
dulwich/tests/test_diff_tree.py

@@ -88,6 +88,10 @@ class DiffTestCase(TestCase):
 
 
 class TreeChangesTest(DiffTestCase):
 class TreeChangesTest(DiffTestCase):
 
 
+    def setUp(self):
+        super(TreeChangesTest, self).setUp()
+        self.detector = RenameDetector(self.store)
+
     def assertMergeFails(self, merge_entries, name, mode, sha):
     def assertMergeFails(self, merge_entries, name, mode, sha):
         t = Tree()
         t = Tree()
         t[name] = (mode, sha)
         t[name] = (mode, sha)
@@ -422,6 +426,28 @@ class TreeChangesTest(DiffTestCase):
             None]],
             None]],
           [parent1, parent2, parent3], merge)
           [parent1, parent2, parent3], merge)
 
 
+    def test_tree_changes_for_merge_octopus_add_rename_conflict(self):
+        blob1 = make_object(Blob, data='a\nb\nc\nd\n')
+        blob2 = make_object(Blob, data='a\nb\nc\ne\n')
+        parent1 = self.commit_tree([('a', blob1)])
+        parent2 = self.commit_tree([])
+        merge = self.commit_tree([('b', blob2)])
+        self.assertChangesForMergeEqual(
+          [[TreeChange(CHANGE_RENAME, ('a', F, blob1.id), ('b', F, blob2.id)),
+            TreeChange.add(('b', F, blob2.id))]],
+          [parent1, parent2], merge, rename_detector=self.detector)
+
+    def test_tree_changes_for_merge_octopus_modify_rename_conflict(self):
+        blob1 = make_object(Blob, data='a\nb\nc\nd\n')
+        blob2 = make_object(Blob, data='a\nb\nc\ne\n')
+        parent1 = self.commit_tree([('a', blob1)])
+        parent2 = self.commit_tree([('b', blob1)])
+        merge = self.commit_tree([('b', blob2)])
+        self.assertChangesForMergeEqual(
+          [[TreeChange(CHANGE_RENAME, ('a', F, blob1.id), ('b', F, blob2.id)),
+            TreeChange(CHANGE_MODIFY, ('b', F, blob1.id), ('b', F, blob2.id))]],
+          [parent1, parent2], merge, rename_detector=self.detector)
+
 
 
 class RenameDetectionTest(DiffTestCase):
 class RenameDetectionTest(DiffTestCase):