Exemplo n.º 1
0
    def export_threads(self, root_transport):
        """Export the threads in this loom as branches.

        :param root_transport: Transport for the directory to place branches
            under.  Defaults to branch root transport.
        """
        threads = self.get_loom_state().get_threads()
        for thread_name, thread_revision, _parents in threads:
            thread_transport = root_transport.clone(thread_name)
            user_location = urlutils.unescape_for_display(
                thread_transport.base, 'utf-8')
            try:
                control_dir = controldir.ControlDir.open(
                    thread_transport.base,
                    possible_transports=[thread_transport])
                tree, branch = control_dir._get_tree_branch()
            except errors.NotBranchError:
                trace.note('Creating branch at %s' % user_location)
                branch = controldir.ControlDir.create_branch_convenience(
                    thread_transport.base,
                    possible_transports=[thread_transport])
                tree, branch = branch.controldir.open_tree_or_branch(
                    thread_transport.base)
            else:
                if thread_revision == branch.last_revision():
                    trace.note('Skipping up-to-date branch at %s' %
                               user_location)
                    continue
                else:
                    trace.note('Updating branch at %s' % user_location)
            if tree is not None:
                tree.pull(self, stop_revision=thread_revision)
            else:
                branch.pull(self, stop_revision=thread_revision)
Exemplo n.º 2
0
    def test_upgrade_url(self):
        self.run_bzr('init --format=pack-0.92')
        t = self.get_transport()
        url = t.base
        display_url = urlutils.unescape_for_display(url, 'utf-8')
        out, err = self.run_bzr(['upgrade', '--format=2a', url])
        backup_dir = 'backup.bzr.~1~'
        self.assertEqualDiff(
            """Upgrading branch %s ...
starting upgrade of %s
making backup of %s.bzr
  to %s%s
starting repository conversion
repository converted
finished
""" % (display_url, display_url, display_url, display_url, backup_dir), out)
        self.assertEqual('', err)
Exemplo n.º 3
0
    def test_push_suggests_parent_alias(self):
        """Push suggests using :parent if there is a known parent branch."""
        tree_a = self.make_branch_and_tree('a')
        tree_a.commit('this is a commit')
        tree_b = self.make_branch_and_tree('b')

        # If there is no parent location set, :parent isn't mentioned.
        out = self.run_bzr('push', working_dir='a', retcode=3)
        self.assertEqual(out,
                         ('', 'brz: ERROR: No push location known or specified.\n'))

        # If there is a parent location set, the error suggests :parent.
        tree_a.branch.set_parent(tree_b.branch.base)
        out = self.run_bzr('push', working_dir='a', retcode=3)
        self.assertEqual(out,
                         ('', 'brz: ERROR: No push location known or specified. '
                          'To push to the parent branch '
                          '(at %s), use \'brz push :parent\'.\n' %
                          urlutils.unescape_for_display(tree_b.branch.base, 'utf-8')))
Exemplo n.º 4
0
    def run(self, from_location, to_location=None, format=None, trees=False,
            standalone=False, layout=None, all=False, prefix=None, keep=False,
            restore=False, until=None, colocated=False):
        from breezy import (
            osutils,
            trace,
            urlutils,
            )
        from breezy.controldir import ControlDir
        from breezy.errors import (
            BzrCommandError,
            NoRepositoryPresent,
            )
        from . import gettext
        from .convert import convert_repository
        from .remote import SvnRemoteAccess
        from .repository import SvnRepository
        from .workingtree import SvnCheckout
        import os
        from subvertpy import NODE_NONE

        if to_location is None:
            to_location = os.path.basename(from_location.rstrip("/\\"))

        if all:
            # All implies shared repository
            # (otherwise there is no repository to store revisions in)
            standalone = False

        if os.path.isfile(from_location):
            from .convert import load_dumpfile
            import tempfile
            tmp_repos = tempfile.mkdtemp(prefix='bzr-svn-dump-')
            load_dumpfile(from_location, tmp_repos)
            from_location = tmp_repos
        else:
            tmp_repos = None

        from_dir = ControlDir.open(from_location)

        if not (isinstance(from_dir, SvnRemoteAccess) or
                isinstance(from_dir, SvnCheckout)):
            raise BzrCommandError(gettext(
                "Source repository is not a Subversion repository."))

        try:
            from_repos = from_dir.open_repository()
        except NoRepositoryPresent:
            if prefix is not None:
                raise BzrCommandError(
                    gettext("Path inside repository specified "
                            "and --prefix specified"))
            from_repos = from_dir.find_repository(_ignore_branch_path=True)
            assert from_dir.root_transport.base.startswith(from_repos.base)
            prefix = from_dir.root_transport.base[
                len(from_repos.base):].strip("/")
            prefix = prefix.encode("utf-8")

        if not isinstance(from_repos, SvnRepository):
            raise BzrCommandError(
                    gettext("Not a Subversion repository: %s") % from_location)

        if until is None:
            to_revnum = from_repos.get_latest_revnum()
        else:
            to_revnum = min(until, from_repos.get_latest_revnum())

        with from_repos.lock_read():
            if prefix is not None:
                if layout is None:
                    overall_layout = from_repos.get_guessed_layout()
                else:
                    overall_layout = layout
                prefix = prefix.strip("/") + "/"
                if overall_layout.is_branch(prefix):
                    raise BzrCommandError(
                        gettext("%s appears to contain a branch. "
                                "For individual branches, use 'bzr branch'.") %
                        from_location)
                # FIXME: Hint about is_tag()
                elif overall_layout.is_branch_parent(prefix):
                    self.outf.write(
                        gettext("Importing branches with prefix %s\n") %
                        ("/" + urlutils.unescape_for_display(prefix,
                         self.outf.encoding)))
                else:
                    raise BzrCommandError(
                        gettext("The specified path is inside a branch. "
                                "Specify a different URL or a different "
                                "repository layout (see also "
                                "'bzr help svn-layout')."))

            if (prefix is not None and
                    from_repos.transport.check_path(prefix, to_revnum)
                    == NODE_NONE):
                raise BzrCommandError("Prefix %s does not exist" % prefix)

            def filter_branch(branch):
                if (prefix is not None and
                        not branch.get_branch_path().startswith(prefix)):
                    return False
                return True

            trace.note(gettext("Using repository layout: %s"),
                       layout or from_repos.get_layout())
            convert_repository(
                from_repos, to_location, layout,
                not standalone, trees, all, format=format,
                filter_branch=filter_branch, keep=keep,
                incremental=not restore, to_revnum=to_revnum, prefix=prefix,
                colocated=colocated, remember_parent=(tmp_repos is None))

            if tmp_repos is not None:
                osutils.rmtree(tmp_repos)
            if not trees:
                trace.note(
                    gettext("Use 'bzr checkout' to create a working tree in "
                            "the newly created branches."))
Exemplo n.º 5
0
 def friendly_location(url):
     path = urlutils.unescape_for_display(url, 'ascii')
     try:
         return osutils.relpath(osutils.getcwd(), path)
     except errors.PathNotChild:
         return path