Skip to content

Commit

Permalink
diff_tree: Factor out a protected _add_change method.
Browse files Browse the repository at this point in the history
This should have been included in a52514a but I neglected to include it.

Change-Id: I9a8976ca583844d41cd6b61ac3fdad765db560b0
  • Loading branch information
dborowitz authored and jelmer committed Aug 12, 2011
1 parent 60ed785 commit fd8f3ed
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions dulwich/diff_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit fd8f3ed

Please sign in to comment.