1
# Copyright (C) 2006-2010 Canonical Ltd
1
# Copyright (C) 2006 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
47
45
# clients that don't anticipate errors from this method.
50
bzr_prober = BzrProber()
48
default_format = BzrDirFormat.get_default_format()
49
real_bzrdir = default_format.open(t, _found=True)
52
bzr_prober.probe_transport(t)
51
real_bzrdir._format.probe_transport(t)
53
52
except (errors.NotBranchError, errors.UnknownFormatError):
57
56
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
59
class SmartServerRequestBzrDir(SmartServerRequest):
88
61
def do(self, path, *args):
91
64
self._bzrdir = BzrDir.open_from_transport(
92
65
self.transport_from_client_path(path))
93
except errors.NotBranchError, e:
94
return FailedSmartServerResponse(('nobranch',))
66
except errors.NotBranchError:
67
return FailedSmartServerResponse(('nobranch', ))
95
68
return self.do_bzrdir_request(*args)
97
70
def _boolean_to_yes_no(self, a_boolean):
112
85
"""Get the relative path for repository from current_transport."""
113
86
# the relpath of the bzrdir in the found repository gives us the
114
87
# path segments to pop-out.
115
relpath = repository.user_transport.relpath(
88
relpath = repository.bzrdir.root_transport.relpath(
116
89
current_transport.base)
118
91
segments = ['..'] * len(relpath.split('/'))
431
404
# 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 ''
407
repo_lock_token = repo.lock_write() or ''
435
408
if repo_lock_token:
436
409
repo.leave_lock_in_place()
467
440
return SuccessfulSmartServerResponse(('ok', ''))
469
442
return SuccessfulSmartServerResponse(('ok', reference_url))
470
except errors.NotBranchError, e:
471
return FailedSmartServerResponse(('nobranch',))
443
except errors.NotBranchError:
444
return FailedSmartServerResponse(('nobranch', ))
474
447
class SmartServerRequestOpenBranchV2(SmartServerRequestBzrDir):
483
456
return SuccessfulSmartServerResponse(('branch', format))
485
458
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)
459
except errors.NotBranchError:
460
return FailedSmartServerResponse(('nobranch', ))