dulwich-users team mailing list archive
-
dulwich-users team
-
Mailing list archive
-
Message #00297
[PATCH 19/28] diff: Factor out _is_tree function for TreeEntry objects.
From: Dave Borowitz <dborowitz@xxxxxxxxxx>
Change-Id: I2cbf009a8d63d3a1b0c23adb6855c5757c133f03
---
dulwich/diff.py | 11 +++++++++--
dulwich/tests/test_diff.py | 10 ++++++++++
2 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/dulwich/diff.py b/dulwich/diff.py
index 6b26528..0f285a6 100644
--- a/dulwich/diff.py
+++ b/dulwich/diff.py
@@ -104,6 +104,13 @@ def _merge_entries(path, tree1, tree2):
return result
+def _is_tree(entry):
+ mode = entry.mode
+ if mode is None:
+ return False
+ return stat.S_ISDIR(mode)
+
+
def walk_trees(store, tree1_id, tree2_id, prune_identical=False):
"""Recursively walk all the entries of two trees.
@@ -124,8 +131,8 @@ def walk_trees(store, tree1_id, tree2_id, prune_identical=False):
todo = [(TreeEntry('', mode1, tree1_id), TreeEntry('', mode2, tree2_id))]
while todo:
entry1, entry2 = todo.pop()
- is_tree1 = entry1.mode and stat.S_ISDIR(entry1.mode)
- is_tree2 = entry2.mode and stat.S_ISDIR(entry2.mode)
+ is_tree1 = _is_tree(entry1)
+ is_tree2 = _is_tree(entry2)
if prune_identical and is_tree1 and is_tree2 and entry1 == entry2:
continue
diff --git a/dulwich/tests/test_diff.py b/dulwich/tests/test_diff.py
index 8d8f65d..9adc807 100644
--- a/dulwich/tests/test_diff.py
+++ b/dulwich/tests/test_diff.py
@@ -30,6 +30,7 @@ from dulwich.diff import (
_similarity_score,
_tree_change_key,
RenameDetector,
+ _is_tree,
)
from dulwich.index import (
commit_tree,
@@ -119,6 +120,15 @@ class TreeChangesTest(DiffTestCase):
(('c', 0100755, blob_c2.id), (None, None, None)),
], _merge_entries('', tree2, tree1))
+ def test_is_tree(self):
+ self.assertFalse(_is_tree(TreeEntry(None, None, None)))
+ self.assertFalse(_is_tree(TreeEntry('a', 0100644, 'a' * 40)))
+ self.assertFalse(_is_tree(TreeEntry('a', 0100755, 'a' * 40)))
+ self.assertFalse(_is_tree(TreeEntry('a', 0120000, 'a' * 40)))
+ self.assertTrue(_is_tree(TreeEntry('a', 0040000, 'a' * 40)))
+ self.assertRaises(TypeError, _is_tree, TreeEntry('a', 'x', 'a' * 40))
+ self.assertRaises(AttributeError, _is_tree, 1234)
+
def assertChangesEqual(self, expected, tree1, tree2, **kwargs):
actual = list(tree_changes(self.store, tree1.id, tree2.id, **kwargs))
self.assertEqual(expected, actual)
--
1.7.3.2.168.gd6b63
References