def test_pack_preserves_chk_bytes_store(self): leaf_lines = [b"chkleaf:\n", b"0\n", b"1\n", b"0\n", b"\n"] leaf_sha1 = osutils.sha_strings(leaf_lines) node_lines = [ b"chknode:\n", b"0\n", b"1\n", b"1\n", b"foo\n", b"\x00sha1:%s\n" % (leaf_sha1, ) ] node_sha1 = osutils.sha_strings(node_lines) expected_set = {(b'sha1:' + leaf_sha1, ), (b'sha1:' + node_sha1, )} repo = self.make_repository('.') with repo.lock_write(): with repository.WriteGroup(repo): # Internal node pointing at a leaf. repo.chk_bytes.add_lines((None, ), None, node_lines, random_id=True) with repository.WriteGroup(repo): # Leaf in a separate pack. repo.chk_bytes.add_lines((None, ), None, leaf_lines, random_id=True) repo.pack() self.assertEqual(expected_set, repo.chk_bytes.keys()) # and reopening repo = repo.controldir.open_repository() with repo.lock_read(): self.assertEqual(expected_set, repo.chk_bytes.keys())
def setUp(self): super(TestCaseWithComplexRepository, self).setUp() tree_a = self.make_branch_and_tree('a') self.controldir = tree_a.branch.controldir # add a corrupt inventory 'orphan' # this may need some generalising for knits. with tree_a.lock_write(), _mod_repository.WriteGroup( tree_a.branch.repository): inv_file = tree_a.branch.repository.inventories inv_file.add_lines((b'orphan', ), [], []) # add a real revision 'rev1' tree_a.commit('rev1', rev_id=b'rev1', allow_pointless=True) # add a real revision 'rev2' based on rev1 tree_a.commit('rev2', rev_id=b'rev2', allow_pointless=True) # add a reference to a ghost tree_a.add_parent_tree_id(b'ghost1') try: tree_a.commit('rev3', rev_id=b'rev3', allow_pointless=True) except errors.RevisionNotPresent: raise tests.TestNotApplicable( "Cannot test with ghosts for this format.") # add another reference to a ghost, and a second ghost. tree_a.add_parent_tree_id(b'ghost1') tree_a.add_parent_tree_id(b'ghost2') tree_a.commit('rev4', rev_id=b'rev4', allow_pointless=True)
def test_chk_bytes_are_fully_buffered(self): repo = self.make_repository('.') repo.lock_write() self.addCleanup(repo.unlock) with repository.WriteGroup(repo): sha1, len, _ = repo.chk_bytes.add_lines((None, ), None, [b"foo\n", b"bar\n"], random_id=True) self.assertEqual(b'4e48e2c9a3d2ca8a708cb0cc545700544efb5021', sha1) self.assertEqual( {(b'sha1:4e48e2c9a3d2ca8a708cb0cc545700544efb5021', )}, repo.chk_bytes.keys()) # This may not always be correct if we change away from BTreeGraphIndex # in the future. But for now, lets check that chk_bytes are fully # buffered index = repo.chk_bytes._index._graph_index._indices[0] self.assertIsInstance(index, btree_index.BTreeGraphIndex) self.assertIs(type(index._leaf_node_cache), dict) # Re-opening the repository should also have a repo with everything # fully buffered repo2 = repository.Repository.open(self.get_url()) repo2.lock_read() self.addCleanup(repo2.unlock) index = repo2.chk_bytes._index._graph_index._indices[0] self.assertIsInstance(index, btree_index.BTreeGraphIndex) self.assertIs(type(index._leaf_node_cache), dict)
def test_reserved_id(self): repo = self.make_repository('repository') with repo.lock_write(), _mod_repository.WriteGroup(repo): self.assertRaises(errors.ReservedId, repo.add_inventory, b'reserved:', None, None) self.assertRaises(errors.ReservedId, repo.add_inventory_by_delta, "foo", [], b'reserved:', None) self.assertRaises(errors.ReservedId, repo.add_revision, b'reserved:', None)
def test_add_bytes_to_chk_bytes_store(self): repo = self.make_repository('.') with repo.lock_write(), repository.WriteGroup(repo): sha1, len, _ = repo.chk_bytes.add_lines((None, ), None, [b"foo\n", b"bar\n"], random_id=True) self.assertEqual(b'4e48e2c9a3d2ca8a708cb0cc545700544efb5021', sha1) self.assertEqual( {(b'sha1:4e48e2c9a3d2ca8a708cb0cc545700544efb5021', )}, repo.chk_bytes.keys()) # And after an unlock/lock pair with repo.lock_read(): self.assertEqual( {(b'sha1:4e48e2c9a3d2ca8a708cb0cc545700544efb5021', )}, repo.chk_bytes.keys()) # and reopening repo = repo.controldir.open_repository() with repo.lock_read(): self.assertEqual( {(b'sha1:4e48e2c9a3d2ca8a708cb0cc545700544efb5021', )}, repo.chk_bytes.keys())