Exemplo n.º 1
0
 def do(self, path, *args):
     """Open a BzrDir at path, and return `self.do_bzrdir_request(*args)`."""
     try:
         self._bzrdir = BzrDir.open_from_transport(
             self.transport_from_client_path(path))
     except errors.NotBranchError, e:
         return FailedSmartServerResponse(('nobranch',))
Exemplo n.º 2
0
    def do(self, path, network_name):
        """Create a branch in the bzr dir at path.

        This operates precisely like 'bzrdir.create_branch'.

        If a bzrdir is not present, an exception is propogated
        rather than 'no branch' because these are different conditions (and
        this method should only be called after establishing that a bzr dir
        exists anyway).

        This is the initial version of this method introduced to the smart
        server for 1.13.

        :param path: The path to the bzrdir.
        :param network_name: The network name of the branch type to create.
        :return: ('ok', branch_format, repo_path, rich_root, tree_ref,
            external_lookup, repo_format)
        """
        bzrdir = BzrDir.open_from_transport(
            self.transport_from_client_path(path))
        format = branch.network_format_registry.get(network_name)
        bzrdir.branch_format = format
        result = format.initialize(bzrdir, name="")
        rich_root, tree_ref, external_lookup = self._format_to_capabilities(
            result.repository._format)
        branch_format = result._format.network_name()
        repo_format = result.repository._format.network_name()
        repo_path = self._repo_relpath(bzrdir.root_transport,
            result.repository)
        # branch format, repo relpath, rich_root, tree_ref, external_lookup,
        # repo_network_name
        return SuccessfulSmartServerResponse(('ok', branch_format, repo_path,
            rich_root, tree_ref, external_lookup, repo_format))
Exemplo n.º 3
0
 def _find(self, path):
     """try to find a repository from path upwards
     
     This operates precisely like 'bzrdir.find_repository'.
     
     :return: (relpath, rich_root, tree_ref, external_lookup) flags. All are
         strings, relpath is a / prefixed path, and the other three are
         either 'yes' or 'no'.
     :raises errors.NoRepositoryPresent: When there is no repository
         present.
     """
     bzrdir = BzrDir.open_from_transport(
         self.transport_from_client_path(path))
     repository = bzrdir.find_repository()
     # the relpath of the bzrdir in the found repository gives us the
     # path segments to pop-out.
     relpath = repository.bzrdir.root_transport.relpath(
         bzrdir.root_transport.base)
     if len(relpath):
         segments = ['..'] * len(relpath.split('/'))
     else:
         segments = []
     rich_root = self._boolean_to_yes_no(repository.supports_rich_root())
     tree_ref = self._boolean_to_yes_no(
         repository._format.supports_tree_reference)
     external_lookup = self._boolean_to_yes_no(
         repository._format.supports_external_lookups)
     return '/'.join(segments), rich_root, tree_ref, external_lookup
Exemplo n.º 4
0
 def do(self, path, *args):
     """Open a BzrDir at path, and return `self.do_bzrdir_request(*args)`."""
     try:
         self._bzrdir = BzrDir.open_from_transport(
             self.transport_from_client_path(path))
     except errors.NotBranchError, e:
         return FailedSmartServerResponse(('nobranch', ))
Exemplo n.º 5
0
    def do(self, path, network_name, shared):
        """Create a repository in the bzr dir at path.

        This operates precisely like 'bzrdir.create_repository'.

        If a bzrdir is not present, an exception is propagated
        rather than 'no branch' because these are different conditions (and
        this method should only be called after establishing that a bzr dir
        exists anyway).

        This is the initial version of this method introduced to the smart
        server for 1.13.

        :param path: The path to the bzrdir.
        :param network_name: The network name of the repository type to create.
        :param shared: The value to pass create_repository for the shared
            parameter.
        :return: (ok, rich_root, tree_ref, external_lookup, network_name)
        """
        bzrdir = BzrDir.open_from_transport(
            self.transport_from_client_path(path))
        shared = shared == 'True'
        format = repository.network_format_registry.get(network_name)
        bzrdir.repository_format = format
        result = format.initialize(bzrdir, shared=shared)
        rich_root, tree_ref, external_lookup = self._format_to_capabilities(
            result._format)
        return SuccessfulSmartServerResponse(('ok', rich_root, tree_ref,
            external_lookup, result._format.network_name()))
