~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/bzrdir.py

  • Committer: Robert Collins
  • Date: 2009-02-24 05:37:17 UTC
  • mto: This revision was merged to the branch mainline in revision 4038.
  • Revision ID: robertc@robertcollins.net-20090224053717-sau62hnxgo2f1pzr
Create and use a RPC call to create branches on bzr servers rather than using VFS calls.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Server-side bzrdir related request implmentations."""
18
18
 
19
19
 
20
 
from bzrlib import errors
 
20
from bzrlib import branch, errors, repository
21
21
from bzrlib.bzrdir import BzrDir, BzrDirFormat
22
22
from bzrlib.smart.request import (
23
23
    FailedSmartServerResponse,
24
24
    SmartServerRequest,
25
25
    SuccessfulSmartServerResponse,
26
26
    )
27
 
from bzrlib.repository import network_format_registry
28
27
 
29
28
 
30
29
class SmartServerRequestOpenBzrDir(SmartServerRequest):
68
67
            repo_format.supports_external_lookups)
69
68
        return rich_root, tree_ref, external_lookup
70
69
 
 
70
    def _repo_relpath(self, current_transport, repository):
 
71
        """Get the relative path for repository from current_transport."""
 
72
        # the relpath of the bzrdir in the found repository gives us the
 
73
        # path segments to pop-out.
 
74
        relpath = repository.bzrdir.root_transport.relpath(
 
75
            current_transport.base)
 
76
        if len(relpath):
 
77
            segments = ['..'] * len(relpath.split('/'))
 
78
        else:
 
79
            segments = []
 
80
        return '/'.join(segments)
 
81
 
 
82
 
 
83
class SmartServerRequestCreateBranch(SmartServerRequestBzrDir):
 
84
 
 
85
    def do(self, path, network_name):
 
86
        """Create a branch in the bzr dir at path.
 
87
 
 
88
        This operates precisely like 'bzrdir.create_branch'.
 
89
 
 
90
        If a bzrdir is not present, an exception is propogated
 
91
        rather than 'no branch' because these are different conditions (and
 
92
        this method should only be called after establishing that a bzr dir
 
93
        exists anyway).
 
94
 
 
95
        This is the initial version of this method introduced to the smart
 
96
        server for 1.13.
 
97
 
 
98
        :param path: The path to the bzrdir.
 
99
        :param network_name: The network name of the branch type to create.
 
100
        :return: (ok, network_name)
 
101
        """
 
102
        bzrdir = BzrDir.open_from_transport(
 
103
            self.transport_from_client_path(path))
 
104
        format = branch.network_format_registry.get(network_name)
 
105
        bzrdir.branch_format = format
 
106
        result = format.initialize(bzrdir)
 
107
        rich_root, tree_ref, external_lookup = self._format_to_capabilities(
 
108
            result.repository._format)
 
109
        branch_format = result._format.network_name()
 
110
        repo_format = result.repository._format.network_name()
 
111
        repo_path = self._repo_relpath(bzrdir.root_transport,
 
112
            result.repository)
 
113
        # branch format, repo relpath, rich_root, tree_ref, external_lookup,
 
114
        # repo_network_name
 
115
        return SuccessfulSmartServerResponse(('ok', branch_format, repo_path,
 
116
            rich_root, tree_ref, external_lookup, repo_format))
 
117
 
71
118
 
72
119
class SmartServerRequestCreateRepository(SmartServerRequestBzrDir):
73
120
 
93
140
        bzrdir = BzrDir.open_from_transport(
94
141
            self.transport_from_client_path(path))
95
142
        shared = shared == 'True'
96
 
        format = network_format_registry.get(network_name)
 
143
        format = repository.network_format_registry.get(network_name)
97
144
        bzrdir.repository_format = format
98
145
        result = format.initialize(bzrdir, shared=shared)
99
146
        rich_root, tree_ref, external_lookup = self._format_to_capabilities(
118
165
        bzrdir = BzrDir.open_from_transport(
119
166
            self.transport_from_client_path(path))
120
167
        repository = bzrdir.find_repository()
121
 
        # the relpath of the bzrdir in the found repository gives us the 
122
 
        # path segments to pop-out.
123
 
        relpath = repository.bzrdir.root_transport.relpath(
124
 
            bzrdir.root_transport.base)
125
 
        if len(relpath):
126
 
            segments = ['..'] * len(relpath.split('/'))
127
 
        else:
128
 
            segments = []
 
168
        path = self._repo_relpath(bzrdir.root_transport, repository)
129
169
        rich_root, tree_ref, external_lookup = self._format_to_capabilities(
130
170
            repository._format)
131
 
        return '/'.join(segments), rich_root, tree_ref, external_lookup
 
171
        return path, rich_root, tree_ref, external_lookup
132
172
 
133
173
 
134
174
class SmartServerRequestFindRepositoryV1(SmartServerRequestFindRepository):