commit e9f9d24c4d03f5f9a4c59601be2c992a2ef01be8 from: Jelmer Vernooij date: Sun Jan 15 16:54:47 2023 UTC Minor compatibility fix: support None as argument for iter_tree_contents. commit - 786867b56210cec6de187f096f362fccb529104a commit + e9f9d24c4d03f5f9a4c59601be2c992a2ef01be8 blob - f7234f58ebfe16f68c31999ba5dc0db53519c4d4 blob + 01459a62e2002b01c25d7a8df72a66cab3173398 --- dulwich/object_store.py +++ dulwich/object_store.py @@ -1648,7 +1648,7 @@ def _collect_ancestors( def iter_tree_contents( - store: ObjectContainer, tree_id: bytes, *, include_trees: bool = False): + store: ObjectContainer, tree_id: Optional[ObjectID], *, include_trees: bool = False): """Iterate the contents of a tree and all subtrees. Iteration is depth-first pre-order, as in e.g. os.walk. @@ -1659,6 +1659,8 @@ def iter_tree_contents( Returns: Iterator over TreeEntry namedtuples for all the objects in a tree. """ + if tree_id is None: + return # This could be fairly easily generalized to >2 trees if we find a use # case. todo = [TreeEntry(b"", stat.S_IFDIR, tree_id)] blob - 2bd6fe7dfdcb661ef9303afa55b16a5eaf8ae99c blob + c03a11956bdd8f3a1c4abc67ae7c3fecdc52bd81 --- dulwich/tests/test_object_store.py +++ dulwich/tests/test_object_store.py @@ -223,6 +223,7 @@ class ObjectStoreTests: [TreeEntry(p, m, h) for (p, h, m) in blobs], list(iter_tree_contents(self.store, tree_id)), ) + self.assertEqual([], list(iter_tree_contents(self.store, None))) def test_iter_tree_contents_include_trees(self): blob_a = make_object(Blob, data=b"a")