87
# Note: RemoteBzrDirFormat is in bzrdir.py
89
class RemoteBzrDir(BzrDir, _RpcHelper):
92
# Note that RemoteBzrDirProber lives in bzrlib.bzrdir so bzrlib.remote
93
# does not have to be imported unless a remote format is involved.
95
class RemoteBzrDirFormat(_mod_bzrdir.BzrDirMetaFormat1):
96
"""Format representing bzrdirs accessed via a smart server"""
98
supports_workingtrees = False
101
_mod_bzrdir.BzrDirMetaFormat1.__init__(self)
102
# XXX: It's a bit ugly that the network name is here, because we'd
103
# like to believe that format objects are stateless or at least
104
# immutable, However, we do at least avoid mutating the name after
105
# it's returned. See <https://bugs.launchpad.net/bzr/+bug/504102>
106
self._network_name = None
109
return "%s(_network_name=%r)" % (self.__class__.__name__,
112
def get_format_description(self):
113
if self._network_name:
114
real_format = controldir.network_format_registry.get(self._network_name)
115
return 'Remote: ' + real_format.get_format_description()
116
return 'bzr remote bzrdir'
118
def get_format_string(self):
119
raise NotImplementedError(self.get_format_string)
121
def network_name(self):
122
if self._network_name:
123
return self._network_name
125
raise AssertionError("No network name set.")
127
def initialize_on_transport(self, transport):
129
# hand off the request to the smart server
130
client_medium = transport.get_smart_medium()
131
except errors.NoSmartMedium:
132
# TODO: lookup the local format from a server hint.
133
local_dir_format = _mod_bzrdir.BzrDirMetaFormat1()
134
return local_dir_format.initialize_on_transport(transport)
135
client = _SmartClient(client_medium)
136
path = client.remote_path_from_transport(transport)
138
response = client.call('BzrDirFormat.initialize', path)
139
except errors.ErrorFromSmartServer, err:
140
_translate_error(err, path=path)
141
if response[0] != 'ok':
142
raise errors.SmartProtocolError('unexpected response code %s' % (response,))
143
format = RemoteBzrDirFormat()
144
self._supply_sub_formats_to(format)
145
return RemoteBzrDir(transport, format)
147
def parse_NoneTrueFalse(self, arg):
154
raise AssertionError("invalid arg %r" % arg)
156
def _serialize_NoneTrueFalse(self, arg):
163
def _serialize_NoneString(self, arg):
166
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
167
create_prefix=False, force_new_repo=False, stacked_on=None,
168
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
171
# hand off the request to the smart server
172
client_medium = transport.get_smart_medium()
173
except errors.NoSmartMedium:
176
# Decline to open it if the server doesn't support our required
177
# version (3) so that the VFS-based transport will do it.
178
if client_medium.should_probe():
180
server_version = client_medium.protocol_version()
181
if server_version != '2':
185
except errors.SmartProtocolError:
186
# Apparently there's no usable smart server there, even though
187
# the medium supports the smart protocol.
192
client = _SmartClient(client_medium)
193
path = client.remote_path_from_transport(transport)
194
if client_medium._is_remote_before((1, 16)):
197
# TODO: lookup the local format from a server hint.
198
local_dir_format = _mod_bzrdir.BzrDirMetaFormat1()
199
self._supply_sub_formats_to(local_dir_format)
200
return local_dir_format.initialize_on_transport_ex(transport,
201
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
202
force_new_repo=force_new_repo, stacked_on=stacked_on,
203
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
204
make_working_trees=make_working_trees, shared_repo=shared_repo,
206
return self._initialize_on_transport_ex_rpc(client, path, transport,
207
use_existing_dir, create_prefix, force_new_repo, stacked_on,
208
stack_on_pwd, repo_format_name, make_working_trees, shared_repo)
210
def _initialize_on_transport_ex_rpc(self, client, path, transport,
211
use_existing_dir, create_prefix, force_new_repo, stacked_on,
212
stack_on_pwd, repo_format_name, make_working_trees, shared_repo):
214
args.append(self._serialize_NoneTrueFalse(use_existing_dir))
215
args.append(self._serialize_NoneTrueFalse(create_prefix))
216
args.append(self._serialize_NoneTrueFalse(force_new_repo))
217
args.append(self._serialize_NoneString(stacked_on))
218
# stack_on_pwd is often/usually our transport
221
stack_on_pwd = transport.relpath(stack_on_pwd)
224
except errors.PathNotChild:
226
args.append(self._serialize_NoneString(stack_on_pwd))
227
args.append(self._serialize_NoneString(repo_format_name))
228
args.append(self._serialize_NoneTrueFalse(make_working_trees))
229
args.append(self._serialize_NoneTrueFalse(shared_repo))
230
request_network_name = self._network_name or \
231
_mod_bzrdir.BzrDirFormat.get_default_format().network_name()
233
response = client.call('BzrDirFormat.initialize_ex_1.16',
234
request_network_name, path, *args)
235
except errors.UnknownSmartMethod:
236
client._medium._remember_remote_is_before((1,16))
237
local_dir_format = _mod_bzrdir.BzrDirMetaFormat1()
238
self._supply_sub_formats_to(local_dir_format)
239
return local_dir_format.initialize_on_transport_ex(transport,
240
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
241
force_new_repo=force_new_repo, stacked_on=stacked_on,
242
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
243
make_working_trees=make_working_trees, shared_repo=shared_repo,
245
except errors.ErrorFromSmartServer, err:
246
_translate_error(err, path=path)
247
repo_path = response[0]
248
bzrdir_name = response[6]
249
require_stacking = response[7]
250
require_stacking = self.parse_NoneTrueFalse(require_stacking)
251
format = RemoteBzrDirFormat()
252
format._network_name = bzrdir_name
253
self._supply_sub_formats_to(format)
254
bzrdir = RemoteBzrDir(transport, format, _client=client)
256
repo_format = response_tuple_to_repo_format(response[1:])
260
repo_bzrdir_format = RemoteBzrDirFormat()
261
repo_bzrdir_format._network_name = response[5]
262
repo_bzr = RemoteBzrDir(transport.clone(repo_path),
266
final_stack = response[8] or None
267
final_stack_pwd = response[9] or None
269
final_stack_pwd = urlutils.join(
270
transport.base, final_stack_pwd)
271
remote_repo = RemoteRepository(repo_bzr, repo_format)
272
if len(response) > 10:
273
# Updated server verb that locks remotely.
274
repo_lock_token = response[10] or None
275
remote_repo.lock_write(repo_lock_token, _skip_rpc=True)
277
remote_repo.dont_leave_lock_in_place()
279
remote_repo.lock_write()
280
policy = _mod_bzrdir.UseExistingRepository(remote_repo, final_stack,
281
final_stack_pwd, require_stacking)
282
policy.acquire_repository()
286
bzrdir._format.set_branch_format(self.get_branch_format())
288
# The repo has already been created, but we need to make sure that
289
# we'll make a stackable branch.
290
bzrdir._format.require_stacking(_skip_repo=True)
291
return remote_repo, bzrdir, require_stacking, policy
293
def _open(self, transport):
294
return RemoteBzrDir(transport, self)
296
def __eq__(self, other):
297
if not isinstance(other, RemoteBzrDirFormat):
299
return self.get_format_description() == other.get_format_description()
301
def __return_repository_format(self):
302
# Always return a RemoteRepositoryFormat object, but if a specific bzr
303
# repository format has been asked for, tell the RemoteRepositoryFormat
304
# that it should use that for init() etc.
305
result = RemoteRepositoryFormat()
306
custom_format = getattr(self, '_repository_format', None)
308
if isinstance(custom_format, RemoteRepositoryFormat):
311
# We will use the custom format to create repositories over the
312
# wire; expose its details like rich_root_data for code to
314
result._custom_format = custom_format
317
def get_branch_format(self):
318
result = _mod_bzrdir.BzrDirMetaFormat1.get_branch_format(self)
319
if not isinstance(result, RemoteBranchFormat):
320
new_result = RemoteBranchFormat()
321
new_result._custom_format = result
323
self.set_branch_format(new_result)
327
repository_format = property(__return_repository_format,
328
_mod_bzrdir.BzrDirMetaFormat1._set_repository_format) #.im_func)
331
class RemoteBzrDir(_mod_bzrdir.BzrDir, _RpcHelper):
90
332
"""Control directory on a remote server, accessed via bzr:// or similar."""
92
334
def __init__(self, transport, format, _client=None, _force_probe=False):
1301
1606
@needs_read_lock
1302
def search_missing_revision_ids(self, other, revision_id=None, find_ghosts=True):
1607
def search_missing_revision_ids(self, other,
1608
revision_id=symbol_versioning.DEPRECATED_PARAMETER,
1609
find_ghosts=True, revision_ids=None, if_present_ids=None,
1303
1611
"""Return the revision ids that other has that this does not.
1305
1613
These are returned in topological order.
1307
1615
revision_id: only return revision ids included by revision_id.
1309
return repository.InterRepository.get(
1310
other, self).search_missing_revision_ids(revision_id, find_ghosts)
1617
if symbol_versioning.deprecated_passed(revision_id):
1618
symbol_versioning.warn(
1619
'search_missing_revision_ids(revision_id=...) was '
1620
'deprecated in 2.4. Use revision_ids=[...] instead.',
1621
DeprecationWarning, stacklevel=2)
1622
if revision_ids is not None:
1623
raise AssertionError(
1624
'revision_ids is mutually exclusive with revision_id')
1625
if revision_id is not None:
1626
revision_ids = [revision_id]
1627
inter_repo = _mod_repository.InterRepository.get(other, self)
1628
return inter_repo.search_missing_revision_ids(
1629
find_ghosts=find_ghosts, revision_ids=revision_ids,
1630
if_present_ids=if_present_ids, limit=limit)
1312
def fetch(self, source, revision_id=None, pb=None, find_ghosts=False,
1632
def fetch(self, source, revision_id=None, find_ghosts=False,
1313
1633
fetch_spec=None):
1314
1634
# No base implementation to use as RemoteRepository is not a subclass
1315
1635
# of Repository; so this is a copy of Repository.fetch().
2739
3141
medium = self._branch._client._medium
2740
3142
if medium._is_remote_before((1, 14)):
2741
3143
return self._vfs_set_option(value, name, section)
3144
if isinstance(value, dict):
3145
if medium._is_remote_before((2, 2)):
3146
return self._vfs_set_option(value, name, section)
3147
return self._set_config_option_dict(value, name, section)
3149
return self._set_config_option(value, name, section)
3151
def _set_config_option(self, value, name, section):
2743
3153
path = self._branch._remote_path()
2744
3154
response = self._branch._client.call('Branch.set_config_option',
2745
3155
path, self._branch._lock_token, self._branch._repo_lock_token,
2746
3156
value.encode('utf8'), name, section or '')
2747
3157
except errors.UnknownSmartMethod:
3158
medium = self._branch._client._medium
2748
3159
medium._remember_remote_is_before((1, 14))
2749
3160
return self._vfs_set_option(value, name, section)
2750
3161
if response != ():
2751
3162
raise errors.UnexpectedSmartServerResponse(response)
3164
def _serialize_option_dict(self, option_dict):
3166
for key, value in option_dict.items():
3167
if isinstance(key, unicode):
3168
key = key.encode('utf8')
3169
if isinstance(value, unicode):
3170
value = value.encode('utf8')
3171
utf8_dict[key] = value
3172
return bencode.bencode(utf8_dict)
3174
def _set_config_option_dict(self, value, name, section):
3176
path = self._branch._remote_path()
3177
serialised_dict = self._serialize_option_dict(value)
3178
response = self._branch._client.call(
3179
'Branch.set_config_option_dict',
3180
path, self._branch._lock_token, self._branch._repo_lock_token,
3181
serialised_dict, name, section or '')
3182
except errors.UnknownSmartMethod:
3183
medium = self._branch._client._medium
3184
medium._remember_remote_is_before((2, 2))
3185
return self._vfs_set_option(value, name, section)
3187
raise errors.UnexpectedSmartServerResponse(response)
2753
3189
def _real_object(self):
2754
3190
self._branch._ensure_real()
2755
3191
return self._branch._real_branch