17
17
"""Server-side bzrdir related request implmentations."""
19
from __future__ import absolute_import
20
21
from bzrlib import branch, errors, repository, urlutils
21
22
from bzrlib.bzrdir import (
27
27
from bzrlib.controldir import (
121
121
return '/'.join(segments)
124
class SmartServerBzrDirRequestDestroyBranch(SmartServerRequestBzrDir):
126
def do_bzrdir_request(self, name=None):
127
"""Destroy the branch with the specified name.
130
:return: On success, 'ok'.
133
self._bzrdir.destroy_branch(name)
134
except errors.NotBranchError, e:
135
return FailedSmartServerResponse(('nobranch',))
136
return SuccessfulSmartServerResponse(('ok',))
139
class SmartServerBzrDirRequestHasWorkingTree(SmartServerRequestBzrDir):
141
def do_bzrdir_request(self, name=None):
142
"""Check whether there is a working tree present.
146
:return: If there is a working tree present, 'yes'.
149
if self._bzrdir.has_workingtree():
150
return SuccessfulSmartServerResponse(('yes', ))
152
return SuccessfulSmartServerResponse(('no', ))
155
class SmartServerBzrDirRequestDestroyRepository(SmartServerRequestBzrDir):
157
def do_bzrdir_request(self, name=None):
158
"""Destroy the repository.
162
:return: On success, 'ok'.
165
self._bzrdir.destroy_repository()
166
except errors.NoRepositoryPresent, e:
167
return FailedSmartServerResponse(('norepository',))
168
return SuccessfulSmartServerResponse(('ok',))
124
171
class SmartServerBzrDirRequestCloningMetaDir(SmartServerRequestBzrDir):
126
173
def do_bzrdir_request(self, require_stacking):
150
197
control_format = self._bzrdir.cloning_metadir(
151
198
require_stacking=require_stacking)
152
199
control_name = control_format.network_name()
153
# XXX: There should be a method that tells us that the format does/does
154
# not have subformats.
155
if isinstance(control_format, BzrDirMetaFormat1):
200
if not control_format.fixed_components:
156
201
branch_name = ('branch',
157
202
control_format.get_branch_format().network_name())
158
203
repository_name = control_format.repository_format.network_name()
212
class SmartServerBzrDirRequestCheckoutMetaDir(SmartServerRequestBzrDir):
213
"""Get the format to use for checkouts.
217
:return: on success, a 3-tuple of network names for (control,
218
repository, branch) directories, where '' signifies "not present".
219
If this BzrDir contains a branch reference then this will fail with
220
BranchReference; clients should resolve branch references before
221
calling this RPC (they should not try to create a checkout of a
225
def do_bzrdir_request(self):
227
branch_ref = self._bzrdir.get_branch_reference()
228
except errors.NotBranchError:
230
if branch_ref is not None:
231
# The server shouldn't try to resolve references, and it quite
232
# possibly can't reach them anyway. The client needs to resolve
233
# the branch reference to determine the cloning_metadir.
234
return FailedSmartServerResponse(('BranchReference',))
235
control_format = self._bzrdir.checkout_metadir()
236
control_name = control_format.network_name()
237
if not control_format.fixed_components:
238
branch_name = control_format.get_branch_format().network_name()
239
repo_name = control_format.repository_format.network_name()
243
return SuccessfulSmartServerResponse(
244
(control_name, repo_name, branch_name))
167
247
class SmartServerRequestCreateBranch(SmartServerRequestBzrDir):
169
249
def do(self, path, network_name):