13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
17
"""Server-side bzrdir related request implmentations."""
56
56
def do(self, path, *args):
57
57
"""Open a BzrDir at path, and return self.do_bzrdir_request(*args)."""
59
self._bzrdir = BzrDir.open_from_transport(
60
self.transport_from_client_path(path))
61
except errors.NotBranchError:
62
return FailedSmartServerResponse(('nobranch', ))
58
self._bzrdir = BzrDir.open_from_transport(
59
self.transport_from_client_path(path))
63
60
return self.do_bzrdir_request(*args)
65
62
def _boolean_to_yes_no(self, a_boolean):
92
89
class SmartServerBzrDirRequestCloningMetaDir(SmartServerRequestBzrDir):
94
91
def do_bzrdir_request(self, require_stacking):
95
"""Get the format that should be used when cloning from this dir.
99
:return: on success, a 3-tuple of network names for (control,
100
repository, branch) directories, where '' signifies "not present".
101
If this BzrDir contains a branch reference then this will fail with
102
BranchReference; clients should resolve branch references before
92
"""Get the format that should be used when cloning from this dir."""
106
94
branch_ref = self._bzrdir.get_branch_reference()
107
95
except errors.NotBranchError:
109
if branch_ref is not None:
110
# The server shouldn't try to resolve references, and it quite
111
# possibly can't reach them anyway. The client needs to resolve
112
# the branch reference to determine the cloning_metadir.
113
return FailedSmartServerResponse(('BranchReference',))
114
97
if require_stacking == "True":
115
98
require_stacking = True
118
101
control_format = self._bzrdir.cloning_metadir(
119
102
require_stacking=require_stacking)
120
103
control_name = control_format.network_name()
121
# XXX: There should be a method that tells us that the format does/does
122
# not have subformats.
104
# XXX: There should be a method that tells us that the format does/does not
123
106
if isinstance(control_format, BzrDirMetaFormat1):
124
branch_name = ('branch',
125
control_format.get_branch_format().network_name())
107
if branch_ref is not None:
108
# If there's a branch reference, the client will have to resolve
109
# the branch reference to figure out the cloning metadir
110
branch_name = ('reference', branch_ref)
113
'direct', control_format.get_branch_format().network_name())
126
114
repository_name = control_format.repository_format.network_name()
128
116
# Only MetaDir has delegated formats today.
129
branch_name = ('branch', '')
130
118
repository_name = ''
131
119
return SuccessfulSmartServerResponse((control_name, repository_name,
176
164
This operates precisely like 'bzrdir.create_repository'.
178
If a bzrdir is not present, an exception is propagated
166
If a bzrdir is not present, an exception is propogated
179
167
rather than 'no branch' because these are different conditions (and
180
168
this method should only be called after establishing that a bzr dir
233
221
This operates precisely like 'bzrdir.find_repository'.
235
If a bzrdir is not present, an exception is propagated
223
If a bzrdir is not present, an exception is propogated
236
224
rather than 'no branch' because these are different conditions.
238
226
This is the initial version of this method introduced with the smart
256
244
This operates precisely like 'bzrdir.find_repository'.
258
If a bzrdir is not present, an exception is propagated
246
If a bzrdir is not present, an exception is propogated
259
247
rather than 'no branch' because these are different conditions.
261
249
This is the second edition of this method introduced in bzr 1.3, which
310
298
return SuccessfulSmartServerResponse(('ok', ))
313
class SmartServerRequestOpenBranch(SmartServerRequestBzrDir):
315
def do_bzrdir_request(self):
316
"""open a branch at path and return the branch reference or branch."""
301
class SmartServerRequestOpenBranch(SmartServerRequest):
304
"""try to open a branch at path and return ok/nobranch.
306
If a bzrdir is not present, an exception is propogated
307
rather than 'no branch' because these are different conditions.
309
bzrdir = BzrDir.open_from_transport(
310
self.transport_from_client_path(path))
318
reference_url = self._bzrdir.get_branch_reference()
312
reference_url = bzrdir.get_branch_reference()
319
313
if reference_url is None:
320
314
return SuccessfulSmartServerResponse(('ok', ''))
322
316
return SuccessfulSmartServerResponse(('ok', reference_url))
323
317
except errors.NotBranchError:
324
318
return FailedSmartServerResponse(('nobranch', ))
327
class SmartServerRequestOpenBranchV2(SmartServerRequestBzrDir):
329
def do_bzrdir_request(self):
330
"""open a branch at path and return the reference or format."""
332
reference_url = self._bzrdir.get_branch_reference()
333
if reference_url is None:
334
br = self._bzrdir.open_branch(ignore_fallbacks=True)
335
format = br._format.network_name()
336
return SuccessfulSmartServerResponse(('branch', format))
338
return SuccessfulSmartServerResponse(('ref', reference_url))
339
except errors.NotBranchError:
340
return FailedSmartServerResponse(('nobranch', ))