def run(self, src_location, dest_location): from bzrlib.bzrdir import BzrDir, format_registry from bzrlib.errors import NoRepositoryPresent, NotBranchError from bzrlib.repository import Repository source_repo = Repository.open(src_location) format = format_registry.make_bzrdir('rich-root-pack') try: target_bzrdir = BzrDir.open(dest_location) except NotBranchError: target_bzrdir = BzrDir.create(dest_location, format=format) try: target_repo = target_bzrdir.open_repository() except NoRepositoryPresent: target_repo = target_bzrdir.create_repository(shared=True) target_repo.fetch(source_repo) for name, ref in source_repo._git.heads().iteritems(): head_loc = os.path.join(dest_location, name) try: head_bzrdir = BzrDir.open(head_loc) except NotBranchError: head_bzrdir = BzrDir.create(head_loc, format=format) try: head_branch = head_bzrdir.open_branch() except NotBranchError: head_branch = head_bzrdir.create_branch() head_branch.generate_revision_history( source_repo.get_mapping().revision_id_foreign_to_bzr(ref))
def run(self, src_location, dest_location): from bzrlib.bzrdir import BzrDir, format_registry from bzrlib.errors import NoRepositoryPresent, NotBranchError from bzrlib.repository import Repository source_repo = Repository.open(src_location) format = format_registry.make_bzrdir('rich-root-pack') try: target_bzrdir = BzrDir.open(dest_location) except NotBranchError: target_bzrdir = BzrDir.create(dest_location, format=format) try: target_repo = target_bzrdir.open_repository() except NoRepositoryPresent: target_repo = target_bzrdir.create_repository(shared=True) target_repo.fetch(source_repo) for name, ref in source_repo._git.heads().iteritems(): head_loc = os.path.join(dest_location, name) try: head_bzrdir = BzrDir.open(head_loc) except NotBranchError: head_bzrdir = BzrDir.create(head_loc, format=format) try: head_branch = head_bzrdir.open_branch() except NotBranchError: head_branch = head_bzrdir.create_branch() head_branch.generate_revision_history(source_repo.get_mapping().revision_id_foreign_to_bzr(ref))
def test_subtree_format_repo_format(self): """Even subtree formats use 2a if they don't have tree references.""" self.useBzrBranches(direct_database=True) format = format_registry.make_bzrdir('pack-0.92-subtree') branch, tree = self.create_branch_and_tree(format=format) upgrader = self.getUpgrader(tree.branch, branch) with read_locked(upgrader.bzr_branch): target_format = upgrader.get_target_format() self.assertIs(target_format._repository_format.__class__, RepositoryFormat2a)
def test_has_tree_references(self): """Detects whether repo contains actual tree references.""" self.useBzrBranches(direct_database=True) format = format_registry.make_bzrdir('pack-0.92-subtree') branch, tree = self.create_branch_and_tree(format=format) upgrader = self.getUpgrader(tree.branch, branch) with read_locked(tree.branch.repository): self.assertFalse(upgrader.has_tree_references()) self.addTreeReference(tree) with read_locked(tree.branch.repository): self.assertTrue(upgrader.has_tree_references())
def test_tree_reference_repo_format(self): """Repos with tree references get 2aSubtree.""" self.useBzrBranches(direct_database=True) format = format_registry.make_bzrdir('pack-0.92-subtree') branch, tree = self.create_branch_and_tree(format=format) upgrader = self.getUpgrader(tree.branch, branch) self.addTreeReference(tree) with read_locked(upgrader.bzr_branch): target_format = upgrader.get_target_format() self.assertIs(target_format._repository_format.__class__, RepositoryFormat2aSubtree)
def test_use_subtree_format_for_tree_references(self): """Subtree references cause RepositoryFormat2aSubtree to be used.""" self.useBzrBranches(direct_database=True) format = format_registry.make_bzrdir('pack-0.92-subtree') branch, tree = self.create_branch_and_tree(format=format) sub_branch = BzrDir.create_branch_convenience( tree.bzrdir.root_transport.clone('sub').base, format=format) tree.add_reference(sub_branch.bzrdir.open_workingtree()) tree.commit('added tree reference', committer='*****@*****.**') upgrader = self.getUpgrader(tree.branch, branch) with read_locked(tree.branch): upgrader.create_upgraded_repository() upgraded = upgrader.get_bzrdir().open_repository() self.assertIs(RepositoryFormat2aSubtree, upgraded._format.__class__)
def get_target_format(self): """Return the format to upgrade a branch to. The repository format is always upgraded to a 2a format, but the branch format is left alone if the branch is a loom. :param branch: The bzr branch to upgrade :return: A Metadir format instance. """ format = format_registry.make_bzrdir('2a') try: require_loom_branch(self.bzr_branch) except NotALoom: pass else: format._branch_format = self.bzr_branch._format if getattr( self.bzr_branch.repository._format, 'supports_tree_reference', False): if self.has_tree_references(): format._repository_format = RepositoryFormat2aSubtree() return format