Exemplo n.º 6
0
 def _find(self, path):
     """try to find a repository from path upwards
     
     This operates precisely like 'bzrdir.find_repository'.
     
     :return: (relpath, rich_root, tree_ref, external_lookup) flags. All are
         strings, relpath is a / prefixed path, and the other three are
         either 'yes' or 'no'.
     :raises errors.NoRepositoryPresent: When there is no repository
         present.
     """
     bzrdir = BzrDir.open_from_transport(
         self.transport_from_client_path(path))
     repository = bzrdir.find_repository()
     # the relpath of the bzrdir in the found repository gives us the 
     # path segments to pop-out.
     relpath = repository.bzrdir.root_transport.relpath(
         bzrdir.root_transport.base)
     if len(relpath):
         segments = ['..'] * len(relpath.split('/'))
     else:
         segments = []
     rich_root = self._boolean_to_yes_no(repository.supports_rich_root())
     tree_ref = self._boolean_to_yes_no(
         repository._format.supports_tree_reference)
     external_lookup = self._boolean_to_yes_no(
         repository._format.supports_external_lookups)
     return '/'.join(segments), rich_root, tree_ref, external_lookup
Exemplo n.º 7
0
    def do(self, path, network_name, shared):
        """Create a repository in the bzr dir at path.

        This operates precisely like 'bzrdir.create_repository'.

        If a bzrdir is not present, an exception is propagated
        rather than 'no branch' because these are different conditions (and
        this method should only be called after establishing that a bzr dir
        exists anyway).

        This is the initial version of this method introduced to the smart
        server for 1.13.

        :param path: The path to the bzrdir.
        :param network_name: The network name of the repository type to create.
        :param shared: The value to pass create_repository for the shared
            parameter.
        :return: (ok, rich_root, tree_ref, external_lookup, network_name)
        """
        bzrdir = BzrDir.open_from_transport(
            self.transport_from_client_path(path))
        shared = shared == 'True'
        format = repository.network_format_registry.get(network_name)
        bzrdir.repository_format = format
        result = format.initialize(bzrdir, shared=shared)
        rich_root, tree_ref, external_lookup = self._format_to_capabilities(
            result._format)
        return SuccessfulSmartServerResponse(
            ('ok', rich_root, tree_ref, external_lookup,
             result._format.network_name()))
Exemplo n.º 8
0
    def do(self, path, network_name):
        """Create a branch in the bzr dir at path.

        This operates precisely like 'bzrdir.create_branch'.

        If a bzrdir is not present, an exception is propogated
        rather than 'no branch' because these are different conditions (and
        this method should only be called after establishing that a bzr dir
        exists anyway).

        This is the initial version of this method introduced to the smart
        server for 1.13.

        :param path: The path to the bzrdir.
        :param network_name: The network name of the branch type to create.
        :return: ('ok', branch_format, repo_path, rich_root, tree_ref,
            external_lookup, repo_format)
        """
        bzrdir = BzrDir.open_from_transport(
            self.transport_from_client_path(path))
        format = branch.network_format_registry.get(network_name)
        bzrdir.branch_format = format
        result = format.initialize(bzrdir, name="")
        rich_root, tree_ref, external_lookup = self._format_to_capabilities(
            result.repository._format)
        branch_format = result._format.network_name()
        repo_format = result.repository._format.network_name()
        repo_path = self._repo_relpath(bzrdir.root_transport,
                                       result.repository)
        # branch format, repo relpath, rich_root, tree_ref, external_lookup,
        # repo_network_name
        return SuccessfulSmartServerResponse(
            ('ok', branch_format, repo_path, rich_root, tree_ref,
             external_lookup, repo_format))
