← Back to team overview

dulwich-users team mailing list archive

[PATCH 16/34] diff_tree: Add rename_detector to tree_changes_for_merge.

 

From: Dave Borowitz <dborowitz@xxxxxxxxxx>

Change-Id: I8f7cd2eaa055459c536f9cd8a80a62d71f047e2a
---
 dulwich/diff_tree.py            |    7 +++++--
 dulwich/tests/test_diff_tree.py |   26 ++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/dulwich/diff_tree.py b/dulwich/diff_tree.py
index e90afa2..9a53ff8 100644
--- a/dulwich/diff_tree.py
+++ b/dulwich/diff_tree.py
@@ -242,12 +242,14 @@ def _matches_any_parent(store, parent_tree_ids, changes):
     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.
 
     :param store: An ObjectStore for looking up objects.
     :param parent_tree_ids: An iterable of the SHAs of the parent trees.
     :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.
 
@@ -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
         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]
     num_parents = len(parent_tree_ids)
     changes_by_path = defaultdict(lambda: [None] * num_parents)
diff --git a/dulwich/tests/test_diff_tree.py b/dulwich/tests/test_diff_tree.py
index 9c3ac70..02c86c4 100644
--- a/dulwich/tests/test_diff_tree.py
+++ b/dulwich/tests/test_diff_tree.py
@@ -88,6 +88,10 @@ class DiffTestCase(TestCase):
 
 class TreeChangesTest(DiffTestCase):
 
+    def setUp(self):
+        super(TreeChangesTest, self).setUp()
+        self.detector = RenameDetector(self.store)
+
     def assertMergeFails(self, merge_entries, name, mode, sha):
         t = Tree()
         t[name] = (mode, sha)
@@ -422,6 +426,28 @@ class TreeChangesTest(DiffTestCase):
             None]],
           [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):
 
-- 
1.7.3.1



References