Преглед на файлове

Support rename_detector and include_trees at the same time in tree_changes.

Jelmer Vernooij преди 5 години
родител
ревизия
e0d41ce7b4
променени са 3 файла, в които са добавени 15 реда и са изтрити 8 реда
  1. 4 0
      NEWS
  2. 7 6
      dulwich/diff_tree.py
  3. 4 2
      dulwich/object_store.py

+ 4 - 0
NEWS

@@ -7,6 +7,10 @@
    ``dulwich.porcelain.get_object_by_path`` on Python 3.
    (Jelmer Vernooij)
 
+ * Support the include_trees and rename_detector arguments
+   at the same time when diffing trees.
+   (Jelmer Vernooij)
+
 0.19.14	2019-11-30
 
  * Strip superfluous <> around email. (monnerat)

+ 7 - 6
dulwich/diff_tree.py

@@ -182,13 +182,11 @@ def tree_changes(store, tree1_id, tree2_id, want_unchanged=False,
       Iterator over TreeChange instances for each change between the
         source and target tree.
     """
-    if include_trees and rename_detector is not None:
-        raise NotImplementedError(
-            'rename_detector and include_trees are mutually exclusive')
     if (rename_detector is not None and tree1_id is not None and
             tree2_id is not None):
         for change in rename_detector.changes_with_renames(
-                tree1_id, tree2_id, want_unchanged=want_unchanged):
+                tree1_id, tree2_id, want_unchanged=want_unchanged,
+                include_trees=include_trees):
             yield change
         return
 
@@ -457,7 +455,8 @@ class RenameDetector(object):
     def _collect_changes(self, tree1_id, tree2_id):
         want_unchanged = self._find_copies_harder or self._want_unchanged
         for change in tree_changes(self._store, tree1_id, tree2_id,
-                                   want_unchanged=want_unchanged):
+                                   want_unchanged=want_unchanged,
+                                   include_trees=self._include_trees):
             self._add_change(change)
 
     def _prune(self, add_paths, delete_paths):
@@ -599,10 +598,12 @@ class RenameDetector(object):
         self._deletes = [
             d for d in self._deletes if d.type != CHANGE_UNCHANGED]
 
-    def changes_with_renames(self, tree1_id, tree2_id, want_unchanged=False):
+    def changes_with_renames(self, tree1_id, tree2_id, want_unchanged=False,
+                             include_trees=False):
         """Iterate TreeChanges between two tree SHAs, with rename detection."""
         self._reset()
         self._want_unchanged = want_unchanged
+        self._include_trees = include_trees
         self._collect_changes(tree1_id, tree2_id)
         self._find_exact_renames()
         self._find_content_rename_candidates()

+ 4 - 2
dulwich/object_store.py

@@ -160,7 +160,8 @@ class BaseObjectStore(object):
             return commit()
 
     def tree_changes(self, source, target, want_unchanged=False,
-                     include_trees=False, change_type_same=False):
+                     include_trees=False, change_type_same=False,
+                     rename_detector=None):
         """Find the differences between the contents of two trees
 
         Args:
@@ -176,7 +177,8 @@ class BaseObjectStore(object):
         for change in tree_changes(self, source, target,
                                    want_unchanged=want_unchanged,
                                    include_trees=include_trees,
-                                   change_type_same=change_type_same):
+                                   change_type_same=change_type_same,
+                                   rename_detector=rename_detector):
             yield ((change.old.path, change.new.path),
                    (change.old.mode, change.new.mode),
                    (change.old.sha, change.new.sha))