Exemplo n.º 9
0
    def test_bzr_serve_inet_readwrite(self):
        # Make a branch
        self.make_branch('.')

        process, transport = self.start_server_inet(['--allow-writes'])

        # We get a working branch
        branch = BzrDir.open_from_transport(transport).open_branch()
        self.make_read_requests(branch)
        self.assertInetServerShutsdownCleanly(process)
Exemplo n.º 10
0
    def test_bzr_serve_inet_readwrite(self):
        # Make a branch
        self.make_branch('.')

        process, transport = self.start_server_inet(['--allow-writes'])

        # We get a working branch
        branch = BzrDir.open_from_transport(transport).open_branch()
        self.make_read_requests(branch)
        self.assertInetServerShutsdownCleanly(process)
Exemplo n.º 11
0
 def test_commit_readonly_checkout(self):
     # https://bugs.edge.launchpad.net/bzr/+bug/129701
     # "UnlockableTransport error trying to commit in checkout of readonly
     # branch"
     self.make_branch('master')
     master = BzrDir.open_from_transport(
         self.get_readonly_transport('master')).open_branch()
     master.create_checkout('checkout')
     out, err = self.run_bzr(['commit', '--unchanged', '-mfoo', 'checkout'],
                             retcode=3)
     self.assertContainsRe(err,
                           r'^bzr: ERROR: Cannot lock.*readonly transport')
Exemplo n.º 12
0
 def test_commit_readonly_checkout(self):
     # https://bugs.edge.launchpad.net/bzr/+bug/129701
     # "UnlockableTransport error trying to commit in checkout of readonly
     # branch"
     self.make_branch('master')
     master = BzrDir.open_from_transport(
         self.get_readonly_transport('master')).open_branch()
     master.create_checkout('checkout')
     out, err = self.run_bzr(['commit', '--unchanged', '-mfoo', 'checkout'],
         retcode=3)
     self.assertContainsRe(err,
         r'^bzr: ERROR: Cannot lock.*readonly transport')
Exemplo n.º 13
0
 def test_can_open_product_control_dir(self):
     # The stacking policy lives in a bzrdir in the product directory.
     # Bazaar needs to be able to open this bzrdir.
     product = self.factory.makeProduct()
     self.factory.enableDefaultStackingForProduct(product)
     transport = self.getTransport().clone(
         '~%s/%s' % (self.requester.name, product.name))
     found_bzrdir = BzrDir.open_from_transport(transport)
     # We really just want to test that the above line doesn't raise an
     # exception. However, we'll also check that we get the bzrdir that we
     # expected.
     expected_url = transport.clone('.bzr').base
     self.assertEqual(expected_url, found_bzrdir.transport.base)
Exemplo n.º 14
0
 def test_can_open_product_control_dir(self):
     # The stacking policy lives in a bzrdir in the product directory.
     # Bazaar needs to be able to open this bzrdir.
     product = self.factory.makeProduct()
     self.factory.enableDefaultStackingForProduct(product)
     transport = self.getTransport().clone(
         '~%s/%s' % (self.requester.name, product.name))
     found_bzrdir = BzrDir.open_from_transport(transport)
     # We really just want to test that the above line doesn't raise an
     # exception. However, we'll also check that we get the bzrdir that we
     # expected.
     expected_url = transport.clone('.bzr').base
     self.assertEqual(expected_url, found_bzrdir.transport.base)
Exemplo n.º 15
0
 def do(self, path):
     """try to open a branch at path and return ok/nobranch.
     
     If a bzrdir is not present, an exception is propogated
     rather than 'no branch' because these are different conditions.
     """
     bzrdir = BzrDir.open_from_transport(
         self.transport_from_client_path(path))
     try:
         reference_url = bzrdir.get_branch_reference()
         if reference_url is None:
             return SuccessfulSmartServerResponse(('ok', ''))
         else:
             return SuccessfulSmartServerResponse(('ok', reference_url))
     except errors.NotBranchError:
         return FailedSmartServerResponse(('nobranch', ))
Exemplo n.º 16
0
 def got_path_info((transport_type, data, trailing_path)):
     if transport_type != BRANCH_TRANSPORT:
         raise NotABranchPath(virtual_url_fragment)
     transport, _ = self._transport_dispatch.makeTransport((transport_type, data, trailing_path))
     if jail_info.transports:
         jail_info.transports.append(transport)
     try:
         branch = BzrDir.open_from_transport(transport).open_branch(ignore_fallbacks=True)
         info = get_branch_info(branch)
         info["stacked_on_url"] = self._normalize_stacked_on_url(branch)
     finally:
         if jail_info.transports:
             jail_info.transports.remove(transport)
     if info["stacked_on_url"] is None:
         info["stacked_on_url"] = ""
     return self._branchfs_client.branchChanged(data["id"], **info)
Exemplo n.º 17
0
 def do(self, path):
     """try to open a branch at path and return ok/nobranch.
     
     If a bzrdir is not present, an exception is propogated
     rather than 'no branch' because these are different conditions.
     """
     bzrdir = BzrDir.open_from_transport(
         self.transport_from_client_path(path))
     try:
         reference_url = bzrdir.get_branch_reference()
         if reference_url is None:
             return SuccessfulSmartServerResponse(('ok', ''))
         else:
             return SuccessfulSmartServerResponse(('ok', reference_url))
     except errors.NotBranchError:
         return FailedSmartServerResponse(('nobranch', ))
Exemplo n.º 18
0
    def do(self, path, *args):
        """Execute a request for a branch at path.
    
        All Branch requests take a path to the branch as their first argument.

        If the branch is a branch reference, NotBranchError is raised.

        :param path: The path for the repository as received from the
            client.
        :return: A SmartServerResponse from self.do_with_branch().
        """
        transport = self.transport_from_client_path(path)
        bzrdir = BzrDir.open_from_transport(transport)
        if bzrdir.get_branch_reference() is not None:
            raise errors.NotBranchError(transport.base)
        branch = bzrdir.open_branch()
        return self.do_with_branch(branch, *args)
Exemplo n.º 19
0
    def do(self, path, *args):
        """Execute a request for a branch at path.
    
        All Branch requests take a path to the branch as their first argument.

        If the branch is a branch reference, NotBranchError is raised.

        :param path: The path for the repository as received from the
            client.
        :return: A SmartServerResponse from self.do_with_branch().
        """
        transport = self.transport_from_client_path(path)
        bzrdir = BzrDir.open_from_transport(transport)
        if bzrdir.get_branch_reference() is not None:
            raise errors.NotBranchError(transport.base)
        branch = bzrdir.open_branch()
        return self.do_with_branch(branch, *args)
Exemplo n.º 20
0
    def do(self, path, *args):
        """Execute a repository request.
        
        All Repository requests take a path to the repository as their first
        argument.  The repository must be at the exact path given by the
        client - no searching is done.

        The actual logic is delegated to self.do_repository_request.

        :param client_path: The path for the repository as received from the
            client.
        :return: A SmartServerResponse from self.do_repository_request().
        """
        transport = self.transport_from_client_path(path)
        bzrdir = BzrDir.open_from_transport(transport)
        # Save the repository for use with do_body.
        self._repository = bzrdir.open_repository()
        return self.do_repository_request(self._repository, *args)
Exemplo n.º 21
0
    def do(self, path, *args):
        """Execute a repository request.

        All Repository requests take a path to the repository as their first
        argument.  The repository must be at the exact path given by the
        client - no searching is done.

        The actual logic is delegated to self.do_repository_request.

        :param client_path: The path for the repository as received from the
            client.
        :return: A SmartServerResponse from self.do_repository_request().
        """
        transport = self.transport_from_client_path(path)
        bzrdir = BzrDir.open_from_transport(transport)
        # Save the repository for use with do_body.
        self._repository = bzrdir.open_repository()
        return self.do_repository_request(self._repository, *args)
Exemplo n.º 22
0
 def got_path_info((transport_type, data, trailing_path)):
     if transport_type != BRANCH_TRANSPORT:
         raise NotABranchPath(virtual_url_fragment)
     transport, _ = self._transport_dispatch.makeTransport(
         (transport_type, data, trailing_path))
     if jail_info.transports:
         jail_info.transports.append(transport)
     try:
         branch = BzrDir.open_from_transport(transport).open_branch(
             ignore_fallbacks=True)
         info = get_branch_info(branch)
         info['stacked_on_url'] = (
             self._normalize_stacked_on_url(branch))
     finally:
         if jail_info.transports:
             jail_info.transports.remove(transport)
     if info['stacked_on_url'] is None:
         info['stacked_on_url'] = ''
     return self._branchfs_client.branchChanged(data['id'], **info)
Exemplo n.º 23
0
    def pull(self,
             db_branch_id,
             target_path,
             required_format,
             needs_tree=False,
             stacked_on_url=None):
        """Pull down the Bazaar branch of an import to `target_path`.

        :return: A Bazaar branch for the code import corresponding to the
            database branch with id `db_branch_id`.
        """
        remote_url = self._getMirrorURL(db_branch_id)
        try:
            remote_bzr_dir = BzrDir.open(remote_url)
        except NotBranchError:
            local_branch = BzrDir.create_branch_and_repo(
                target_path, format=required_format)
            if needs_tree:
                local_branch.bzrdir.create_workingtree()
            if stacked_on_url:
                local_branch.set_stacked_on_url(stacked_on_url)
            return local_branch
        # The proper thing to do here would be to call
        # "remote_bzr_dir.sprout()".  But 2a fetch slowly checks which
        # revisions are in the ancestry of the tip of the remote branch, which
        # we strictly don't care about, so we just copy the whole thing down
        # at the vfs level.
        control_dir = remote_bzr_dir.root_transport.relpath(
            remote_bzr_dir.transport.abspath('.'))
        target = get_transport_from_path(target_path)
        target_control = target.clone(control_dir)
        target_control.create_prefix()
        remote_bzr_dir.transport.copy_tree_to_transport(target_control)
        local_bzr_dir = BzrDir.open_from_transport(target)
        if local_bzr_dir.needs_format_conversion(format=required_format):
            try:
                local_bzr_dir.root_transport.delete_tree('backup.bzr')
            except NoSuchFile:
                pass
            upgrade(target_path, required_format, clean_up=True)
        if needs_tree:
            local_bzr_dir.create_workingtree()
        return local_bzr_dir.open_branch()
Exemplo n.º 24
0
    def _find(self, path):
        """try to find a repository from path upwards

        This operates precisely like 'bzrdir.find_repository'.

        :return: (relpath, rich_root, tree_ref, external_lookup, network_name).
            All are strings, relpath is a / prefixed path, the next three are
            either 'yes' or 'no', and the last is a repository format network
            name.
        :raises errors.NoRepositoryPresent: When there is no repository
            present.
        """
        bzrdir = BzrDir.open_from_transport(
            self.transport_from_client_path(path))
        repository = bzrdir.find_repository()
        path = self._repo_relpath(bzrdir.root_transport, repository)
        rich_root, tree_ref, external_lookup = self._format_to_capabilities(
            repository._format)
        network_name = repository._format.network_name()
        return path, rich_root, tree_ref, external_lookup, network_name
