فهرست منبع

Drop PackData.iterobjects.

Jelmer Vernooij 2 سال پیش
والد
کامیت
1bfc88ea55
4فایلهای تغییر یافته به همراه19 افزوده شده و 47 حذف شده
  1. 2 1
      dulwich/object_store.py
  2. 3 30
      dulwich/pack.py
  3. 5 5
      dulwich/repo.py
  4. 9 11
      dulwich/tests/test_pack.py

+ 2 - 1
dulwich/object_store.py

@@ -395,7 +395,8 @@ class PackBasedObjectStore(BaseObjectStore):
           ofs_delta: Whether OFS deltas can be included
           progress: Optional progress reporting method
         """
-        missing_objects = MissingObjectFinder(self, have, want, shallow, progress)
+        missing_objects = MissingObjectFinder(
+            self, haves=have, wants=want, shallow=shallow, progress=progress)
         remote_has = missing_objects.get_remote_has()
         object_ids = list(missing_objects)
         return len(object_ids), generate_unpacked_objects(

+ 3 - 30
dulwich/pack.py

@@ -200,8 +200,8 @@ class UnpackedObject:
 
     # TODO(dborowitz): read_zlib_chunks and unpack_object could very well be
     # methods of this object.
-    def __init__(self, pack_type_num, delta_base, decomp_len=None, crc32=None, sha=None, decomp_chunks=None):
-        self.offset = None
+    def __init__(self, pack_type_num, *, delta_base=None, decomp_len=None, crc32=None, sha=None, decomp_chunks=None, offset=None):
+        self.offset = offset
         self._sha = sha
         self.pack_type_num = pack_type_num
         self.delta_base = delta_base
@@ -875,7 +875,7 @@ def unpack_object(
     else:
         delta_base = None
 
-    unpacked = UnpackedObject(type_num, delta_base, size, crc32)
+    unpacked = UnpackedObject(type_num, delta_base=delta_base, decomp_len=size, crc32=crc32)
     unused = read_zlib_chunks(
         read_some,
         unpacked,
@@ -1193,13 +1193,6 @@ class PackData:
     def __eq__(self, other):
         if isinstance(other, PackData):
             return self.get_stored_checksum() == other.get_stored_checksum()
-        if isinstance(other, list):
-            if len(self) != len(other):
-                return False
-            for o1, o2 in zip(self.iterobjects(), other):
-                if o1 != o2:
-                    return False
-            return True
         return False
 
     def _get_size(self):
@@ -1226,27 +1219,7 @@ class PackData:
         """
         return compute_file_sha(self._file, end_ofs=-20).digest()
 
-    def iterobjects(self, progress: Optional[ProgressFn] = None, compute_crc32: bool = True):
-        self._file.seek(self._header_size)
-        for i in range(1, self._num_objects + 1):
-            offset = self._file.tell()
-            unpacked, unused = unpack_object(
-                self._file.read, compute_crc32=compute_crc32
-            )
-            if progress is not None:
-                progress(i, self._num_objects)
-            yield (
-                offset,
-                unpacked.pack_type_num,
-                unpacked._obj(),
-                unpacked.crc32,
-            )
-            # Back up over unused data.
-            self._file.seek(-len(unused), SEEK_CUR)
-
     def iter_unpacked(self, *, include_comp: bool = False):
-        # TODO(dborowitz): Merge this with iterobjects, if we can change its
-        # return type.
         self._file.seek(self._header_size)
 
         if self._num_objects is None:

+ 5 - 5
dulwich/repo.py

@@ -584,11 +584,11 @@ class BaseRepo:
 
         return MissingObjectFinder(
             self.object_store,
-            haves,
-            wants,
-            self.get_shallow(),
-            progress,
-            get_tagged,
+            haves=haves,
+            wants=wants,
+            shallow=self.get_shallow(),
+            progress=progress,
+            get_tagged=get_tagged,
             get_parents=get_parents)
 
     def generate_pack_data(self, have: List[ObjectID], want: List[ObjectID],

+ 9 - 11
dulwich/tests/test_pack.py

@@ -284,7 +284,7 @@ class TestPackData(PackTests):
         with self.get_pack_data(pack1_sha) as p:
             self.assertSucceeds(p.check)
 
-    def test_iterobjects(self):
+    def test_iter_unpacked(self):
         with self.get_pack_data(pack1_sha) as p:
             commit_data = (
                 b"tree b2a2766a2879c209ab1176e7e778b81ae422eeaa\n"
@@ -297,14 +297,12 @@ class TestPackData(PackTests):
             )
             blob_sha = b"6f670c0fb53f9463760b7295fbb814e965fb20c8"
             tree_data = b"100644 a\0" + hex_to_sha(blob_sha)
-            actual = []
-            for offset, type_num, chunks, crc32 in p.iterobjects():
-                actual.append((offset, type_num, b"".join(chunks), crc32))
+            actual = list(p.iter_unpacked())
             self.assertEqual(
                 [
-                    (12, 1, commit_data, 3775879613),
-                    (138, 2, tree_data, 912998690),
-                    (178, 3, b"test 1\n", 1373561701),
+                    UnpackedObject(offset=12, pack_type_num=1, decomp_chunks=[commit_data], crc32=None),
+                    UnpackedObject(offset=138, pack_type_num=2, decomp_chunks=[tree_data], crc32=None),
+                    UnpackedObject(offset=178, pack_type_num=3, decomp_chunks=[b"test 1\n"], crc32=None),
                 ],
                 actual,
             )
@@ -583,7 +581,7 @@ class TestThinPack(PackTests):
         with self.make_pack(False) as p:
             expected = UnpackedObject(
                 7,
-                b"\x19\x10(\x15f=#\xf8\xb7ZG\xe7\xa0\x19e\xdc\xdc\x96F\x8c",
+                delta_base=b"\x19\x10(\x15f=#\xf8\xb7ZG\xe7\xa0\x19e\xdc\xdc\x96F\x8c",
                 decomp_chunks=[b'\x03\x07\x90\x03\x041234'],
             )
             expected.offset = 12
@@ -592,7 +590,7 @@ class TestThinPack(PackTests):
         with self.make_pack(True) as p:
             expected = UnpackedObject(
                 7,
-                b"\x19\x10(\x15f=#\xf8\xb7ZG\xe7\xa0\x19e\xdc\xdc\x96F\x8c",
+                delta_base=b"\x19\x10(\x15f=#\xf8\xb7ZG\xe7\xa0\x19e\xdc\xdc\x96F\x8c",
                 decomp_chunks=[b'\x03\x07\x90\x03\x041234'],
             )
             expected.offset = 12
@@ -805,7 +803,7 @@ class ReadZlibTests(TestCase):
     def setUp(self):
         super().setUp()
         self.read = BytesIO(self.comp + self.extra).read
-        self.unpacked = UnpackedObject(Tree.type_num, None, len(self.decomp), 0)
+        self.unpacked = UnpackedObject(Tree.type_num, decomp_len=len(self.decomp), crc32=0)
 
     def test_decompress_size(self):
         good_decomp_len = len(self.decomp)
@@ -824,7 +822,7 @@ class ReadZlibTests(TestCase):
         self.assertRaises(zlib.error, read_zlib_chunks, read, self.unpacked)
 
     def test_decompress_empty(self):
-        unpacked = UnpackedObject(Tree.type_num, None, 0, None)
+        unpacked = UnpackedObject(Tree.type_num, decomp_len=0)
         comp = zlib.compress(b"")
         read = BytesIO(comp + self.extra).read
         unused = read_zlib_chunks(read, unpacked)