浏览代码

diff_tree: Factor out a protected _add_change method.

This should have been included in a52514ae but I neglected to include it.

Change-Id: I9a8976ca583844d41cd6b61ac3fdad765db560b0
Dave Borowitz 13 年之前
父节点
当前提交
fd8f3edee3
共有 1 个文件被更改,包括 19 次插入16 次删除
  1. 19 16
      dulwich/diff_tree.py

+ 19 - 16
dulwich/diff_tree.py

@@ -405,26 +405,29 @@ class RenameDetector(object):
         new_obj = self._store[change.new.sha]
         return _similarity_score(old_obj, new_obj) < self._rewrite_threshold
 
+    def _add_change(self, change):
+        if change.type == CHANGE_ADD:
+            self._adds.append(change)
+        elif change.type == CHANGE_DELETE:
+            self._deletes.append(change)
+        elif self._should_split(change):
+            self._deletes.append(TreeChange.delete(change.old))
+            self._adds.append(TreeChange.add(change.new))
+        elif ((self._find_copies_harder and change.type == CHANGE_UNCHANGED)
+              or change.type == CHANGE_MODIFY):
+            # Treat all modifies as potential deletes for rename detection,
+            # but don't split them (to avoid spurious renames). Setting
+            # find_copies_harder means we treat unchanged the same as
+            # modified.
+            self._deletes.append(change)
+        else:
+            self._changes.append(change)
+
     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):
-            if change.type == CHANGE_ADD:
-                self._adds.append(change)
-            elif change.type == CHANGE_DELETE:
-                self._deletes.append(change)
-            elif self._should_split(change):
-                self._deletes.append(TreeChange.delete(change.old))
-                self._adds.append(TreeChange.add(change.new))
-            elif ((self._find_copies_harder and change.type == CHANGE_UNCHANGED)
-                  or change.type == CHANGE_MODIFY):
-                # Treat all modifies as potential deletes for rename detection,
-                # but don't split them (to avoid spurious renames). Setting
-                # find_copies_harder means we treat unchanged the same as
-                # modified.
-                self._deletes.append(change)
-            else:
-                self._changes.append(change)
+            self._add_change(change)
 
     def _prune(self, add_paths, delete_paths):
         self._adds = [a for a in self._adds if a.new.path not in add_paths]