Преглед на файлове

pack: Add a PackIndexer to index packs more quickly.

Change-Id: I6e94e778beb221590dbf10c1a7aba302f700ef03
Dave Borowitz преди 13 години
родител
ревизия
9945067caf
променени са 2 файла, в които са добавени 19 реда и са изтрити 8 реда
  1. 2 2
      NEWS
  2. 17 6
      dulwich/pack.py

+ 2 - 2
NEWS

@@ -2,8 +2,8 @@
 
  FEATURES
 
-  * New DeltaChainIterator abstract class for quickly inflating/iterating all
-    objects in a pack. (Dave Borowitz)
+  * New DeltaChainIterator abstract class for quickly iterating all objects in
+    a pack, with an implementation for pack indexing. (Dave Borowitz)
 
  BUG FIXES
 

+ 17 - 6
dulwich/pack.py

@@ -900,12 +900,11 @@ class PackData(object):
             object count.
         :return: iterator of tuples with (sha, offset, crc32)
         """
-        for offset, type, obj, crc32 in self.iterobjects(progress=progress):
-            assert isinstance(offset, int)
-            assert isinstance(type, int)
-            assert isinstance(obj, list) or isinstance(obj, tuple)
-            type, obj = self.resolve_object(offset, type, obj)
-            yield obj_sha(type, obj), offset, crc32
+        num_objects = self._num_objects
+        for i, result in enumerate(PackIndexer.for_pack_data(self)):
+            if progress is not None:
+                progress(i, num_objects)
+            yield result
 
     def sorted_entries(self, progress=None):
         """Return entries in this pack, sorted by SHA.
@@ -1170,6 +1169,18 @@ class DeltaChainIterator(object):
             for result in self._follow_chain(new_offset, base_type_num, chunks):
                 yield result
 
+    def __iter__(self):
+        return self._walk_all_chains()
+
+
+class PackIndexer(DeltaChainIterator):
+    """Delta chain iterator that yields index entries."""
+
+    _compute_crc32 = True
+
+    def _result(self, offset, unused_type_num, unused_chunks, sha, crc32):
+        return sha, offset, crc32
+
 
 class SHA1Reader(object):
     """Wrapper around a file-like object that remembers the SHA1 of its data."""