55
51
return SuccessfulSmartServerResponse((answer,))
58
class SmartServerRequestOpenBzrDir_2_1(SmartServerRequest):
61
"""Is there a BzrDir present, and if so does it have a working tree?
66
t = self.transport_from_client_path(path)
67
except errors.PathNotChild:
68
# The client is trying to ask about a path that they have no access
70
return SuccessfulSmartServerResponse(('no',))
72
bd = BzrDir.open_from_transport(t)
73
except errors.NotBranchError:
77
if bd.has_workingtree():
81
return SuccessfulSmartServerResponse(answer)
84
54
class SmartServerRequestBzrDir(SmartServerRequest):
86
56
def do(self, path, *args):
355
310
return SuccessfulSmartServerResponse(('ok', ))
358
class SmartServerRequestBzrDirInitializeEx(SmartServerRequestBzrDir):
360
def parse_NoneTrueFalse(self, arg):
367
raise AssertionError("invalid arg %r" % arg)
369
def parse_NoneString(self, arg):
372
def _serialize_NoneTrueFalse(self, arg):
379
def do(self, bzrdir_network_name, path, use_existing_dir, create_prefix,
380
force_new_repo, stacked_on, stack_on_pwd, repo_format_name,
381
make_working_trees, shared_repo):
382
"""Initialize a bzrdir at path as per
383
BzrDirFormat.initialize_on_transport_ex.
385
New in 1.16. (Replaces BzrDirFormat.initialize_ex verb from 1.15).
387
:return: return SuccessfulSmartServerResponse((repo_path, rich_root,
388
tree_ref, external_lookup, repo_network_name,
389
repo_bzrdir_network_name, bzrdir_format_network_name,
390
NoneTrueFalse(stacking), final_stack, final_stack_pwd,
393
target_transport = self.transport_from_client_path(path)
394
format = network_format_registry.get(bzrdir_network_name)
395
use_existing_dir = self.parse_NoneTrueFalse(use_existing_dir)
396
create_prefix = self.parse_NoneTrueFalse(create_prefix)
397
force_new_repo = self.parse_NoneTrueFalse(force_new_repo)
398
stacked_on = self.parse_NoneString(stacked_on)
399
stack_on_pwd = self.parse_NoneString(stack_on_pwd)
400
make_working_trees = self.parse_NoneTrueFalse(make_working_trees)
401
shared_repo = self.parse_NoneTrueFalse(shared_repo)
402
if stack_on_pwd == '.':
403
stack_on_pwd = target_transport.base
404
repo_format_name = self.parse_NoneString(repo_format_name)
405
repo, bzrdir, stacking, repository_policy = \
406
format.initialize_on_transport_ex(target_transport,
407
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
408
force_new_repo=force_new_repo, stacked_on=stacked_on,
409
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
410
make_working_trees=make_working_trees, shared_repo=shared_repo)
414
rich_root = tree_ref = external_lookup = ''
415
repo_bzrdir_name = ''
417
final_stack_pwd = None
420
repo_path = self._repo_relpath(bzrdir.root_transport, repo)
423
rich_root, tree_ref, external_lookup = self._format_to_capabilities(
425
repo_name = repo._format.network_name()
426
repo_bzrdir_name = repo.bzrdir._format.network_name()
427
final_stack = repository_policy._stack_on
428
final_stack_pwd = repository_policy._stack_on_pwd
429
# It is returned locked, but we need to do the lock to get the lock
432
repo_lock_token = repo.lock_write() or ''
434
repo.leave_lock_in_place()
436
final_stack = final_stack or ''
437
final_stack_pwd = final_stack_pwd or ''
439
# We want this to be relative to the bzrdir.
441
final_stack_pwd = urlutils.relative_url(
442
target_transport.base, final_stack_pwd)
444
# Can't meaningfully return a root path.
445
if final_stack.startswith('/'):
446
client_path = self._root_client_path + final_stack[1:]
447
final_stack = urlutils.relative_url(
448
self._root_client_path, client_path)
449
final_stack_pwd = '.'
451
return SuccessfulSmartServerResponse((repo_path, rich_root, tree_ref,
452
external_lookup, repo_name, repo_bzrdir_name,
453
bzrdir._format.network_name(),
454
self._serialize_NoneTrueFalse(stacking), final_stack,
455
final_stack_pwd, repo_lock_token))
458
313
class SmartServerRequestOpenBranch(SmartServerRequestBzrDir):
460
315
def do_bzrdir_request(self):
481
336
return SuccessfulSmartServerResponse(('branch', format))
483
338
return SuccessfulSmartServerResponse(('ref', reference_url))
484
except errors.NotBranchError, e:
485
return FailedSmartServerResponse(('nobranch',))
488
class SmartServerRequestOpenBranchV3(SmartServerRequestBzrDir):
490
def do_bzrdir_request(self):
491
"""Open a branch at path and return the reference or format.
493
This version introduced in 2.1.
495
Differences to SmartServerRequestOpenBranchV2:
496
* can return 2-element ('nobranch', extra), where 'extra' is a string
497
with an explanation like 'location is a repository'. Previously
498
a 'nobranch' response would never have more than one element.
501
reference_url = self._bzrdir.get_branch_reference()
502
if reference_url is None:
503
br = self._bzrdir.open_branch(ignore_fallbacks=True)
504
format = br._format.network_name()
505
return SuccessfulSmartServerResponse(('branch', format))
507
return SuccessfulSmartServerResponse(('ref', reference_url))
508
except errors.NotBranchError, e:
509
# Stringify the exception so that its .detail attribute will be
515
if detail.startswith(': '):
518
return FailedSmartServerResponse(resp)
339
except errors.NotBranchError:
340
return FailedSmartServerResponse(('nobranch', ))