From fd8f3edee394fe20425f4fd5175a66d59d904aae Mon Sep 17 00:00:00 2001 From: Dave Borowitz Date: Fri, 12 Aug 2011 10:20:47 +0200 Subject: [PATCH] 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 --- dulwich/diff_tree.py | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/dulwich/diff_tree.py b/dulwich/diff_tree.py index a10334f7c..48ae0b3a7 100644 --- a/dulwich/diff_tree.py +++ b/dulwich/diff_tree.py @@ -405,26 +405,29 @@ def _should_split(self, change): 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]