17
17
"""Server-side bzrdir related request implmentations."""
19
from __future__ import absolute_import
20
from bzrlib import branch, errors, repository, urlutils
21
28
from bzrlib.bzrdir import (
33
from bzrlib.controldir import (
25
34
network_format_registry,
27
36
from bzrlib.smart.request import (
44
53
# clients that don't anticipate errors from this method.
47
default_format = BzrDirFormat.get_default_format()
48
real_bzrdir = default_format.open(t, _found=True)
56
bzr_prober = BzrProber()
50
real_bzrdir._format.probe_transport(t)
58
bzr_prober.probe_transport(t)
51
59
except (errors.NotBranchError, errors.UnknownFormatError):
84
92
class SmartServerRequestBzrDir(SmartServerRequest):
86
94
def do(self, path, *args):
87
"""Open a BzrDir at path, and return self.do_bzrdir_request(*args)."""
95
"""Open a BzrDir at path, and return `self.do_bzrdir_request(*args)`."""
89
97
self._bzrdir = BzrDir.open_from_transport(
90
98
self.transport_from_client_path(path))
119
127
return '/'.join(segments)
130
class SmartServerBzrDirRequestDestroyBranch(SmartServerRequestBzrDir):
132
def do_bzrdir_request(self, name=None):
133
"""Destroy the branch with the specified name.
136
:return: On success, 'ok'.
139
self._bzrdir.destroy_branch(name)
140
except errors.NotBranchError, e:
141
return FailedSmartServerResponse(('nobranch',))
142
return SuccessfulSmartServerResponse(('ok',))
145
class SmartServerBzrDirRequestHasWorkingTree(SmartServerRequestBzrDir):
147
def do_bzrdir_request(self, name=None):
148
"""Check whether there is a working tree present.
152
:return: If there is a working tree present, 'yes'.
155
if self._bzrdir.has_workingtree():
156
return SuccessfulSmartServerResponse(('yes', ))
158
return SuccessfulSmartServerResponse(('no', ))
161
class SmartServerBzrDirRequestDestroyRepository(SmartServerRequestBzrDir):
163
def do_bzrdir_request(self, name=None):
164
"""Destroy the repository.
168
:return: On success, 'ok'.
171
self._bzrdir.destroy_repository()
172
except errors.NoRepositoryPresent, e:
173
return FailedSmartServerResponse(('norepository',))
174
return SuccessfulSmartServerResponse(('ok',))
122
177
class SmartServerBzrDirRequestCloningMetaDir(SmartServerRequestBzrDir):
124
179
def do_bzrdir_request(self, require_stacking):
148
203
control_format = self._bzrdir.cloning_metadir(
149
204
require_stacking=require_stacking)
150
205
control_name = control_format.network_name()
151
# XXX: There should be a method that tells us that the format does/does
152
# not have subformats.
153
if isinstance(control_format, BzrDirMetaFormat1):
206
if not control_format.fixed_components:
154
207
branch_name = ('branch',
155
208
control_format.get_branch_format().network_name())
156
209
repository_name = control_format.repository_format.network_name()
218
class SmartServerBzrDirRequestCheckoutMetaDir(SmartServerRequestBzrDir):
219
"""Get the format to use for checkouts.
223
:return: on success, a 3-tuple of network names for (control,
224
repository, branch) directories, where '' signifies "not present".
225
If this BzrDir contains a branch reference then this will fail with
226
BranchReference; clients should resolve branch references before
227
calling this RPC (they should not try to create a checkout of a
231
def do_bzrdir_request(self):
233
branch_ref = self._bzrdir.get_branch_reference()
234
except errors.NotBranchError:
236
if branch_ref is not None:
237
# The server shouldn't try to resolve references, and it quite
238
# possibly can't reach them anyway. The client needs to resolve
239
# the branch reference to determine the cloning_metadir.
240
return FailedSmartServerResponse(('BranchReference',))
241
control_format = self._bzrdir.checkout_metadir()
242
control_name = control_format.network_name()
243
if not control_format.fixed_components:
244
branch_name = control_format.get_branch_format().network_name()
245
repo_name = control_format.repository_format.network_name()
249
return SuccessfulSmartServerResponse(
250
(control_name, repo_name, branch_name))
165
253
class SmartServerRequestCreateBranch(SmartServerRequestBzrDir):
167
255
def do(self, path, network_name):
180
268
:param path: The path to the bzrdir.
181
269
:param network_name: The network name of the branch type to create.
182
:return: (ok, network_name)
270
:return: ('ok', branch_format, repo_path, rich_root, tree_ref,
271
external_lookup, repo_format)
184
273
bzrdir = BzrDir.open_from_transport(
185
274
self.transport_from_client_path(path))
186
275
format = branch.network_format_registry.get(network_name)
187
276
bzrdir.branch_format = format
188
result = format.initialize(bzrdir)
277
result = format.initialize(bzrdir, name="")
189
278
rich_root, tree_ref, external_lookup = self._format_to_capabilities(
190
279
result.repository._format)
191
280
branch_format = result._format.network_name()
342
431
return SuccessfulSmartServerResponse((), content)
434
class SmartServerBzrDirRequestGetBranches(SmartServerRequestBzrDir):
436
def do_bzrdir_request(self):
437
"""Get the branches in a control directory.
439
The body is a bencoded dictionary, with values similar to the return
440
value of the open branch request.
442
branches = self._bzrdir.get_branches()
444
for name, b in branches.iteritems():
447
ret[name] = ("branch", b._format.network_name())
448
return SuccessfulSmartServerResponse(
449
("success", ), bencode.bencode(ret))
345
452
class SmartServerRequestInitializeBzrDir(SmartServerRequest):
347
454
def do(self, path):