consistently use chunks internally inside of the pack code.
authorJelmer Vernooij <jelmer@samba.org>
Wed, 31 Mar 2010 19:34:40 +0000 (21:34 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Wed, 31 Mar 2010 19:34:40 +0000 (21:34 +0200)
dulwich/pack.py
dulwich/tests/test_pack.py

index 2a13e724cdc7647832f9932d4579113bbc41b643..4aaac6d106cf47c74544ba326f4773a8d96476e2 100644 (file)
@@ -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:
index fb7cba84d268a425cc13fb6af53b45b9f6c655fd..2dce64b973013d15a626f3b7f187ddad80bf564c 100644 (file)
@@ -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)