Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
 def test_swap_in_retains_original(self):
     """Swap in retains the original branch in backup.bzr."""
     upgrader = self.prepare()
     upgrader.start_upgrade()
     upgrader.add_upgraded_branch()
     upgrader.swap_in()
     t = get_transport(upgrader.branch.getInternalBzrUrl())
     t = t.clone('backup.bzr')
     branch = Branch.open_from_transport(t)
     self.check_branch(branch, BranchFormat.BZR_BRANCH_6,
                       RepositoryFormat.BZR_KNITPACK_1)
Exemplo n.º 4
0
    def test_directory_open_branch(self):
        # Test that opening an lp: branch redirects to the real location.
        target_branch = self.make_branch('target')

        class FooService(object):
            """A directory service that maps the name to a FILE url"""
            def look_up(self, name, url):
                if 'lp:///apt' == url:
                    return target_branch.base.rstrip('/')
                return '!unexpected look_up value!'

        directories.remove('lp:')
        directories.register('lp:', FooService, 'Map lp URLs to local urls')
        self.addCleanup(_register_directory)
        self.addCleanup(lambda: directories.remove('lp:'))
        transport = get_transport('lp:///apt')
        branch = Branch.open_from_transport(transport)
        self.assertEqual(target_branch.base, branch.base)
Exemplo n.º 5
0
    def test_directory_open_branch(self):
        # Test that opening an lp: branch redirects to the real location.
        target_branch = self.make_branch('target')
        class FooService(object):
            """A directory service that maps the name to a FILE url"""

            def look_up(self, name, url):
                if 'lp:///apt' == url:
                    return target_branch.base.rstrip('/')
                return '!unexpected look_up value!'

        directories.remove('lp:')
        directories.register('lp:', FooService, 'Map lp URLs to local urls')
        self.addCleanup(_register_directory)
        self.addCleanup(lambda: directories.remove('lp:'))
        transport = get_transport('lp:///apt')
        branch = Branch.open_from_transport(transport)
        self.assertEqual(target_branch.base, branch.base)
Exemplo n.º 6
0
    def createDestinationBranch(self, source_branch, destination_url):
        """See `BranchOpenPolicy.createDestinationBranch`.

        Because we control the process that creates import branches, a
        vfs-level copy is safe and more efficient than a bzr fetch.
        """
        source_transport = source_branch.bzrdir.root_transport
        dest_transport = get_transport(destination_url)
        while True:
            # We loop until the remote file list before and after the copy is
            # the same to catch the case where the remote side is being
            # mutated as we copy it.
            if dest_transport.has('.'):
                dest_transport.delete_tree('.')
            files_before = set(source_transport.iter_files_recursive())
            source_transport.copy_tree_to_transport(dest_transport)
            files_after = set(source_transport.iter_files_recursive())
            if files_before == files_after:
                break
        return Branch.open_from_transport(dest_transport)