Changeset 2e9ea87d7178…
Parent b706e4d30405…
by
Changes to 2 files · Browse files at 2e9ea87d7178 Showing diff from parent b706e4d30405 Diff from another changeset...
@@ -41,7 +41,6 @@ Pack,
PackData,
iter_sha1,
- load_packs,
load_pack_index,
write_pack,
write_pack_data,
@@ -169,8 +168,15 @@ def packs(self):
"""List with pack objects."""
if self._pack_cache is None:
- self._pack_cache = list(load_packs(self.pack_dir))
+ self._pack_cache = list(self._load_packs())
return self._pack_cache
+
+ def _load_packs(self):
+ if not os.path.exists(self.pack_dir):
+ return
+ for name in os.listdir(self.pack_dir):
+ if name.startswith("pack-") and name.endswith(".pack"):
+ yield Pack(os.path.join(self.pack_dir, name[:-len(".pack")]))
def _add_known_pack(self, path):
"""Add a newly appeared pack to the cache by path.
|
@@ -68,6 +68,11 @@
def take_msb_bytes(map, offset):
+ """Read bytes marked with most significant bit.
+
+ :param map: The buffer.
+ :param offset: Offset in the buffer at which to start reading.
+ """
ret = []
while len(ret) == 0 or ret[-1] & 0x80:
ret.append(ord(map[offset]))
@@ -75,7 +80,14 @@ return ret
-def read_zlib_chunks(data, offset, dec_size):
+def read_zlib_chunks(data, offset):
+ """Read chunks of zlib data from a buffer.
+
+ :param data: Buffer to read from
+ :param offset: Offset at which to start reading
+ :return: Tuple with list of chunks and length of
+ compressed data length
+ """
obj = zlib.decompressobj()
ret = []
fed = 0
@@ -91,7 +103,14 @@
def read_zlib(data, offset, dec_size):
- ret, comp_len = read_zlib_chunks(data, offset, dec_size)
+ """Read zlib-compressed data from a buffer.
+
+ :param data: Buffer
+ :param offset: Offset in the buffer at which to read
+ :param dec_size: Size of the decompressed buffer
+ :return: Uncompressed buffer and compressed buffer length.
+ """
+ ret, comp_len = read_zlib_chunks(data, offset)
x = "".join(ret)
assert len(x) == dec_size
return x, comp_len
@@ -123,6 +142,10 @@
def load_pack_index(filename):
+ """Load an index file by path.
+
+ :param filename: Path to the index file
+ """
f = open(filename, 'rb')
if f.read(4) == '\377tOc':
version = struct.unpack(">L", f.read(4))[0]
@@ -371,10 +394,6 @@ assert version in (2, 3), "Version was %d" % version
(num_objects,) = unpack_from(">L", header, 8)
return (version, num_objects)
-
-
-def read_pack_tail(f):
- return (f.read(20),)
def unpack_object(map, offset=0):
@@ -472,7 +491,7 @@ def _read_header(self):
(version, self._num_objects) = read_pack_header(self._file)
self._file.seek(self._size-20)
- (self._stored_checksum,) = read_pack_tail(self._file)
+ self._stored_checksum = self._file.read(20)
def __len__(self):
"""Returns the number of objects in this pack."""
@@ -636,6 +655,7 @@ return self._stored_checksum
def check(self):
+ """Check the consistency of this pack."""
return (self.calculate_checksum() == self.get_stored_checksum())
def get_object_at(self, offset):
@@ -1097,14 +1117,6 @@ *self.data.resolve_object(offset, type, obj, get_raw))
-def load_packs(path):
- if not os.path.exists(path):
- return
- for name in os.listdir(path):
- if name.startswith("pack-") and name.endswith(".pack"):
- yield Pack(os.path.join(path, name[:-len(".pack")]))
-
-
try:
from dulwich._pack import apply_delta, bisect_find_sha
except ImportError:
|
Loading...