Beispiel #1
0
 def make_double_stacked_branches(self):
     wt_a = self.make_branch_and_tree('a')
     branch_a = wt_a.branch
     branch_b = self.make_branch('b')
     branch_b.set_stacked_on_url(
         urlutils.relative_url(branch_b.base, branch_a.base))
     branch_c = self.make_branch('c')
     branch_c.set_stacked_on_url(
         urlutils.relative_url(branch_c.base, branch_b.base))
     revid_1 = wt_a.commit('first commit')
     return branch_a, branch_b, branch_c, revid_1
Beispiel #2
0
 def make_double_stacked_branches(self):
     wt_a = self.make_branch_and_tree('a')
     branch_a = wt_a.branch
     branch_b = self.make_branch('b')
     branch_b.set_stacked_on_url(
         urlutils.relative_url(branch_b.base, branch_a.base))
     branch_c = self.make_branch('c')
     branch_c.set_stacked_on_url(
         urlutils.relative_url(branch_c.base, branch_b.base))
     revid_1 = wt_a.commit('first commit')
     return branch_a, branch_b, branch_c, revid_1
Beispiel #3
0
 def remote_path_from_transport(self, transport):
     # Strip the optional 'bzr+' prefix from transport so it will have the
     # same scheme as self.
     transport_base = transport.base
     if transport_base.startswith('bzr+'):
         transport_base = transport_base[4:]
     rel_url = urlutils.relative_url(self.base, transport_base)
     return urlutils.unquote(rel_url)
Beispiel #4
0
 def assertLocations(self, expected_locations):
     br, _ = branch.Branch.open_containing(self.working_dir)
     if not expected_locations:
         self.assertEqual(None, br.get_parent())
     else:
         expected_pull_location = expected_locations[0]
         pull_location = urlutils.relative_url(br.base, br.get_parent())
         self.assertIsSameRealPath(expected_pull_location, pull_location)
Beispiel #5
0
 def assertLocations(self, expected_locations):
     br, _ = branch.Branch.open_containing(self.working_dir)
     if not expected_locations:
         self.assertEquals(None, br.get_parent())
     else:
         expected_pull_location = expected_locations[0]
         pull_location = urlutils.relative_url(br.base, br.get_parent())
         self.assertIsSameRealPath(expected_pull_location, pull_location)
 def remote_path_from_transport(self, transport):
     # Strip the optional 'bzr+' prefix from transport so it will have the
     # same scheme as self.
     transport_base = transport.base
     if transport_base.startswith('bzr+'):
         transport_base = transport_base[4:]
     rel_url = urlutils.relative_url(self.base, transport_base)
     return urlutils.unquote(rel_url)
Beispiel #7
0
 def _remote_path(self, relpath):
     """After connecting, HTTP Transport only deals in relative URLs."""
     # Adjust the relpath based on which URL this smart transport is
     # connected to.
     http_base = urlutils.normalize_url(self.get_smart_medium().base)
     url = urlutils.join(self.base[len('bzr+'):], relpath)
     url = urlutils.normalize_url(url)
     return urlutils.relative_url(http_base, url)
Beispiel #8
0
 def _remote_path(self, relpath):
     """After connecting, HTTP Transport only deals in relative URLs."""
     # Adjust the relpath based on which URL this smart transport is
     # connected to.
     http_base = urlutils.normalize_url(self.get_smart_medium().base)
     url = urlutils.join(self.base[len('bzr+'):], relpath)
     url = urlutils.normalize_url(url)
     return urlutils.relative_url(http_base, url)
Beispiel #9
0
 def test_lock_write_on_readonly_transport(self):
     backing = self.get_readonly_transport()
     request = smart.branch.SmartServerBranchRequestLockWrite(backing)
     branch = self.make_branch('.')
     root = self.get_transport().clone('/')
     path = urlutils.relative_url(root.base, self.get_transport().base)
     response = request.execute(path)
     error_name, lock_str, why_str = response.args
     self.assertFalse(response.is_successful())
     self.assertEqual('LockFailed', error_name)
