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)
1739
1775
# The stream included an inventory-delta record, but the remote
1740
1776
# side isn't new enough to support them. So we need to send the
1741
1777
# rest of the stream via VFS.
1778
self.target_repo.refresh_data()
1742
1779
return self._resume_stream_with_vfs(response, src_format)
1743
1780
if response[0][0] == 'missing-basis':
1744
1781
tokens, missing_keys = bencode.bdecode_as_tuple(response[0][1])
2267
2304
medium = self._client._medium
2268
2305
if medium._is_remote_before((1, 18)):
2269
2306
self._vfs_set_tags_bytes(bytes)
2272
2310
self._remote_path(), self._lock_token, self._repo_lock_token)
2759
2797
'Missing key %r in context %r', key_err.args[0], context)
2762
if err.error_verb == 'NoSuchRevision':
2800
if err.error_verb == 'IncompatibleRepositories':
2801
raise errors.IncompatibleRepositories(err.error_args[0],
2802
err.error_args[1], err.error_args[2])
2803
elif err.error_verb == 'NoSuchRevision':
2763
2804
raise NoSuchRevision(find('branch'), err.error_args[0])
2764
2805
elif err.error_verb == 'nosuchrevision':
2765
2806
raise NoSuchRevision(find('repository'), err.error_args[0])