def test_get_branch_format_packs(self): # Test the packs branch format. branch = self.make_branch('test', 'pack-0.92') formats = get_branch_formats(branch) self.assertEqual(ControlFormat.BZR_METADIR_1, formats[0]) self.assertEqual(BranchFormat.BZR_BRANCH_6, formats[1]) self.assertEqual(RepositoryFormat.BZR_KNITPACK_1, formats[2])
def test_get_branch_format_knits(self): # Test the knits branch format. branch = self.make_branch('test', 'knit') formats = get_branch_formats(branch) self.assertEqual(ControlFormat.BZR_METADIR_1, formats[0]) self.assertEqual(BranchFormat.BZR_BRANCH_5, formats[1]) self.assertEqual(RepositoryFormat.BZR_KNIT_1, formats[2])
def test_get_branch_format_2a(self): # Test the 2a branch format. branch = self.make_branch('test', '2a') formats = get_branch_formats(branch) self.assertEqual(ControlFormat.BZR_METADIR_1, formats[0]) self.assertEqual(BranchFormat.BZR_BRANCH_7, formats[1]) self.assertEqual(RepositoryFormat.BZR_CHK_2A, formats[2])
def test_get_branch_format_1_9(self): # Test the 1.9 branch format. branch = self.make_branch('test', '1.9') formats = get_branch_formats(branch) self.assertEqual(ControlFormat.BZR_METADIR_1, formats[0]) self.assertEqual(BranchFormat.BZR_BRANCH_7, formats[1]) self.assertEqual(RepositoryFormat.BZR_KNITPACK_6, formats[2])
def check_branch(self, upgraded, branch_format=BranchFormat.BZR_BRANCH_7, repository_format=RepositoryFormat.BZR_CHK_2A): """Check that a branch matches expected post-upgrade formats.""" control, branch, repository = get_branch_formats(upgraded) self.assertEqual(repository, repository_format) self.assertEqual(branch, branch_format)
def run(self, _check_transaction=False): """See `IBranchUpgradeJob`.""" # Set up the new branch structure with server(get_rw_server(), no_replace=True): upgrade_branch_path = tempfile.mkdtemp() try: upgrade_transport = get_transport(upgrade_branch_path) upgrade_transport.mkdir('.bzr') source_branch_transport = get_transport( self.branch.getInternalBzrUrl()) source_branch_transport.clone('.bzr').copy_tree_to_transport( upgrade_transport.clone('.bzr')) transaction.commit() upgrade_branch = BzrBranch.open_from_transport( upgrade_transport) # No transactions are open so the DB connection won't be # killed. with TransactionFreeOperation(): # Perform the upgrade. upgrade(upgrade_branch.base) # Re-open the branch, since its format has changed. upgrade_branch = BzrBranch.open_from_transport( upgrade_transport) source_branch = BzrBranch.open_from_transport( source_branch_transport) source_branch.lock_write() upgrade_branch.pull(source_branch) upgrade_branch.fetch(source_branch) source_branch.unlock() # Move the branch in the old format to backup.bzr try: source_branch_transport.delete_tree('backup.bzr') except NoSuchFile: pass source_branch_transport.rename('.bzr', 'backup.bzr') source_branch_transport.mkdir('.bzr') upgrade_transport.clone('.bzr').copy_tree_to_transport( source_branch_transport.clone('.bzr')) # Re-open the source branch again. source_branch = BzrBranch.open_from_transport( source_branch_transport) formats = get_branch_formats(source_branch) self.branch.branchChanged( self.branch.stacked_on, self.branch.last_scanned_id, *formats) finally: shutil.rmtree(upgrade_branch_path)