# FIXME: Will just fetch everything..
graphwalker = SimpleFetchGraphWalker([], None)
-f = r.add_pack()
+f, commit = r.add_pack()
try:
client.fetch_pack(path, determine_wants, graphwalker, f.write, sys.stdout.write)
finally:
f.close()
+ commit()
return x, comp_len
+def iter_sha1(iter):
+ sha = hashlib.sha1()
+ for name in iter:
+ sha.update(name)
+ return sha.hexdigest()
+
+
def hex_to_sha(hex):
"""Convert a hex string to a binary sha string."""
ret = ""
yield self._unpack_name(i)
def objects_sha1(self):
- sha = hashlib.sha1()
- for name in self._itersha():
- sha.update(name)
- return sha.hexdigest()
+ return iter_sha1(self._itersha())
def iterentries(self):
"""Iterate over the entries in this pack index.
found[sha] = (type, obj)
yield sha, offset, shafile.crc32()
+ def sorted_entries(self):
+ ret = list(self.iterentries())
+ ret.sort()
+ return ret
+
def create_index_v1(self, filename):
- entries = list(self.iterentries())
- # Sort entries first
- entries = sorted(entries)
+ entries = self.sorted_entries()
write_pack_index_v1(filename, entries, self.calculate_checksum())
def create_index_v2(self, filename):
- entries = list(self.iterentries())
- # Sort entries first
- entries = sorted(entries)
+ entries = self.sorted_entries()
write_pack_index_v2(filename, entries, self.calculate_checksum())
def get_stored_checksum(self):
Tree,
Blob,
)
-from pack import load_packs
+from pack import load_packs, iter_sha1, PackData, write_pack_index_v2
import tempfile
OBJECTDIR = 'objects'
return os.path.join(self.object_dir(), PACKDIR)
def add_pack(self):
- fd, name = tempfile.mkstemp(suffix='.pack', prefix='', dir=self.pack_dir())
- return os.fdopen(fd, 'w')
+ fd, path = tempfile.mkstemp(dir=self.pack_dir(), suffix=".pack")
+ f = os.fdopen(fd, 'w')
+ def commit():
+ self._move_in_pack(path)
+ return f, commit
+
+ def _move_in_pack(self, path):
+ p = PackData(path)
+ entries = p.sorted_entries()
+ basename = os.path.join(self.pack_dir(), "pack-%s" % iter_sha1(entry[0] for entry in entries))
+ write_pack_index_v2(basename+".idx", entries, p.calculate_checksum())
+ os.rename(path, basename + ".pack")
def _get_packs(self):
if self._packs is None: