def move_in_thin_pack(self, path): """Move a specific file containing a pack into the pack directory. :note: The file should be on the same file system as the packs directory. :param path: Path to the pack file. """ 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, ((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") os.rename(temppath+".idx", newbasename+".idx") self._add_known_pack(newbasename)
def test_empty(self): pack_checksum = 'r\x19\x80\xe8f\xaf\x9a_\x93\xadgAD\xe1E\x9b\x8b\xa3\xe7\xb7' self._write_fn("empty.idx", [], pack_checksum) idx = load_pack_index("empty.idx") self.assertTrue(idx.check()) self.assertEquals(idx.get_pack_checksum(), pack_checksum) self.assertEquals(0, len(idx))
def index(self, filename, entries, pack_checksum): path = os.path.join(self.tempdir, filename) self.writeIndex(path, entries, pack_checksum) idx = load_pack_index(path) self.assertSucceeds(idx.check) self.assertEquals(idx.version, self._expected_version) return idx
def test_empty(self): pack_checksum = "r\x19\x80\xe8f\xaf\x9a_\x93\xadgAD\xe1E\x9b\x8b\xa3\xe7\xb7" self._write_fn("empty.idx", [], pack_checksum) idx = load_pack_index("empty.idx") self.assertTrue(idx.check()) self.assertEquals(idx.get_pack_checksum(), pack_checksum) self.assertEquals(0, len(idx))
def index(self, filename, entries, pack_checksum): path = os.path.join(self.tempdir, filename) self.writeIndex(path, entries, pack_checksum) idx = load_pack_index(path) self.assertSucceeds(idx.check) self.assertEqual(idx.version, self._expected_version) return idx
def test_create_index_v1(self): p = self.get_pack_data(pack1_sha) filename = os.path.join(self.tempdir, 'v1test.idx') p.create_index_v1(filename) idx1 = load_pack_index(filename) idx2 = self.get_pack_index(pack1_sha) self.assertEquals(idx1, idx2)
def test_create_index_v2(self): with self.get_pack_data(pack1_sha) as p: filename = os.path.join(self.tempdir, 'v2test.idx') p.create_index_v2(filename) idx1 = load_pack_index(filename) idx2 = self.get_pack_index(pack1_sha) self.assertEqual(idx1, idx2)
def _idx_load_or_generate(self, path): if not os.path.exists(path): with ui.ui_factory.nested_progress_bar() as pb: def report_progress(cur, total): pb.update("generating index", cur, total) self.data.create_index(path, progress=report_progress) return load_pack_index(path)
def test_create_index_v2(self): p = self.get_pack_data(pack1_sha) filename = os.path.join(self.tempdir, "v2test.idx") p.create_index_v2(filename) idx1 = load_pack_index(filename) idx2 = self.get_pack_index(pack1_sha) self.assertEquals(idx1, idx2)
def test_create_index_v2(self): with self.get_pack_data(pack1_sha) as p: filename = os.path.join(self.tempdir, "v2test.idx") p.create_index_v2(filename) idx1 = load_pack_index(filename) idx2 = self.get_pack_index(pack1_sha) self.assertEqual(oct(os.stat(filename).st_mode), indexmode) self.assertEqual(idx1, idx2)
def test_single(self): pack_checksum = "r\x19\x80\xe8f\xaf\x9a_\x93\xadgAD\xe1E\x9b\x8b\xa3\xe7\xb7" my_entries = [("og\x0c\x0f\xb5?\x94cv\x0br\x95\xfb\xb8\x14\xe9e\xfb \xc8", 178, 42)] my_entries.sort() self._write_fn("single.idx", my_entries, pack_checksum) idx = load_pack_index("single.idx") self.assertEquals(idx.version, self._expected_version) self.assertTrue(idx.check()) self.assertEquals(idx.get_pack_checksum(), pack_checksum) self.assertEquals(1, len(idx)) actual_entries = list(idx.iterentries()) self.assertEquals(len(my_entries), len(actual_entries)) for a, b in zip(my_entries, actual_entries): self.assertEquals(a[0], b[0]) self.assertEquals(a[1], b[1]) if self._has_crc32_checksum: self.assertEquals(a[2], b[2]) else: self.assertTrue(b[2] is None)
def test_single(self): pack_checksum = 'r\x19\x80\xe8f\xaf\x9a_\x93\xadgAD\xe1E\x9b\x8b\xa3\xe7\xb7' my_entries = [ ('og\x0c\x0f\xb5?\x94cv\x0br\x95\xfb\xb8\x14\xe9e\xfb \xc8', 178, 42) ] my_entries.sort() self._write_fn("single.idx", my_entries, pack_checksum) idx = load_pack_index("single.idx") self.assertEquals(idx.version, self._expected_version) self.assertTrue(idx.check()) self.assertEquals(idx.get_pack_checksum(), pack_checksum) self.assertEquals(1, len(idx)) actual_entries = list(idx.iterentries()) self.assertEquals(len(my_entries), len(actual_entries)) for a, b in zip(my_entries, actual_entries): self.assertEquals(a[0], b[0]) self.assertEquals(a[1], b[1]) if self._has_crc32_checksum: self.assertEquals(a[2], b[2]) else: self.assertTrue(b[2] is None)
def get_pack_index(self, sha): """Returns a PackIndex from the datadir with the given sha""" return load_pack_index( os.path.join(self.datadir, 'pack-%s.idx' % sha.decode('ascii')))
def get_pack_index(self, sha): """Returns a PackIndex from the datadir with the given sha""" return load_pack_index(os.path.join(self.datadir, 'pack-%s.idx' % sha))
def get_pack_index(self, sha): """Returns a PackIndex from the datadir with the given sha""" return load_pack_index(os.path.join(self.datadir, b'pack-' + sha + b'.idx'))
def test_create_index_v2(self): p = self.get_pack_data(pack1_sha) p.create_index_v2("v2test.idx") idx1 = load_pack_index("v2test.idx") idx2 = self.get_pack_index(pack1_sha) self.assertEquals(idx1, idx2)
def get_pack_index(self, sha): """Returns a PackIndex from the datadir with the given sha""" return load_pack_index( os.path.join(self.datadir, "pack-%s.idx" % sha.decode("ascii")))
def get_pack_index(self, sha): """Returns a PackIndex from the datadir with the given sha""" return load_pack_index(os.path.join(self.datadir, "pack-%s.idx" % sha))