Beispiel #10
0
 def test_reference_parent(self):
     tree = self.make_branch_and_tree("tree")
     subtree = self.make_branch_and_tree("tree/subtree")
     subtree.set_root_id("subtree-id")
     try:
         tree.add_reference(subtree)
     except errors.UnsupportedOperation:
         raise tests.TestNotApplicable("Tree cannot hold references.")
     reference_parent = tree.branch.reference_parent(
         "subtree-id", urlutils.relative_url(tree.branch.user_url, subtree.branch.user_url)
     )
     self.assertEqual(subtree.branch.base, reference_parent.base)
 def test_reference_parent_accepts_possible_transports(self):
     tree = self.make_branch_and_tree('tree')
     subtree = self.make_branch_and_tree('tree/subtree')
     subtree.set_root_id('subtree-id')
     try:
         tree.add_reference(subtree)
     except errors.UnsupportedOperation:
         raise tests.TestNotApplicable('Tree cannot hold references.')
     reference_parent = tree.branch.reference_parent(
         'subtree-id',
         urlutils.relative_url(tree.branch.user_url,
                               subtree.branch.user_url),
         possible_transports=[subtree.bzrdir.root_transport])
 def test_reference_parent(self):
     tree = self.make_branch_and_tree('tree')
     subtree = self.make_branch_and_tree('tree/subtree')
     subtree.set_root_id('subtree-id')
     try:
         tree.add_reference(subtree)
     except errors.UnsupportedOperation:
         raise tests.TestNotApplicable('Tree cannot hold references.')
     reference_parent = tree.branch.reference_parent(
         'subtree-id',
         urlutils.relative_url(tree.branch.user_url,
                               subtree.branch.user_url))
     self.assertEqual(subtree.branch.base, reference_parent.base)
Beispiel #13
0
 def test_reference_parent_accepts_possible_transports(self):
     tree = self.make_branch_and_tree("tree")
     subtree = self.make_branch_and_tree("tree/subtree")
     subtree.set_root_id("subtree-id")
     try:
         tree.add_reference(subtree)
     except errors.UnsupportedOperation:
         raise tests.TestNotApplicable("Tree cannot hold references.")
     reference_parent = tree.branch.reference_parent(
         "subtree-id",
         urlutils.relative_url(tree.branch.user_url, subtree.branch.user_url),
         possible_transports=[subtree.bzrdir.root_transport],
     )
Beispiel #14
0
 def test_bind_clears_cached_master_branch(self):
     """b.bind clears any cached value of b.get_master_branch."""
     master1 = self.make_branch("master1")
     master2 = self.make_branch("master2")
     branch = self.make_branch("branch")
     try:
         branch.bind(master1)
     except errors.UpgradeRequired:
         raise tests.TestNotApplicable("Format does not support binding")
     self.addCleanup(branch.lock_write().unlock)
     self.assertNotEqual(None, branch.get_master_branch())
     branch.bind(master2)
     self.assertEqual(".", urlutils.relative_url(self.get_url("master2"), branch.get_master_branch().base))
Beispiel #15
0
 def apply(self, bzrdir, stacked_on_url):
     branch = bzrdir.open_branch()
     # it may be a path relative to the cwd or a url; the branch wants
     # a path relative to itself...
     on_url = urlutils.relative_url(branch.base,
         urlutils.normalize_url(stacked_on_url))
     branch.lock_write()
     try:
         branch.set_stacked_on_url(on_url)
         if not trace.is_quiet():
             ui.ui_factory.note(gettext(
                 "{0} is now stacked on {1}\n").format(
                   branch.base, branch.get_stacked_on_url()))
     finally:
         branch.unlock()
 def test_bind_clears_cached_master_branch(self):
     """b.bind clears any cached value of b.get_master_branch."""
     master1 = self.make_branch('master1')
     master2 = self.make_branch('master2')
     branch = self.make_branch('branch')
     try:
         branch.bind(master1)
     except errors.UpgradeRequired:
         raise tests.TestNotApplicable('Format does not support binding')
     self.addCleanup(branch.lock_write().unlock)
     self.assertNotEqual(None, branch.get_master_branch())
     branch.bind(master2)
     self.assertEqual(
         '.',
         urlutils.relative_url(self.get_url('master2'),
                               branch.get_master_branch().base))
