34
34
from bzrlib.branch import BranchReferenceFormat
35
35
from bzrlib.bzrdir import BzrDir, RemoteBzrDirFormat
36
from bzrlib.decorators import needs_read_lock, needs_write_lock
36
from bzrlib.decorators import needs_read_lock, needs_write_lock, only_raises
37
37
from bzrlib.errors import (
39
39
SmartProtocolError,
89
89
class RemoteBzrDir(BzrDir, _RpcHelper):
90
90
"""Control directory on a remote server, accessed via bzr:// or similar."""
92
def __init__(self, transport, format, _client=None):
92
def __init__(self, transport, format, _client=None, _force_probe=False):
93
93
"""Construct a RemoteBzrDir.
95
95
:param _client: Private parameter for testing. Disables probing and the
99
99
# this object holds a delegated bzrdir that uses file-level operations
100
100
# to talk to the other side
101
101
self._real_bzrdir = None
102
self._has_working_tree = None
102
103
# 1-shot cache for the call pattern 'create_branch; open_branch' - see
103
104
# create_branch for details.
104
105
self._next_open_branch_result = None
108
109
self._client = client._SmartClient(medium)
110
111
self._client = _client
117
def _probe_bzrdir(self):
118
medium = self._client._medium
113
119
path = self._path_for_remote_call(self._client)
120
if medium._is_remote_before((2, 1)):
124
self._rpc_open_2_1(path)
126
except errors.UnknownSmartMethod:
127
medium._remember_remote_is_before((2, 1))
130
def _rpc_open_2_1(self, path):
131
response = self._call('BzrDir.open_2.1', path)
132
if response == ('no',):
133
raise errors.NotBranchError(path=self.root_transport.base)
134
elif response[0] == 'yes':
135
if response[1] == 'yes':
136
self._has_working_tree = True
137
elif response[1] == 'no':
138
self._has_working_tree = False
140
raise errors.UnexpectedSmartServerResponse(response)
142
raise errors.UnexpectedSmartServerResponse(response)
144
def _rpc_open(self, path):
114
145
response = self._call('BzrDir.open', path)
115
146
if response not in [('yes',), ('no',)]:
116
147
raise errors.UnexpectedSmartServerResponse(response)
117
148
if response == ('no',):
118
raise errors.NotBranchError(path=transport.base)
149
raise errors.NotBranchError(path=self.root_transport.base)
120
151
def _ensure_real(self):
121
152
"""Ensure that there is a _real_bzrdir set.
356
387
raise errors.NoRepositoryPresent(self)
389
def has_workingtree(self):
390
if self._has_working_tree is None:
392
self._has_working_tree = self._real_bzrdir.has_workingtree()
393
return self._has_working_tree
358
395
def open_workingtree(self, recommend_upgrade=True):
360
if self._real_bzrdir.has_workingtree():
396
if self.has_workingtree():
361
397
raise errors.NotLocalUrl(self.root_transport)
363
399
raise errors.NoWorkingTree(self.root_transport.base)
583
619
return self._custom_format._serializer
586
class RemoteRepository(_RpcHelper):
622
class RemoteRepository(_RpcHelper, lock._RelockDebugMixin):
587
623
"""Repository accessed over rpc.
589
625
For the moment most operations are performed using local transport-backed
2045
2084
return self._custom_format.supports_set_append_revisions_only()
2048
class RemoteBranch(branch.Branch, _RpcHelper):
2087
class RemoteBranch(branch.Branch, _RpcHelper, lock._RelockDebugMixin):
2049
2088
"""Branch stored on a server accessed by HPSS RPC.
2051
2090
At the moment most operations are mapped down to simple file operations.
2308
2348
def lock_write(self, token=None):
2309
2349
if not self._lock_mode:
2350
self._note_lock('w')
2310
2351
# Lock the branch and repo in one remote call.
2311
2352
remote_tokens = self._remote_lock_write(token)
2312
2353
self._lock_token, self._repo_lock_token = remote_tokens