Fix fetching of thin packs.
authorJelmer Vernooij <jelmer@samba.org>
Fri, 10 Apr 2009 12:23:01 +0000 (12:23 +0000)
committerJelmer Vernooij <jelmer@samba.org>
Fri, 10 Apr 2009 12:23:01 +0000 (12:23 +0000)
dulwich/object_store.py
dulwich/pack.py

index 83c639afeb05d84b914142c8041ceea6cf33bf5a..591eb49d6cee53538d98fe9331d621143a2c2959 100644 (file)
@@ -146,10 +146,19 @@ class ObjectStore(object):
 
         :param path: Path to the pack file.
         """
-        p = PackData(path)
+        data = PackData(path)
+
+        # Write index for the thin pack (do we really need this?)
+        temppath = os.path.join(self.pack_dir, 
+            sha_to_hex(urllib2.randombytes(20))+".tempidx")
+        data.create_index_v2(temppath, self.get_raw)
+        p = Pack.from_objects(data, load_pack_index(temppath))
+
+        # Write a full pack version
         temppath = os.path.join(self.pack_dir, 
             sha_to_hex(urllib2.randombytes(20))+".temppack")
-        write_pack(temppath, p.iterobjects(self.get_raw), len(p))
+        write_pack(temppath, ((o, None) for o in p.iterobjects(self.get_raw)), 
+                len(p))
         pack_sha = load_pack_index(temppath+".idx").objects_sha1()
         newbasename = os.path.join(self.pack_dir, "pack-%s" % pack_sha)
         os.rename(temppath+".pack", newbasename+".pack")
index 4175e88f3c6458fa367a306fcc5ebdc0cc08f07c..dbde608a0ecd83b66d067167400c50e024b23286 100644 (file)
@@ -523,7 +523,7 @@ class PackData(object):
                     pass
             raise Postpone, (sha, )
         extra = []
-        todo = chain(self.iterobjects(progress), extra)
+        todo = chain(self.iterobjects(progress=progress), extra)
         for (offset, type, obj, crc32) in todo:
             assert isinstance(offset, int)
             assert isinstance(type, int)
@@ -883,6 +883,13 @@ class Pack(object):
         self._data = None
         self._idx = None
 
+    @classmethod
+    def from_objects(self, data, idx):
+        ret = Pack("")
+        ret._data = data
+        ret._idx = idx
+        return ret
+
     def name(self):
         """The SHA over the SHAs of the objects in this pack."""
         return self.idx.objects_sha1()