Beispiel #17
0
def initialise(base, name, content_root, ui):
    """Create a mirrorset at transport, called name, mirroring content_root.

    :param base: The directory under which to put the mirror set
        configuration and metadata. A bzrlib.transport.Transport.
    :param name: The name of the mirrorset.
    :param content_root: The root of the content to be mirrored. A
        bzrlib.transport.Transport.
    :param ui: A l_mirror.ui.AbstractUI.
    :return: A MirrorSet object.
    """
    setdir = base.clone('.lmirror/sets/%s' % name)
    ui.output_log(8, 'l_mirror.mirrorset', 'Creating mirrorset %s at %s'
        % (name, base.base))
    setdir.create_prefix()
    # Ideally we'd use O_EXCL|O_CREAT, but trying a manual open is close enough
    # to race-free, as if it does race, they'll both be creating the same
    # content.
    try:
        MirrorSet(base, name, ui)
    except ValueError:
        pass
    else:
        raise ValueError("Already a set %r configured at %s" % (name,
            base.base))
    setdir.put_bytes('format', '1\n')
    content_relative = urlutils.relative_url(base.base, content_root.base[:-1])
    if not content_relative:
        content_relative = '.'
    setdir.put_bytes('set.conf', '[set]\ncontent_root = %s\n' % content_relative)
    metadir = base.clone('.lmirror/metadata/%s' % name)
    metadir.create_prefix()
    metadir.put_bytes('format', '1\n')
    metadir.put_bytes('metadata.conf', '[metadata]\nbasis = 0\nlatest = 0\ntimestamp = 0\nupdating = True\n')
    journaldir = metadir.clone('journals')
    journaldir.create_prefix()
    journaldir.put_bytes('0', journals.Journal().as_bytes())
    return MirrorSet(base, name, ui)
Beispiel #18
0
    def do(self, bzrdir_network_name, path, use_existing_dir, create_prefix,
           force_new_repo, stacked_on, stack_on_pwd, repo_format_name,
           make_working_trees, shared_repo):
        """Initialize a bzrdir at path as per
        BzrDirFormat.initialize_on_transport_ex.

        New in 1.16.  (Replaces BzrDirFormat.initialize_ex verb from 1.15).

        :return: return SuccessfulSmartServerResponse((repo_path, rich_root,
            tree_ref, external_lookup, repo_network_name,
            repo_bzrdir_network_name, bzrdir_format_network_name,
            NoneTrueFalse(stacking), final_stack, final_stack_pwd,
            repo_lock_token))
        """
        target_transport = self.transport_from_client_path(path)
        format = network_format_registry.get(bzrdir_network_name)
        use_existing_dir = self.parse_NoneTrueFalse(use_existing_dir)
        create_prefix = self.parse_NoneTrueFalse(create_prefix)
        force_new_repo = self.parse_NoneTrueFalse(force_new_repo)
        stacked_on = self.parse_NoneString(stacked_on)
        stack_on_pwd = self.parse_NoneString(stack_on_pwd)
        make_working_trees = self.parse_NoneTrueFalse(make_working_trees)
        shared_repo = self.parse_NoneTrueFalse(shared_repo)
        if stack_on_pwd == '.':
            stack_on_pwd = target_transport.base
        repo_format_name = self.parse_NoneString(repo_format_name)
        repo, bzrdir, stacking, repository_policy = \
            format.initialize_on_transport_ex(target_transport,
            use_existing_dir=use_existing_dir, create_prefix=create_prefix,
            force_new_repo=force_new_repo, stacked_on=stacked_on,
            stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
            make_working_trees=make_working_trees, shared_repo=shared_repo)
        if repo is None:
            repo_path = ''
            repo_name = ''
            rich_root = tree_ref = external_lookup = ''
            repo_bzrdir_name = ''
            final_stack = None
            final_stack_pwd = None
            repo_lock_token = ''
        else:
            repo_path = self._repo_relpath(bzrdir.root_transport, repo)
            if repo_path == '':
                repo_path = '.'
            rich_root, tree_ref, external_lookup = self._format_to_capabilities(
                repo._format)
            repo_name = repo._format.network_name()
            repo_bzrdir_name = repo.bzrdir._format.network_name()
            final_stack = repository_policy._stack_on
            final_stack_pwd = repository_policy._stack_on_pwd
            # It is returned locked, but we need to do the lock to get the lock
            # token.
            repo.unlock()
            repo_lock_token = repo.lock_write().repository_token or ''
            if repo_lock_token:
                repo.leave_lock_in_place()
            repo.unlock()
        final_stack = final_stack or ''
        final_stack_pwd = final_stack_pwd or ''

        # We want this to be relative to the bzrdir.
        if final_stack_pwd:
            final_stack_pwd = urlutils.relative_url(target_transport.base,
                                                    final_stack_pwd)

        # Can't meaningfully return a root path.
        if final_stack.startswith('/'):
            client_path = self._root_client_path + final_stack[1:]
            final_stack = urlutils.relative_url(self._root_client_path,
                                                client_path)
            final_stack_pwd = '.'

        return SuccessfulSmartServerResponse(
            (repo_path, rich_root, tree_ref, external_lookup, repo_name,
             repo_bzrdir_name, bzrdir._format.network_name(),
             self._serialize_NoneTrueFalse(stacking), final_stack,
             final_stack_pwd, repo_lock_token))