Exemplo n.º 25
0
    def _find(self, path):
        """try to find a repository from path upwards

        This operates precisely like 'bzrdir.find_repository'.

        :return: (relpath, rich_root, tree_ref, external_lookup, network_name).
            All are strings, relpath is a / prefixed path, the next three are
            either 'yes' or 'no', and the last is a repository format network
            name.
        :raises errors.NoRepositoryPresent: When there is no repository
            present.
        """
        bzrdir = BzrDir.open_from_transport(
            self.transport_from_client_path(path))
        repository = bzrdir.find_repository()
        path = self._repo_relpath(bzrdir.root_transport, repository)
        rich_root, tree_ref, external_lookup = self._format_to_capabilities(
            repository._format)
        network_name = repository._format.network_name()
        return path, rich_root, tree_ref, external_lookup, network_name
Exemplo n.º 26
0
    def do(self, path):
        """Is there a BzrDir present, and if so does it have a working tree?

        New in 2.1.
        """
        try:
            t = self.transport_from_client_path(path)
        except errors.PathNotChild:
            # The client is trying to ask about a path that they have no access
            # to.
            return SuccessfulSmartServerResponse(('no', ))
        try:
            bd = BzrDir.open_from_transport(t)
        except errors.NotBranchError:
            answer = ('no', )
        else:
            answer = ('yes', )
            if bd.has_workingtree():
                answer += ('yes', )
            else:
                answer += ('no', )
        return SuccessfulSmartServerResponse(answer)
Exemplo n.º 27
0
    def do(self, path):
        """Is there a BzrDir present, and if so does it have a working tree?

        New in 2.1.
        """
        try:
            t = self.transport_from_client_path(path)
        except errors.PathNotChild:
            # The client is trying to ask about a path that they have no access
            # to.
            return SuccessfulSmartServerResponse(('no',))
        try:
            bd = BzrDir.open_from_transport(t)
        except errors.NotBranchError:
            answer = ('no',)
        else:
            answer = ('yes',)
            if bd.has_workingtree():
                answer += ('yes',)
            else:
                answer += ('no',)
        return SuccessfulSmartServerResponse(answer)
Exemplo n.º 28
0
    def pull(self, db_branch_id, target_path, required_format,
             needs_tree=False, stacked_on_url=None):
        """Pull down the Bazaar branch of an import to `target_path`.

        :return: A Bazaar branch for the code import corresponding to the
            database branch with id `db_branch_id`.
        """
        remote_url = self._getMirrorURL(db_branch_id)
        try:
            remote_bzr_dir = BzrDir.open(remote_url)
        except NotBranchError:
            local_branch = BzrDir.create_branch_and_repo(
                target_path, format=required_format)
            if needs_tree:
                local_branch.bzrdir.create_workingtree()
            if stacked_on_url:
                local_branch.set_stacked_on_url(stacked_on_url)
            return local_branch
        # The proper thing to do here would be to call
        # "remote_bzr_dir.sprout()".  But 2a fetch slowly checks which
        # revisions are in the ancestry of the tip of the remote branch, which
        # we strictly don't care about, so we just copy the whole thing down
        # at the vfs level.
        control_dir = remote_bzr_dir.root_transport.relpath(
            remote_bzr_dir.transport.abspath('.'))
        target = get_transport_from_path(target_path)
        target_control = target.clone(control_dir)
        target_control.create_prefix()
        remote_bzr_dir.transport.copy_tree_to_transport(target_control)
        local_bzr_dir = BzrDir.open_from_transport(target)
        if local_bzr_dir.needs_format_conversion(format=required_format):
            try:
                local_bzr_dir.root_transport.delete_tree('backup.bzr')
            except NoSuchFile:
                pass
            upgrade(target_path, required_format, clean_up=True)
        if needs_tree:
            local_bzr_dir.create_workingtree()
        return local_bzr_dir.open_branch()
 def t():
     BzrDir.open_from_transport(transport)
     thread_result.append('ok')
Exemplo n.º 30
0
 def readonly_repository(self, relpath):
     return BzrDir.open_from_transport(
         self.get_readonly_transport(relpath)).open_repository()
Exemplo n.º 31
0
 def t():
     BzrDir.open_from_transport(transport)
     thread_result.append('ok')