dulwich-users team mailing list archive
-
dulwich-users team
-
Mailing list archive
-
Message #00558
[PATCH 26/33] pack: Add PackInflater to quickly inflate pack objects.
From: Dave Borowitz <dborowitz@xxxxxxxxxx>
Change-Id: I7ce6065370ca31680cb6666b6f7d79fd789489d4
---
dulwich/pack.py | 15 +++++++++++----
dulwich/tests/test_pack.py | 9 +++++++++
2 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/dulwich/pack.py b/dulwich/pack.py
index 0a3ce6c..c3ba114 100644
--- a/dulwich/pack.py
+++ b/dulwich/pack.py
@@ -1260,6 +1260,16 @@ class PackIndexer(DeltaChainIterator):
return self._ext_refs
+class PackInflater(DeltaChainIterator):
+ """Delta chain iterator that yields ShaFile objects."""
+
+ def _result(self, unused_offset, type_num, chunks, unused_sha,
+ unused_crc32):
+ # TODO: If from_raw_chunks supported it, we could pass in the SHA to
+ # avoid another pass over the file.
+ return ShaFile.from_raw_chunks(type_num, chunks)
+
+
class SHA1Reader(object):
"""Wrapper around a file-like object that remembers the SHA1 of its data."""
@@ -1768,10 +1778,7 @@ class Pack(object):
def iterobjects(self):
"""Iterate over the objects in this pack."""
- for offset, type, obj, crc32 in self.data.iterobjects():
- assert isinstance(offset, int)
- yield ShaFile.from_raw_chunks(
- *self.data.resolve_object(offset, type, obj))
+ return iter(PackInflater.for_pack_data(self.data))
def pack_tuples(self):
"""Provide an iterable for use with write_pack_objects.
diff --git a/dulwich/tests/test_pack.py b/dulwich/tests/test_pack.py
index 6b735ce..cb33168 100644
--- a/dulwich/tests/test_pack.py
+++ b/dulwich/tests/test_pack.py
@@ -424,6 +424,15 @@ class TestPack(PackTests):
self.assertRaises(ChecksumMismatch, lambda:
bad_pack.check_length_and_checksum())
+ def test_iterobjects(self):
+ p = self.get_pack(pack1_sha)
+ objs = dict((o.id, o) for o in p.iterobjects())
+ self.assertEquals(3, len(objs))
+ self.assertEquals(sorted(objs), sorted(p.index))
+ self.assertTrue(isinstance(objs[a_sha], Blob))
+ self.assertTrue(isinstance(objs[tree_sha], Tree))
+ self.assertTrue(isinstance(objs[commit_sha], Commit))
+
class WritePackTests(TestCase):
--
1.7.3.1
References