Beispiel #19
0
 def test(expected, base, other):
     result = urlutils.relative_url(base, other)
     self.assertEqual(expected, result)
Beispiel #20
0
 def test(expected, base, other):
     result = urlutils.relative_url(base, other)
     self.assertEqual(expected, result)
Beispiel #21
0
    def do(self, bzrdir_network_name, path, use_existing_dir, create_prefix,
        force_new_repo, stacked_on, stack_on_pwd, repo_format_name,
        make_working_trees, shared_repo):
        """Initialize a bzrdir at path as per
        BzrDirFormat.initialize_on_transport_ex.

        New in 1.16.  (Replaces BzrDirFormat.initialize_ex verb from 1.15).

        :return: return SuccessfulSmartServerResponse((repo_path, rich_root,
            tree_ref, external_lookup, repo_network_name,
            repo_bzrdir_network_name, bzrdir_format_network_name,
            NoneTrueFalse(stacking), final_stack, final_stack_pwd,
            repo_lock_token))
        """
        target_transport = self.transport_from_client_path(path)
        format = network_format_registry.get(bzrdir_network_name)
        use_existing_dir = self.parse_NoneTrueFalse(use_existing_dir)
        create_prefix = self.parse_NoneTrueFalse(create_prefix)
        force_new_repo = self.parse_NoneTrueFalse(force_new_repo)
        stacked_on = self.parse_NoneString(stacked_on)
        stack_on_pwd = self.parse_NoneString(stack_on_pwd)
        make_working_trees = self.parse_NoneTrueFalse(make_working_trees)
        shared_repo = self.parse_NoneTrueFalse(shared_repo)
        if stack_on_pwd == '.':
            stack_on_pwd = target_transport.base
        repo_format_name = self.parse_NoneString(repo_format_name)
        repo, bzrdir, stacking, repository_policy = \
            format.initialize_on_transport_ex(target_transport,
            use_existing_dir=use_existing_dir, create_prefix=create_prefix,
            force_new_repo=force_new_repo, stacked_on=stacked_on,
            stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
            make_working_trees=make_working_trees, shared_repo=shared_repo)
        if repo is None:
            repo_path = ''
            repo_name = ''
            rich_root = tree_ref = external_lookup = ''
            repo_bzrdir_name = ''
            final_stack = None
            final_stack_pwd = None
            repo_lock_token = ''
        else:
            repo_path = self._repo_relpath(bzrdir.root_transport, repo)
            if repo_path == '':
                repo_path = '.'
            rich_root, tree_ref, external_lookup = self._format_to_capabilities(
                repo._format)
            repo_name = repo._format.network_name()
            repo_bzrdir_name = repo.bzrdir._format.network_name()
            final_stack = repository_policy._stack_on
            final_stack_pwd = repository_policy._stack_on_pwd
            # It is returned locked, but we need to do the lock to get the lock
            # token.
            repo.unlock()
            repo_lock_token = repo.lock_write().repository_token or ''
            if repo_lock_token:
                repo.leave_lock_in_place()
            repo.unlock()
        final_stack = final_stack or ''
        final_stack_pwd = final_stack_pwd or ''

        # We want this to be relative to the bzrdir.
        if final_stack_pwd:
            final_stack_pwd = urlutils.relative_url(
                target_transport.base, final_stack_pwd)

        # Can't meaningfully return a root path.
        if final_stack.startswith('/'):
            client_path = self._root_client_path + final_stack[1:]
            final_stack = urlutils.relative_url(
                self._root_client_path, client_path)
            final_stack_pwd = '.'

        return SuccessfulSmartServerResponse((repo_path, rich_root, tree_ref,
            external_lookup, repo_name, repo_bzrdir_name,
            bzrdir._format.network_name(),
            self._serialize_NoneTrueFalse(stacking), final_stack,
            final_stack_pwd, repo_lock_token))