57
51
return SuccessfulSmartServerResponse((answer,))
60
class SmartServerRequestOpenBzrDir_2_1(SmartServerRequest):
63
"""Is there a BzrDir present, and if so does it have a working tree?
68
t = self.transport_from_client_path(path)
69
except errors.PathNotChild:
70
# The client is trying to ask about a path that they have no access
72
return SuccessfulSmartServerResponse(('no',))
74
bd = BzrDir.open_from_transport(t)
75
except errors.NotBranchError:
79
if bd.has_workingtree():
83
return SuccessfulSmartServerResponse(answer)
86
54
class SmartServerRequestBzrDir(SmartServerRequest):
88
56
def do(self, path, *args):
357
310
return SuccessfulSmartServerResponse(('ok', ))
360
class SmartServerRequestBzrDirInitializeEx(SmartServerRequestBzrDir):
362
def parse_NoneTrueFalse(self, arg):
369
raise AssertionError("invalid arg %r" % arg)
371
def parse_NoneString(self, arg):
374
def _serialize_NoneTrueFalse(self, arg):
381
def do(self, bzrdir_network_name, path, use_existing_dir, create_prefix,
382
force_new_repo, stacked_on, stack_on_pwd, repo_format_name,
383
make_working_trees, shared_repo):
384
"""Initialize a bzrdir at path as per
385
BzrDirFormat.initialize_on_transport_ex.
387
New in 1.16. (Replaces BzrDirFormat.initialize_ex verb from 1.15).
389
:return: return SuccessfulSmartServerResponse((repo_path, rich_root,
390
tree_ref, external_lookup, repo_network_name,
391
repo_bzrdir_network_name, bzrdir_format_network_name,
392
NoneTrueFalse(stacking), final_stack, final_stack_pwd,
395
target_transport = self.transport_from_client_path(path)
396
format = network_format_registry.get(bzrdir_network_name)
397
use_existing_dir = self.parse_NoneTrueFalse(use_existing_dir)
398
create_prefix = self.parse_NoneTrueFalse(create_prefix)
399
force_new_repo = self.parse_NoneTrueFalse(force_new_repo)
400
stacked_on = self.parse_NoneString(stacked_on)
401
stack_on_pwd = self.parse_NoneString(stack_on_pwd)
402
make_working_trees = self.parse_NoneTrueFalse(make_working_trees)
403
shared_repo = self.parse_NoneTrueFalse(shared_repo)
404
if stack_on_pwd == '.':
405
stack_on_pwd = target_transport.base
406
repo_format_name = self.parse_NoneString(repo_format_name)
407
repo, bzrdir, stacking, repository_policy = \
408
format.initialize_on_transport_ex(target_transport,
409
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
410
force_new_repo=force_new_repo, stacked_on=stacked_on,
411
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
412
make_working_trees=make_working_trees, shared_repo=shared_repo)
416
rich_root = tree_ref = external_lookup = ''
417
repo_bzrdir_name = ''
419
final_stack_pwd = None
422
repo_path = self._repo_relpath(bzrdir.root_transport, repo)
425
rich_root, tree_ref, external_lookup = self._format_to_capabilities(
427
repo_name = repo._format.network_name()
428
repo_bzrdir_name = repo.bzrdir._format.network_name()
429
final_stack = repository_policy._stack_on
430
final_stack_pwd = repository_policy._stack_on_pwd
431
# It is returned locked, but we need to do the lock to get the lock
434
repo_lock_token = repo.lock_write().repository_token or ''
436
repo.leave_lock_in_place()
438
final_stack = final_stack or ''
439
final_stack_pwd = final_stack_pwd or ''
441
# We want this to be relative to the bzrdir.
443
final_stack_pwd = urlutils.relative_url(
444
target_transport.base, final_stack_pwd)
446
# Can't meaningfully return a root path.
447
if final_stack.startswith('/'):
448
client_path = self._root_client_path + final_stack[1:]
449
final_stack = urlutils.relative_url(
450
self._root_client_path, client_path)
451
final_stack_pwd = '.'
453
return SuccessfulSmartServerResponse((repo_path, rich_root, tree_ref,
454
external_lookup, repo_name, repo_bzrdir_name,
455
bzrdir._format.network_name(),
456
self._serialize_NoneTrueFalse(stacking), final_stack,
457
final_stack_pwd, repo_lock_token))
460
313
class SmartServerRequestOpenBranch(SmartServerRequestBzrDir):
462
315
def do_bzrdir_request(self):
483
336
return SuccessfulSmartServerResponse(('branch', format))
485
338
return SuccessfulSmartServerResponse(('ref', reference_url))
486
except errors.NotBranchError, e:
487
return FailedSmartServerResponse(('nobranch',))
490
class SmartServerRequestOpenBranchV3(SmartServerRequestBzrDir):
492
def do_bzrdir_request(self):
493
"""Open a branch at path and return the reference or format.
495
This version introduced in 2.1.
497
Differences to SmartServerRequestOpenBranchV2:
498
* can return 2-element ('nobranch', extra), where 'extra' is a string
499
with an explanation like 'location is a repository'. Previously
500
a 'nobranch' response would never have more than one element.
503
reference_url = self._bzrdir.get_branch_reference()
504
if reference_url is None:
505
br = self._bzrdir.open_branch(ignore_fallbacks=True)
506
format = br._format.network_name()
507
return SuccessfulSmartServerResponse(('branch', format))
509
return SuccessfulSmartServerResponse(('ref', reference_url))
510
except errors.NotBranchError, e:
511
# Stringify the exception so that its .detail attribute will be
517
if detail.startswith(': '):
520
return FailedSmartServerResponse(resp)
339
except errors.NotBranchError:
340
return FailedSmartServerResponse(('nobranch', ))