dulwich-users team mailing list archive
-
dulwich-users team
-
Mailing list archive
-
Message #00612
[PATCH 14/34] diff_tree: Add want_unchanged to changes_with_renames.
From: Dave Borowitz <dborowitz@xxxxxxxxxx>
Change-Id: I6f2abb3f232dc6abe69a26e4db7188d9edf23d6e
---
NEWS | 2 ++
dulwich/diff_tree.py | 9 +++++++--
dulwich/tests/test_diff_tree.py | 23 +++++++++++++++++++++--
3 files changed, 30 insertions(+), 4 deletions(-)
diff --git a/NEWS b/NEWS
index efc3624..3354272 100644
--- a/NEWS
+++ b/NEWS
@@ -76,6 +76,8 @@
* Optionally create RenameDetectors without passing in tree SHAs.
(Dave Borowitz)
+ * Optionally include unchanged entries in RenameDetectors. (Dave Borowitz)
+
TEST CHANGES
* If setuptools is installed, "python setup.py test" will now run the testsuite.
diff --git a/dulwich/diff_tree.py b/dulwich/diff_tree.py
index bdc5cc4..1ef4779 100644
--- a/dulwich/diff_tree.py
+++ b/dulwich/diff_tree.py
@@ -397,6 +397,7 @@ class RenameDetector(object):
self._rewrite_threshold = rewrite_threshold
self._max_files = max_files
self._find_copies_harder = find_copies_harder
+ self._want_unchanged = False
def _reset(self):
self._adds = []
@@ -412,8 +413,9 @@ class RenameDetector(object):
return _similarity_score(old_obj, new_obj) < self._rewrite_threshold
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=self._find_copies_harder):
+ want_unchanged=want_unchanged):
if change.type == CHANGE_ADD:
self._adds.append(change)
elif change.type == CHANGE_DELETE:
@@ -554,11 +556,14 @@ class RenameDetector(object):
return result
def _prune_unchanged(self):
+ if self._want_unchanged:
+ return
self._deletes = [d for d in self._deletes if d.type != CHANGE_UNCHANGED]
- def changes_with_renames(self, tree1_id, tree2_id):
+ def changes_with_renames(self, tree1_id, tree2_id, want_unchanged=False):
"""Iterate TreeChanges between two tree SHAs, with rename detection."""
self._reset()
+ self._want_unchanged = want_unchanged
self._collect_changes(tree1_id, tree2_id)
self._find_exact_renames()
self._find_content_renames()
diff --git a/dulwich/tests/test_diff_tree.py b/dulwich/tests/test_diff_tree.py
index 52f53ae..5de7a55 100644
--- a/dulwich/tests/test_diff_tree.py
+++ b/dulwich/tests/test_diff_tree.py
@@ -490,9 +490,10 @@ class RenameDetectionTest(DiffTestCase):
self.assertEqual(expected_entries,
sorted(perm, key=_tree_change_key))
- def detect_renames(self, tree1, tree2, **kwargs):
+ def detect_renames(self, tree1, tree2, want_unchanged=False, **kwargs):
detector = RenameDetector(self.store, **kwargs)
- return detector.changes_with_renames(tree1.id, tree2.id)
+ return detector.changes_with_renames(tree1.id, tree2.id,
+ want_unchanged=want_unchanged)
def test_no_renames(self):
blob1 = make_object(Blob, data='a\nb\nc\nd\n')
@@ -784,3 +785,21 @@ class RenameDetectionTest(DiffTestCase):
detector.changes_with_renames(tree1.id, tree2.id))
self.assertEqual(changes,
detector.changes_with_renames(tree1.id, tree2.id))
+
+ def test_want_unchanged(self):
+ blob_a1 = make_object(Blob, data='a\nb\nc\nd\n')
+ blob_b = make_object(Blob, data='b')
+ blob_c2 = make_object(Blob, data='a\nb\nc\ne\n')
+ tree1 = self.commit_tree([('a', blob_a1), ('b', blob_b)])
+ tree2 = self.commit_tree([('c', blob_c2), ('b', blob_b)])
+ detector = RenameDetector(self.store)
+ self.assertEqual(
+ [TreeChange(CHANGE_RENAME, ('a', F, blob_a1.id),
+ ('c', F, blob_c2.id))],
+ self.detect_renames(tree1, tree2))
+ self.assertEqual(
+ [TreeChange(CHANGE_RENAME, ('a', F, blob_a1.id),
+ ('c', F, blob_c2.id)),
+ TreeChange(CHANGE_UNCHANGED, ('b', F, blob_b.id),
+ ('b', F, blob_b.id))],
+ self.detect_renames(tree1, tree2, want_unchanged=True))
--
1.7.3.1
References