89
# Note: RemoteBzrDirFormat is in bzrdir.py
91
class RemoteBzrDir(BzrDir, _RpcHelper):
100
# Note that RemoteBzrDirProber lives in bzrlib.bzrdir so bzrlib.remote
101
# does not have to be imported unless a remote format is involved.
103
class RemoteBzrDirFormat(_mod_bzrdir.BzrDirMetaFormat1):
104
"""Format representing bzrdirs accessed via a smart server"""
106
supports_workingtrees = False
109
_mod_bzrdir.BzrDirMetaFormat1.__init__(self)
110
# XXX: It's a bit ugly that the network name is here, because we'd
111
# like to believe that format objects are stateless or at least
112
# immutable, However, we do at least avoid mutating the name after
113
# it's returned. See <https://bugs.launchpad.net/bzr/+bug/504102>
114
self._network_name = None
117
return "%s(_network_name=%r)" % (self.__class__.__name__,
120
def get_format_description(self):
121
if self._network_name:
123
real_format = controldir.network_format_registry.get(
128
return 'Remote: ' + real_format.get_format_description()
129
return 'bzr remote bzrdir'
131
def get_format_string(self):
132
raise NotImplementedError(self.get_format_string)
134
def network_name(self):
135
if self._network_name:
136
return self._network_name
138
raise AssertionError("No network name set.")
140
def initialize_on_transport(self, transport):
142
# hand off the request to the smart server
143
client_medium = transport.get_smart_medium()
144
except errors.NoSmartMedium:
145
# TODO: lookup the local format from a server hint.
146
local_dir_format = _mod_bzrdir.BzrDirMetaFormat1()
147
return local_dir_format.initialize_on_transport(transport)
148
client = _SmartClient(client_medium)
149
path = client.remote_path_from_transport(transport)
151
response = client.call('BzrDirFormat.initialize', path)
152
except errors.ErrorFromSmartServer, err:
153
_translate_error(err, path=path)
154
if response[0] != 'ok':
155
raise errors.SmartProtocolError('unexpected response code %s' % (response,))
156
format = RemoteBzrDirFormat()
157
self._supply_sub_formats_to(format)
158
return RemoteBzrDir(transport, format)
160
def parse_NoneTrueFalse(self, arg):
167
raise AssertionError("invalid arg %r" % arg)
169
def _serialize_NoneTrueFalse(self, arg):
176
def _serialize_NoneString(self, arg):
179
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
180
create_prefix=False, force_new_repo=False, stacked_on=None,
181
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
184
# hand off the request to the smart server
185
client_medium = transport.get_smart_medium()
186
except errors.NoSmartMedium:
189
# Decline to open it if the server doesn't support our required
190
# version (3) so that the VFS-based transport will do it.
191
if client_medium.should_probe():
193
server_version = client_medium.protocol_version()
194
if server_version != '2':
198
except errors.SmartProtocolError:
199
# Apparently there's no usable smart server there, even though
200
# the medium supports the smart protocol.
205
client = _SmartClient(client_medium)
206
path = client.remote_path_from_transport(transport)
207
if client_medium._is_remote_before((1, 16)):
210
# TODO: lookup the local format from a server hint.
211
local_dir_format = _mod_bzrdir.BzrDirMetaFormat1()
212
self._supply_sub_formats_to(local_dir_format)
213
return local_dir_format.initialize_on_transport_ex(transport,
214
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
215
force_new_repo=force_new_repo, stacked_on=stacked_on,
216
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
217
make_working_trees=make_working_trees, shared_repo=shared_repo,
219
return self._initialize_on_transport_ex_rpc(client, path, transport,
220
use_existing_dir, create_prefix, force_new_repo, stacked_on,
221
stack_on_pwd, repo_format_name, make_working_trees, shared_repo)
223
def _initialize_on_transport_ex_rpc(self, client, path, transport,
224
use_existing_dir, create_prefix, force_new_repo, stacked_on,
225
stack_on_pwd, repo_format_name, make_working_trees, shared_repo):
227
args.append(self._serialize_NoneTrueFalse(use_existing_dir))
228
args.append(self._serialize_NoneTrueFalse(create_prefix))
229
args.append(self._serialize_NoneTrueFalse(force_new_repo))
230
args.append(self._serialize_NoneString(stacked_on))
231
# stack_on_pwd is often/usually our transport
234
stack_on_pwd = transport.relpath(stack_on_pwd)
237
except errors.PathNotChild:
239
args.append(self._serialize_NoneString(stack_on_pwd))
240
args.append(self._serialize_NoneString(repo_format_name))
241
args.append(self._serialize_NoneTrueFalse(make_working_trees))
242
args.append(self._serialize_NoneTrueFalse(shared_repo))
243
request_network_name = self._network_name or \
244
_mod_bzrdir.BzrDirFormat.get_default_format().network_name()
246
response = client.call('BzrDirFormat.initialize_ex_1.16',
247
request_network_name, path, *args)
248
except errors.UnknownSmartMethod:
249
client._medium._remember_remote_is_before((1,16))
250
local_dir_format = _mod_bzrdir.BzrDirMetaFormat1()
251
self._supply_sub_formats_to(local_dir_format)
252
return local_dir_format.initialize_on_transport_ex(transport,
253
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
254
force_new_repo=force_new_repo, stacked_on=stacked_on,
255
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
256
make_working_trees=make_working_trees, shared_repo=shared_repo,
258
except errors.ErrorFromSmartServer, err:
259
_translate_error(err, path=path)
260
repo_path = response[0]
261
bzrdir_name = response[6]
262
require_stacking = response[7]
263
require_stacking = self.parse_NoneTrueFalse(require_stacking)
264
format = RemoteBzrDirFormat()
265
format._network_name = bzrdir_name
266
self._supply_sub_formats_to(format)
267
bzrdir = RemoteBzrDir(transport, format, _client=client)
269
repo_format = response_tuple_to_repo_format(response[1:])
273
repo_bzrdir_format = RemoteBzrDirFormat()
274
repo_bzrdir_format._network_name = response[5]
275
repo_bzr = RemoteBzrDir(transport.clone(repo_path),
279
final_stack = response[8] or None
280
final_stack_pwd = response[9] or None
282
final_stack_pwd = urlutils.join(
283
transport.base, final_stack_pwd)
284
remote_repo = RemoteRepository(repo_bzr, repo_format)
285
if len(response) > 10:
286
# Updated server verb that locks remotely.
287
repo_lock_token = response[10] or None
288
remote_repo.lock_write(repo_lock_token, _skip_rpc=True)
290
remote_repo.dont_leave_lock_in_place()
292
remote_repo.lock_write()
293
policy = _mod_bzrdir.UseExistingRepository(remote_repo, final_stack,
294
final_stack_pwd, require_stacking)
295
policy.acquire_repository()
299
bzrdir._format.set_branch_format(self.get_branch_format())
301
# The repo has already been created, but we need to make sure that
302
# we'll make a stackable branch.
303
bzrdir._format.require_stacking(_skip_repo=True)
304
return remote_repo, bzrdir, require_stacking, policy
306
def _open(self, transport):
307
return RemoteBzrDir(transport, self)
309
def __eq__(self, other):
310
if not isinstance(other, RemoteBzrDirFormat):
312
return self.get_format_description() == other.get_format_description()
314
def __return_repository_format(self):
315
# Always return a RemoteRepositoryFormat object, but if a specific bzr
316
# repository format has been asked for, tell the RemoteRepositoryFormat
317
# that it should use that for init() etc.
318
result = RemoteRepositoryFormat()
319
custom_format = getattr(self, '_repository_format', None)
321
if isinstance(custom_format, RemoteRepositoryFormat):
324
# We will use the custom format to create repositories over the
325
# wire; expose its details like rich_root_data for code to
327
result._custom_format = custom_format
330
def get_branch_format(self):
331
result = _mod_bzrdir.BzrDirMetaFormat1.get_branch_format(self)
332
if not isinstance(result, RemoteBranchFormat):
333
new_result = RemoteBranchFormat()
334
new_result._custom_format = result
336
self.set_branch_format(new_result)
340
repository_format = property(__return_repository_format,
341
_mod_bzrdir.BzrDirMetaFormat1._set_repository_format) #.im_func)
344
class RemoteControlStore(config.IniFileStore):
345
"""Control store which attempts to use HPSS calls to retrieve control store.
347
Note that this is specific to bzr-based formats.
350
def __init__(self, bzrdir):
351
super(RemoteControlStore, self).__init__()
353
self._real_store = None
355
def lock_write(self, token=None):
357
return self._real_store.lock_write(token)
361
return self._real_store.unlock()
365
# We need to be able to override the undecorated implementation
366
self.save_without_locking()
368
def save_without_locking(self):
369
super(RemoteControlStore, self).save()
371
def _ensure_real(self):
372
self.bzrdir._ensure_real()
373
if self._real_store is None:
374
self._real_store = config.ControlStore(self.bzrdir)
376
def external_url(self):
377
return self.bzrdir.user_url
379
def _load_content(self):
380
medium = self.bzrdir._client._medium
381
path = self.bzrdir._path_for_remote_call(self.bzrdir._client)
383
response, handler = self.bzrdir._call_expecting_body(
384
'BzrDir.get_config_file', path)
385
except errors.UnknownSmartMethod:
387
return self._real_store._load_content()
388
if len(response) and response[0] != 'ok':
389
raise errors.UnexpectedSmartServerResponse(response)
390
return handler.read_body_bytes()
392
def _save_content(self, content):
393
# FIXME JRV 2011-11-22: Ideally this should use a
394
# HPSS call too, but at the moment it is not possible
395
# to write lock control directories.
397
return self._real_store._save_content(content)
400
class RemoteBzrDir(_mod_bzrdir.BzrDir, _RpcHelper):
92
401
"""Control directory on a remote server, accessed via bzr:// or similar."""
94
403
def __init__(self, transport, format, _client=None, _force_probe=False):
1195
1668
raise errors.UnexpectedSmartServerResponse(response)
1197
1671
def sprout(self, to_bzrdir, revision_id=None):
1198
# TODO: Option to control what format is created?
1200
dest_repo = self._real_repository._format.initialize(to_bzrdir,
1672
"""Create a descendent repository for new development.
1674
Unlike clone, this does not copy the settings of the repository.
1676
dest_repo = self._create_sprouting_repo(to_bzrdir, shared=False)
1202
1677
dest_repo.fetch(self, revision_id=revision_id)
1203
1678
return dest_repo
1680
def _create_sprouting_repo(self, a_bzrdir, shared):
1681
if not isinstance(a_bzrdir._format, self.bzrdir._format.__class__):
1682
# use target default format.
1683
dest_repo = a_bzrdir.create_repository()
1685
# Most control formats need the repository to be specifically
1686
# created, but on some old all-in-one formats it's not needed
1688
dest_repo = self._format.initialize(a_bzrdir, shared=shared)
1689
except errors.UninitializableFormat:
1690
dest_repo = a_bzrdir.open_repository()
1205
1693
### These methods are just thin shims to the VFS object for now.
1207
1696
def revision_tree(self, revision_id):
1209
return self._real_repository.revision_tree(revision_id)
1697
revision_id = _mod_revision.ensure_null(revision_id)
1698
if revision_id == _mod_revision.NULL_REVISION:
1699
return InventoryRevisionTree(self,
1700
Inventory(root_id=None), _mod_revision.NULL_REVISION)
1702
return list(self.revision_trees([revision_id]))[0]
1211
1704
def get_serializer_format(self):
1213
return self._real_repository.get_serializer_format()
1705
path = self.bzrdir._path_for_remote_call(self._client)
1707
response = self._call('VersionedFileRepository.get_serializer_format',
1709
except errors.UnknownSmartMethod:
1711
return self._real_repository.get_serializer_format()
1712
if response[0] != 'ok':
1713
raise errors.UnexpectedSmartServerResponse(response)
1215
1716
def get_commit_builder(self, branch, parents, config, timestamp=None,
1216
1717
timezone=None, committer=None, revprops=None,
1718
revision_id=None, lossy=False):
1218
1719
# FIXME: It ought to be possible to call this without immediately
1219
1720
# triggering _ensure_real. For now it's the easiest thing to do.
1220
1721
self._ensure_real()
1221
1722
real_repo = self._real_repository
1222
1723
builder = real_repo.get_commit_builder(branch, parents,
1223
1724
config, timestamp=timestamp, timezone=timezone,
1224
committer=committer, revprops=revprops, revision_id=revision_id)
1725
committer=committer, revprops=revprops,
1726
revision_id=revision_id, lossy=lossy)
1227
1729
def add_fallback_repository(self, repository):
1696
2246
def _serializer(self):
1697
2247
return self._format._serializer
1699
2250
def store_revision_signature(self, gpg_strategy, plaintext, revision_id):
1701
return self._real_repository.store_revision_signature(
1702
gpg_strategy, plaintext, revision_id)
2251
signature = gpg_strategy.sign(plaintext)
2252
self.add_signature_text(revision_id, signature)
1704
2254
def add_signature_text(self, revision_id, signature):
1706
return self._real_repository.add_signature_text(revision_id, signature)
2255
if self._real_repository:
2256
# If there is a real repository the write group will
2257
# be in the real repository as well, so use that:
2259
return self._real_repository.add_signature_text(
2260
revision_id, signature)
2261
path = self.bzrdir._path_for_remote_call(self._client)
2262
response, response_handler = self._call_with_body_bytes(
2263
'Repository.add_signature_text', (path, revision_id),
2266
if response[0] != 'ok':
2267
raise errors.UnexpectedSmartServerResponse(response)
1708
2269
def has_signature_for_revision_id(self, revision_id):
1710
return self._real_repository.has_signature_for_revision_id(revision_id)
2270
path = self.bzrdir._path_for_remote_call(self._client)
2272
response = self._call('Repository.has_signature_for_revision_id',
2274
except errors.UnknownSmartMethod:
2276
return self._real_repository.has_signature_for_revision_id(
2278
if response[0] not in ('yes', 'no'):
2279
raise SmartProtocolError('unexpected response code %s' % (response,))
2280
return (response[0] == 'yes')
2283
def verify_revision_signature(self, revision_id, gpg_strategy):
2284
if not self.has_signature_for_revision_id(revision_id):
2285
return gpg.SIGNATURE_NOT_SIGNED, None
2286
signature = self.get_signature_text(revision_id)
2288
testament = _mod_testament.Testament.from_revision(self, revision_id)
2289
plaintext = testament.as_short_text()
2291
return gpg_strategy.verify(signature, plaintext)
1712
2293
def item_keys_introduced_by(self, revision_ids, _files_pb=None):
1713
2294
self._ensure_real()
1714
2295
return self._real_repository.item_keys_introduced_by(revision_ids,
1715
2296
_files_pb=_files_pb)
1717
def revision_graph_can_have_wrong_parents(self):
1718
# The answer depends on the remote repo format.
1720
return self._real_repository.revision_graph_can_have_wrong_parents()
1722
2298
def _find_inconsistent_revision_parents(self, revisions_iterator=None):
1723
2299
self._ensure_real()
1724
2300
return self._real_repository._find_inconsistent_revision_parents(
2071
2658
if isinstance(a_bzrdir, RemoteBzrDir):
2072
2659
a_bzrdir._ensure_real()
2073
2660
result = self._custom_format.initialize(a_bzrdir._real_bzrdir,
2661
name, append_revisions_only=append_revisions_only)
2076
2663
# We assume the bzrdir is parameterised; it may not be.
2077
result = self._custom_format.initialize(a_bzrdir, name)
2664
result = self._custom_format.initialize(a_bzrdir, name,
2665
append_revisions_only=append_revisions_only)
2078
2666
if (isinstance(a_bzrdir, RemoteBzrDir) and
2079
2667
not isinstance(result, RemoteBranch)):
2080
2668
result = RemoteBranch(a_bzrdir, a_bzrdir.find_repository(), result,
2084
def initialize(self, a_bzrdir, name=None):
2672
def initialize(self, a_bzrdir, name=None, repository=None,
2673
append_revisions_only=None):
2085
2674
# 1) get the network name to use.
2086
2675
if self._custom_format:
2087
2676
network_name = self._custom_format.network_name()
2089
2678
# Select the current bzrlib default and ask for that.
2090
reference_bzrdir_format = bzrdir.format_registry.get('default')()
2679
reference_bzrdir_format = _mod_bzrdir.format_registry.get('default')()
2091
2680
reference_format = reference_bzrdir_format.get_branch_format()
2092
2681
self._custom_format = reference_format
2093
2682
network_name = reference_format.network_name()
2094
2683
# Being asked to create on a non RemoteBzrDir:
2095
2684
if not isinstance(a_bzrdir, RemoteBzrDir):
2096
return self._vfs_initialize(a_bzrdir, name=name)
2685
return self._vfs_initialize(a_bzrdir, name=name,
2686
append_revisions_only=append_revisions_only)
2097
2687
medium = a_bzrdir._client._medium
2098
2688
if medium._is_remote_before((1, 13)):
2099
return self._vfs_initialize(a_bzrdir, name=name)
2689
return self._vfs_initialize(a_bzrdir, name=name,
2690
append_revisions_only=append_revisions_only)
2100
2691
# Creating on a remote bzr dir.
2101
2692
# 2) try direct creation via RPC
2102
2693
path = a_bzrdir._path_for_remote_call(a_bzrdir._client)
2148
2754
self._ensure_real()
2149
2755
return self._custom_format.supports_set_append_revisions_only()
2757
def _use_default_local_heads_to_fetch(self):
2758
# If the branch format is a metadir format *and* its heads_to_fetch
2759
# implementation is not overridden vs the base class, we can use the
2760
# base class logic rather than use the heads_to_fetch RPC. This is
2761
# usually cheaper in terms of net round trips, as the last-revision and
2762
# tags info fetched is cached and would be fetched anyway.
2764
if isinstance(self._custom_format, branch.BranchFormatMetadir):
2765
branch_class = self._custom_format._branch_class()
2766
heads_to_fetch_impl = branch_class.heads_to_fetch.im_func
2767
if heads_to_fetch_impl is branch.Branch.heads_to_fetch.im_func:
2772
class RemoteBranchStore(config.IniFileStore):
2773
"""Branch store which attempts to use HPSS calls to retrieve branch store.
2775
Note that this is specific to bzr-based formats.
2778
def __init__(self, branch):
2779
super(RemoteBranchStore, self).__init__()
2780
self.branch = branch
2782
self._real_store = None
2784
def lock_write(self, token=None):
2785
return self.branch.lock_write(token)
2788
return self.branch.unlock()
2792
# We need to be able to override the undecorated implementation
2793
self.save_without_locking()
2795
def save_without_locking(self):
2796
super(RemoteBranchStore, self).save()
2798
def external_url(self):
2799
return self.branch.user_url
2801
def _load_content(self):
2802
path = self.branch._remote_path()
2804
response, handler = self.branch._call_expecting_body(
2805
'Branch.get_config_file', path)
2806
except errors.UnknownSmartMethod:
2808
return self._real_store._load_content()
2809
if len(response) and response[0] != 'ok':
2810
raise errors.UnexpectedSmartServerResponse(response)
2811
return handler.read_body_bytes()
2813
def _save_content(self, content):
2814
path = self.branch._remote_path()
2816
response, handler = self.branch._call_with_body_bytes_expecting_body(
2817
'Branch.put_config_file', (path,
2818
self.branch._lock_token, self.branch._repo_lock_token),
2820
except errors.UnknownSmartMethod:
2822
return self._real_store._save_content(content)
2823
handler.cancel_read_body()
2824
if response != ('ok', ):
2825
raise errors.UnexpectedSmartServerResponse(response)
2827
def _ensure_real(self):
2828
self.branch._ensure_real()
2829
if self._real_store is None:
2830
self._real_store = config.BranchStore(self.branch)
2152
2833
class RemoteBranch(branch.Branch, _RpcHelper, lock._RelockDebugMixin):
2153
2834
"""Branch stored on a server accessed by HPSS RPC.
2654
3390
_override_hook_target=self, **kwargs)
2656
3392
@needs_read_lock
2657
def push(self, target, overwrite=False, stop_revision=None):
3393
def push(self, target, overwrite=False, stop_revision=None, lossy=False):
2658
3394
self._ensure_real()
2659
3395
return self._real_branch.push(
2660
target, overwrite=overwrite, stop_revision=stop_revision,
3396
target, overwrite=overwrite, stop_revision=stop_revision, lossy=lossy,
2661
3397
_override_hook_source_branch=self)
2663
3399
def is_locked(self):
2664
3400
return self._lock_count >= 1
2666
3402
@needs_read_lock
3403
def revision_id_to_dotted_revno(self, revision_id):
3404
"""Given a revision id, return its dotted revno.
3406
:return: a tuple like (1,) or (400,1,3).
3409
response = self._call('Branch.revision_id_to_revno',
3410
self._remote_path(), revision_id)
3411
except errors.UnknownSmartMethod:
3413
return self._real_branch.revision_id_to_dotted_revno(revision_id)
3414
if response[0] == 'ok':
3415
return tuple([int(x) for x in response[1:]])
3417
raise errors.UnexpectedSmartServerResponse(response)
2667
3420
def revision_id_to_revno(self, revision_id):
2669
return self._real_branch.revision_id_to_revno(revision_id)
3421
"""Given a revision id on the branch mainline, return its revno.
3426
response = self._call('Branch.revision_id_to_revno',
3427
self._remote_path(), revision_id)
3428
except errors.UnknownSmartMethod:
3430
return self._real_branch.revision_id_to_revno(revision_id)
3431
if response[0] == 'ok':
3432
if len(response) == 2:
3433
return int(response[1])
3434
raise NoSuchRevision(self, revision_id)
3436
raise errors.UnexpectedSmartServerResponse(response)
2671
3438
@needs_write_lock
2672
3439
def set_last_revision_info(self, revno, revision_id):
2673
3440
# XXX: These should be returned by the set_last_revision_info verb
2674
3441
old_revno, old_revid = self.last_revision_info()
2675
3442
self._run_pre_change_branch_tip_hooks(revno, revision_id)
2676
revision_id = ensure_null(revision_id)
3443
if not revision_id or not isinstance(revision_id, basestring):
3444
raise errors.InvalidRevisionId(revision_id=revision_id, branch=self)
2678
3446
response = self._call('Branch.set_last_revision_info',
2679
3447
self._remote_path(), self._lock_token, self._repo_lock_token,
2774
3579
medium = self._branch._client._medium
2775
3580
if medium._is_remote_before((1, 14)):
2776
3581
return self._vfs_set_option(value, name, section)
3582
if isinstance(value, dict):
3583
if medium._is_remote_before((2, 2)):
3584
return self._vfs_set_option(value, name, section)
3585
return self._set_config_option_dict(value, name, section)
3587
return self._set_config_option(value, name, section)
3589
def _set_config_option(self, value, name, section):
2778
3591
path = self._branch._remote_path()
2779
3592
response = self._branch._client.call('Branch.set_config_option',
2780
3593
path, self._branch._lock_token, self._branch._repo_lock_token,
2781
3594
value.encode('utf8'), name, section or '')
2782
3595
except errors.UnknownSmartMethod:
3596
medium = self._branch._client._medium
2783
3597
medium._remember_remote_is_before((1, 14))
2784
3598
return self._vfs_set_option(value, name, section)
2785
3599
if response != ():
2786
3600
raise errors.UnexpectedSmartServerResponse(response)
3602
def _serialize_option_dict(self, option_dict):
3604
for key, value in option_dict.items():
3605
if isinstance(key, unicode):
3606
key = key.encode('utf8')
3607
if isinstance(value, unicode):
3608
value = value.encode('utf8')
3609
utf8_dict[key] = value
3610
return bencode.bencode(utf8_dict)
3612
def _set_config_option_dict(self, value, name, section):
3614
path = self._branch._remote_path()
3615
serialised_dict = self._serialize_option_dict(value)
3616
response = self._branch._client.call(
3617
'Branch.set_config_option_dict',
3618
path, self._branch._lock_token, self._branch._repo_lock_token,
3619
serialised_dict, name, section or '')
3620
except errors.UnknownSmartMethod:
3621
medium = self._branch._client._medium
3622
medium._remember_remote_is_before((2, 2))
3623
return self._vfs_set_option(value, name, section)
3625
raise errors.UnexpectedSmartServerResponse(response)
2788
3627
def _real_object(self):
2789
3628
self._branch._ensure_real()
2790
3629
return self._branch._real_branch
2873
3716
'Missing key %r in context %r', key_err.args[0], context)
2876
if err.error_verb == 'IncompatibleRepositories':
2877
raise errors.IncompatibleRepositories(err.error_args[0],
2878
err.error_args[1], err.error_args[2])
2879
elif err.error_verb == 'NoSuchRevision':
2880
raise NoSuchRevision(find('branch'), err.error_args[0])
2881
elif err.error_verb == 'nosuchrevision':
2882
raise NoSuchRevision(find('repository'), err.error_args[0])
2883
elif err.error_verb == 'nobranch':
2884
if len(err.error_args) >= 1:
2885
extra = err.error_args[0]
2888
raise errors.NotBranchError(path=find('bzrdir').root_transport.base,
2890
elif err.error_verb == 'norepository':
2891
raise errors.NoRepositoryPresent(find('bzrdir'))
2892
elif err.error_verb == 'LockContention':
2893
raise errors.LockContention('(remote lock)')
2894
elif err.error_verb == 'UnlockableTransport':
2895
raise errors.UnlockableTransport(find('bzrdir').root_transport)
2896
elif err.error_verb == 'LockFailed':
2897
raise errors.LockFailed(err.error_args[0], err.error_args[1])
2898
elif err.error_verb == 'TokenMismatch':
2899
raise errors.TokenMismatch(find('token'), '(remote token)')
2900
elif err.error_verb == 'Diverged':
2901
raise errors.DivergedBranches(find('branch'), find('other_branch'))
2902
elif err.error_verb == 'TipChangeRejected':
2903
raise errors.TipChangeRejected(err.error_args[0].decode('utf8'))
2904
elif err.error_verb == 'UnstackableBranchFormat':
2905
raise errors.UnstackableBranchFormat(*err.error_args)
2906
elif err.error_verb == 'UnstackableRepositoryFormat':
2907
raise errors.UnstackableRepositoryFormat(*err.error_args)
2908
elif err.error_verb == 'NotStacked':
2909
raise errors.NotStacked(branch=find('branch'))
2910
elif err.error_verb == 'PermissionDenied':
2912
if len(err.error_args) >= 2:
2913
extra = err.error_args[1]
2916
raise errors.PermissionDenied(path, extra=extra)
2917
elif err.error_verb == 'ReadError':
2919
raise errors.ReadError(path)
2920
elif err.error_verb == 'NoSuchFile':
2922
raise errors.NoSuchFile(path)
2923
elif err.error_verb == 'FileExists':
2924
raise errors.FileExists(err.error_args[0])
2925
elif err.error_verb == 'DirectoryNotEmpty':
2926
raise errors.DirectoryNotEmpty(err.error_args[0])
2927
elif err.error_verb == 'ShortReadvError':
2928
args = err.error_args
2929
raise errors.ShortReadvError(
2930
args[0], int(args[1]), int(args[2]), int(args[3]))
2931
elif err.error_verb in ('UnicodeEncodeError', 'UnicodeDecodeError'):
3720
translator = error_translators.get(err.error_verb)
3724
raise translator(err, find, get_path)
3726
translator = no_context_error_translators.get(err.error_verb)
3728
raise errors.UnknownErrorFromSmartServer(err)
3730
raise translator(err)
3733
error_translators.register('NoSuchRevision',
3734
lambda err, find, get_path: NoSuchRevision(
3735
find('branch'), err.error_args[0]))
3736
error_translators.register('nosuchrevision',
3737
lambda err, find, get_path: NoSuchRevision(
3738
find('repository'), err.error_args[0]))
3740
def _translate_nobranch_error(err, find, get_path):
3741
if len(err.error_args) >= 1:
3742
extra = err.error_args[0]
3745
return errors.NotBranchError(path=find('bzrdir').root_transport.base,
3748
error_translators.register('nobranch', _translate_nobranch_error)
3749
error_translators.register('norepository',
3750
lambda err, find, get_path: errors.NoRepositoryPresent(
3752
error_translators.register('UnlockableTransport',
3753
lambda err, find, get_path: errors.UnlockableTransport(
3754
find('bzrdir').root_transport))
3755
error_translators.register('TokenMismatch',
3756
lambda err, find, get_path: errors.TokenMismatch(
3757
find('token'), '(remote token)'))
3758
error_translators.register('Diverged',
3759
lambda err, find, get_path: errors.DivergedBranches(
3760
find('branch'), find('other_branch')))
3761
error_translators.register('NotStacked',
3762
lambda err, find, get_path: errors.NotStacked(branch=find('branch')))
3764
def _translate_PermissionDenied(err, find, get_path):
3766
if len(err.error_args) >= 2:
3767
extra = err.error_args[1]
3770
return errors.PermissionDenied(path, extra=extra)
3772
error_translators.register('PermissionDenied', _translate_PermissionDenied)
3773
error_translators.register('ReadError',
3774
lambda err, find, get_path: errors.ReadError(get_path()))
3775
error_translators.register('NoSuchFile',
3776
lambda err, find, get_path: errors.NoSuchFile(get_path()))
3777
no_context_error_translators.register('IncompatibleRepositories',
3778
lambda err: errors.IncompatibleRepositories(
3779
err.error_args[0], err.error_args[1], err.error_args[2]))
3780
no_context_error_translators.register('LockContention',
3781
lambda err: errors.LockContention('(remote lock)'))
3782
no_context_error_translators.register('LockFailed',
3783
lambda err: errors.LockFailed(err.error_args[0], err.error_args[1]))
3784
no_context_error_translators.register('TipChangeRejected',
3785
lambda err: errors.TipChangeRejected(err.error_args[0].decode('utf8')))
3786
no_context_error_translators.register('UnstackableBranchFormat',
3787
lambda err: errors.UnstackableBranchFormat(*err.error_args))
3788
no_context_error_translators.register('UnstackableRepositoryFormat',
3789
lambda err: errors.UnstackableRepositoryFormat(*err.error_args))
3790
no_context_error_translators.register('FileExists',
3791
lambda err: errors.FileExists(err.error_args[0]))
3792
no_context_error_translators.register('DirectoryNotEmpty',
3793
lambda err: errors.DirectoryNotEmpty(err.error_args[0]))
3795
def _translate_short_readv_error(err):
3796
args = err.error_args
3797
return errors.ShortReadvError(args[0], int(args[1]), int(args[2]),
3800
no_context_error_translators.register('ShortReadvError',
3801
_translate_short_readv_error)
3803
def _translate_unicode_error(err):
2932
3804
encoding = str(err.error_args[0]) # encoding must always be a string
2933
3805
val = err.error_args[1]
2934
3806
start = int(err.error_args[2])