implement chunked version of ShaFile.as_legacy_object.
authorJelmer Vernooij <jelmer@samba.org>
Fri, 2 Apr 2010 14:07:33 +0000 (16:07 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Fri, 2 Apr 2010 14:07:33 +0000 (16:07 +0200)
dulwich/objects.py

index 4398336bb92d5a9504ddf8b5bf9f77efd3df0629..9a77cd32d37d1be6d82984d4478bc6e285dde239 100644 (file)
@@ -133,9 +133,15 @@ class ShaFile(object):
         object.set_raw_string(text)
         return object
 
+    def as_legacy_object_chunks(self):
+        compobj = zlib.compressobj()
+        yield compobj.compress(self._header())
+        for chunk in self.as_raw_chunks():
+            yield compobj.compress(chunk)
+        yield compobj.flush()
+
     def as_legacy_object(self):
-        text = self.as_raw_string()
-        return zlib.compress("%s %d\0%s" % (self.type_name, len(text), text))
+        return "".join(self.as_legacy_object_chunks())
 
     def as_raw_chunks(self):
         if self._needs_serialization: