Browse Source

consistently use chunks internally inside of the pack code.

Jelmer Vernooij 15 years ago
parent
commit
9ec4b43bca
2 changed files with 13 additions and 13 deletions
  1. 12 12
      dulwich/pack.py
  2. 1 1
      dulwich/tests/test_pack.py

+ 12 - 12
dulwich/pack.py

@@ -540,7 +540,7 @@ class PackData(object):
         :return: Tuple with object type and contents.
         """
         if type not in (6, 7): # Not a delta
-            return type, "".join(obj)
+            return type, obj
 
         if get_offset is None:
             get_offset = self.get_object_at
@@ -561,11 +561,11 @@ class PackData(object):
             # Can't be a ofs delta, as we wouldn't know the base offset
             assert type != 6
             base_offset = None
-        type, base_text = self.resolve_object(base_offset, type, base_obj,
+        type, base_chunks = self.resolve_object(base_offset, type, base_obj,
             get_ref)
         if base_offset is not None:
-            self._offset_cache[base_offset] = type, base_text
-        return (type, "".join(apply_delta(base_text, delta)))
+            self._offset_cache[base_offset] = type, base_chunks
+        return (type, apply_delta("".join(base_chunks), delta))
   
     def iterobjects(self, progress=None):
 
@@ -587,9 +587,7 @@ class PackData(object):
                 if self.i == self.num:
                     raise StopIteration
                 self.map.seek(self.offset)
-                (type, obj_chunks, total_size, unused) = unpack_object(
-                    self.map.read)
-                obj = "".join(obj_chunks)
+                (type, obj, total_size, unused) = unpack_object(self.map.read)
                 self.map.seek(self.offset)
                 crc32 = zlib.crc32(self.map.read(total_size)) & 0xffffffff
                 ret = (self.offset, type, obj, crc32)
@@ -630,13 +628,13 @@ class PackData(object):
         for (offset, type, obj, crc32) in todo:
             assert isinstance(offset, int)
             assert isinstance(type, int)
-            assert isinstance(obj, tuple) or isinstance(obj, str)
+            assert isinstance(obj, list) or isinstance(obj, str)
             try:
                 type, obj = self.resolve_object(offset, type, obj, get_ref_text)
             except Postpone, (sha, ):
                 postponed[sha].append((offset, type, obj))
             else:
-                shafile = ShaFile.from_raw_string(type, obj)
+                shafile = ShaFile.from_raw_chunks(type, obj)
                 sha = shafile.sha().digest()
                 found[sha] = offset
                 yield sha, offset, crc32
@@ -1141,7 +1139,9 @@ class Pack(object):
           offset = int(offset)
         if resolve_ref is None:
             resolve_ref = self.get_raw
-        return self.data.resolve_object(offset, obj_type, obj, resolve_ref)
+        kind, chunks = self.data.resolve_object(offset, obj_type, obj,
+            resolve_ref)
+        return kind, "".join(chunks)
 
     def __getitem__(self, sha1):
         """Retrieve the specified SHA1."""
@@ -1154,8 +1154,8 @@ class Pack(object):
             get_raw = self.get_raw
         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, get_raw))
+            type, obj = self.data.resolve_object(offset, type, obj, get_raw)
+            yield ShaFile.from_raw_chunks(type, obj)
 
 
 try:

+ 1 - 1
dulwich/tests/test_pack.py

@@ -140,7 +140,7 @@ class TestPackData(PackTests):
   
     def test_iterobjects(self):
         p = self.get_pack_data(pack1_sha)
-        self.assertEquals([(12, 1, 'tree b2a2766a2879c209ab1176e7e778b81ae422eeaa\nauthor James Westby <jw+debian@jameswestby.net> 1174945067 +0100\ncommitter James Westby <jw+debian@jameswestby.net> 1174945067 +0100\n\nTest commit\n', 3775879613L), (138, 2, '100644 a\x00og\x0c\x0f\xb5?\x94cv\x0br\x95\xfb\xb8\x14\xe9e\xfb \xc8', 912998690L), (178, 3, 'test 1\n', 1373561701L)], list(p.iterobjects()))
+        self.assertEquals([(12, 1, 'tree b2a2766a2879c209ab1176e7e778b81ae422eeaa\nauthor James Westby <jw+debian@jameswestby.net> 1174945067 +0100\ncommitter James Westby <jw+debian@jameswestby.net> 1174945067 +0100\n\nTest commit\n', 3775879613L), (138, 2, '100644 a\x00og\x0c\x0f\xb5?\x94cv\x0br\x95\xfb\xb8\x14\xe9e\xfb \xc8', 912998690L), (178, 3, 'test 1\n', 1373561701L)], [(len, type, "".join(chunks), offset) for (len, type, chunks, offset) in p.iterobjects()])
   
     def test_iterentries(self):
         p = self.get_pack_data(pack1_sha)