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:
122
real_format = controldir.network_format_registry.get(self._network_name)
123
return 'Remote: ' + real_format.get_format_description()
124
return 'bzr remote bzrdir'
126
def get_format_string(self):
127
raise NotImplementedError(self.get_format_string)
129
def network_name(self):
130
if self._network_name:
131
return self._network_name
133
raise AssertionError("No network name set.")
135
def initialize_on_transport(self, transport):
137
# hand off the request to the smart server
138
client_medium = transport.get_smart_medium()
139
except errors.NoSmartMedium:
140
# TODO: lookup the local format from a server hint.
141
local_dir_format = _mod_bzrdir.BzrDirMetaFormat1()
142
return local_dir_format.initialize_on_transport(transport)
143
client = _SmartClient(client_medium)
144
path = client.remote_path_from_transport(transport)
146
response = client.call('BzrDirFormat.initialize', path)
147
except errors.ErrorFromSmartServer, err:
148
_translate_error(err, path=path)
149
if response[0] != 'ok':
150
raise errors.SmartProtocolError('unexpected response code %s' % (response,))
151
format = RemoteBzrDirFormat()
152
self._supply_sub_formats_to(format)
153
return RemoteBzrDir(transport, format)
155
def parse_NoneTrueFalse(self, arg):
162
raise AssertionError("invalid arg %r" % arg)
164
def _serialize_NoneTrueFalse(self, arg):
171
def _serialize_NoneString(self, arg):
174
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
175
create_prefix=False, force_new_repo=False, stacked_on=None,
176
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
179
# hand off the request to the smart server
180
client_medium = transport.get_smart_medium()
181
except errors.NoSmartMedium:
184
# Decline to open it if the server doesn't support our required
185
# version (3) so that the VFS-based transport will do it.
186
if client_medium.should_probe():
188
server_version = client_medium.protocol_version()
189
if server_version != '2':
193
except errors.SmartProtocolError:
194
# Apparently there's no usable smart server there, even though
195
# the medium supports the smart protocol.
200
client = _SmartClient(client_medium)
201
path = client.remote_path_from_transport(transport)
202
if client_medium._is_remote_before((1, 16)):
205
# TODO: lookup the local format from a server hint.
206
local_dir_format = _mod_bzrdir.BzrDirMetaFormat1()
207
self._supply_sub_formats_to(local_dir_format)
208
return local_dir_format.initialize_on_transport_ex(transport,
209
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
210
force_new_repo=force_new_repo, stacked_on=stacked_on,
211
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
212
make_working_trees=make_working_trees, shared_repo=shared_repo,
214
return self._initialize_on_transport_ex_rpc(client, path, transport,
215
use_existing_dir, create_prefix, force_new_repo, stacked_on,
216
stack_on_pwd, repo_format_name, make_working_trees, shared_repo)
218
def _initialize_on_transport_ex_rpc(self, client, path, transport,
219
use_existing_dir, create_prefix, force_new_repo, stacked_on,
220
stack_on_pwd, repo_format_name, make_working_trees, shared_repo):
222
args.append(self._serialize_NoneTrueFalse(use_existing_dir))
223
args.append(self._serialize_NoneTrueFalse(create_prefix))
224
args.append(self._serialize_NoneTrueFalse(force_new_repo))
225
args.append(self._serialize_NoneString(stacked_on))
226
# stack_on_pwd is often/usually our transport
229
stack_on_pwd = transport.relpath(stack_on_pwd)
232
except errors.PathNotChild:
234
args.append(self._serialize_NoneString(stack_on_pwd))
235
args.append(self._serialize_NoneString(repo_format_name))
236
args.append(self._serialize_NoneTrueFalse(make_working_trees))
237
args.append(self._serialize_NoneTrueFalse(shared_repo))
238
request_network_name = self._network_name or \
239
_mod_bzrdir.BzrDirFormat.get_default_format().network_name()
241
response = client.call('BzrDirFormat.initialize_ex_1.16',
242
request_network_name, path, *args)
243
except errors.UnknownSmartMethod:
244
client._medium._remember_remote_is_before((1,16))
245
local_dir_format = _mod_bzrdir.BzrDirMetaFormat1()
246
self._supply_sub_formats_to(local_dir_format)
247
return local_dir_format.initialize_on_transport_ex(transport,
248
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
249
force_new_repo=force_new_repo, stacked_on=stacked_on,
250
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
251
make_working_trees=make_working_trees, shared_repo=shared_repo,
253
except errors.ErrorFromSmartServer, err:
254
_translate_error(err, path=path)
255
repo_path = response[0]
256
bzrdir_name = response[6]
257
require_stacking = response[7]
258
require_stacking = self.parse_NoneTrueFalse(require_stacking)
259
format = RemoteBzrDirFormat()
260
format._network_name = bzrdir_name
261
self._supply_sub_formats_to(format)
262
bzrdir = RemoteBzrDir(transport, format, _client=client)
264
repo_format = response_tuple_to_repo_format(response[1:])
268
repo_bzrdir_format = RemoteBzrDirFormat()
269
repo_bzrdir_format._network_name = response[5]
270
repo_bzr = RemoteBzrDir(transport.clone(repo_path),
274
final_stack = response[8] or None
275
final_stack_pwd = response[9] or None
277
final_stack_pwd = urlutils.join(
278
transport.base, final_stack_pwd)
279
remote_repo = RemoteRepository(repo_bzr, repo_format)
280
if len(response) > 10:
281
# Updated server verb that locks remotely.
282
repo_lock_token = response[10] or None
283
remote_repo.lock_write(repo_lock_token, _skip_rpc=True)
285
remote_repo.dont_leave_lock_in_place()
287
remote_repo.lock_write()
288
policy = _mod_bzrdir.UseExistingRepository(remote_repo, final_stack,
289
final_stack_pwd, require_stacking)
290
policy.acquire_repository()
294
bzrdir._format.set_branch_format(self.get_branch_format())
296
# The repo has already been created, but we need to make sure that
297
# we'll make a stackable branch.
298
bzrdir._format.require_stacking(_skip_repo=True)
299
return remote_repo, bzrdir, require_stacking, policy
301
def _open(self, transport):
302
return RemoteBzrDir(transport, self)
304
def __eq__(self, other):
305
if not isinstance(other, RemoteBzrDirFormat):
307
return self.get_format_description() == other.get_format_description()
309
def __return_repository_format(self):
310
# Always return a RemoteRepositoryFormat object, but if a specific bzr
311
# repository format has been asked for, tell the RemoteRepositoryFormat
312
# that it should use that for init() etc.
313
result = RemoteRepositoryFormat()
314
custom_format = getattr(self, '_repository_format', None)
316
if isinstance(custom_format, RemoteRepositoryFormat):
319
# We will use the custom format to create repositories over the
320
# wire; expose its details like rich_root_data for code to
322
result._custom_format = custom_format
325
def get_branch_format(self):
326
result = _mod_bzrdir.BzrDirMetaFormat1.get_branch_format(self)
327
if not isinstance(result, RemoteBranchFormat):
328
new_result = RemoteBranchFormat()
329
new_result._custom_format = result
331
self.set_branch_format(new_result)
335
repository_format = property(__return_repository_format,
336
_mod_bzrdir.BzrDirMetaFormat1._set_repository_format) #.im_func)
339
class RemoteControlStore(config.IniFileStore):
340
"""Control store which attempts to use HPSS calls to retrieve control store.
342
Note that this is specific to bzr-based formats.
345
def __init__(self, bzrdir):
346
super(RemoteControlStore, self).__init__()
348
self._real_store = None
350
def lock_write(self, token=None):
352
return self._real_store.lock_write(token)
356
return self._real_store.unlock()
360
# We need to be able to override the undecorated implementation
361
self.save_without_locking()
363
def save_without_locking(self):
364
super(RemoteControlStore, self).save()
366
def _ensure_real(self):
367
self.bzrdir._ensure_real()
368
if self._real_store is None:
369
self._real_store = config.ControlStore(self.bzrdir)
371
def external_url(self):
372
return self.bzrdir.user_url
374
def _load_content(self):
375
medium = self.bzrdir._client._medium
376
path = self.bzrdir._path_for_remote_call(self.bzrdir._client)
378
response, handler = self.bzrdir._call_expecting_body(
379
'BzrDir.get_config_file', path)
380
except errors.UnknownSmartMethod:
382
return self._real_store._load_content()
383
if len(response) and response[0] != 'ok':
384
raise errors.UnexpectedSmartServerResponse(response)
385
return handler.read_body_bytes()
387
def _save_content(self, content):
388
# FIXME JRV 2011-11-22: Ideally this should use a
389
# HPSS call too, but at the moment it is not possible
390
# to write lock control directories.
392
return self._real_store._save_content(content)
395
class RemoteBzrDir(_mod_bzrdir.BzrDir, _RpcHelper):
92
396
"""Control directory on a remote server, accessed via bzr:// or similar."""
94
398
def __init__(self, transport, format, _client=None, _force_probe=False):
1195
1644
raise errors.UnexpectedSmartServerResponse(response)
1197
1647
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,
1648
"""Create a descendent repository for new development.
1650
Unlike clone, this does not copy the settings of the repository.
1652
dest_repo = self._create_sprouting_repo(to_bzrdir, shared=False)
1202
1653
dest_repo.fetch(self, revision_id=revision_id)
1203
1654
return dest_repo
1656
def _create_sprouting_repo(self, a_bzrdir, shared):
1657
if not isinstance(a_bzrdir._format, self.bzrdir._format.__class__):
1658
# use target default format.
1659
dest_repo = a_bzrdir.create_repository()
1661
# Most control formats need the repository to be specifically
1662
# created, but on some old all-in-one formats it's not needed
1664
dest_repo = self._format.initialize(a_bzrdir, shared=shared)
1665
except errors.UninitializableFormat:
1666
dest_repo = a_bzrdir.open_repository()
1205
1669
### These methods are just thin shims to the VFS object for now.
1207
1672
def revision_tree(self, revision_id):
1209
return self._real_repository.revision_tree(revision_id)
1673
revision_id = _mod_revision.ensure_null(revision_id)
1674
if revision_id == _mod_revision.NULL_REVISION:
1675
return InventoryRevisionTree(self,
1676
Inventory(root_id=None), _mod_revision.NULL_REVISION)
1678
return list(self.revision_trees([revision_id]))[0]
1211
1680
def get_serializer_format(self):
1213
return self._real_repository.get_serializer_format()
1681
path = self.bzrdir._path_for_remote_call(self._client)
1683
response = self._call('VersionedFileRepository.get_serializer_format',
1685
except errors.UnknownSmartMethod:
1687
return self._real_repository.get_serializer_format()
1688
if response[0] != 'ok':
1689
raise errors.UnexpectedSmartServerResponse(response)
1215
1692
def get_commit_builder(self, branch, parents, config, timestamp=None,
1216
1693
timezone=None, committer=None, revprops=None,
1694
revision_id=None, lossy=False):
1218
1695
# FIXME: It ought to be possible to call this without immediately
1219
1696
# triggering _ensure_real. For now it's the easiest thing to do.
1220
1697
self._ensure_real()
1221
1698
real_repo = self._real_repository
1222
1699
builder = real_repo.get_commit_builder(branch, parents,
1223
1700
config, timestamp=timestamp, timezone=timezone,
1224
committer=committer, revprops=revprops, revision_id=revision_id)
1701
committer=committer, revprops=revprops,
1702
revision_id=revision_id, lossy=lossy)
1227
1705
def add_fallback_repository(self, repository):
1696
2222
def _serializer(self):
1697
2223
return self._format._serializer
1699
2226
def store_revision_signature(self, gpg_strategy, plaintext, revision_id):
1701
return self._real_repository.store_revision_signature(
1702
gpg_strategy, plaintext, revision_id)
2227
signature = gpg_strategy.sign(plaintext)
2228
self.add_signature_text(revision_id, signature)
1704
2230
def add_signature_text(self, revision_id, signature):
1706
return self._real_repository.add_signature_text(revision_id, signature)
2231
if self._real_repository:
2232
# If there is a real repository the write group will
2233
# be in the real repository as well, so use that:
2235
return self._real_repository.add_signature_text(
2236
revision_id, signature)
2237
path = self.bzrdir._path_for_remote_call(self._client)
2238
response, response_handler = self._call_with_body_bytes(
2239
'Repository.add_signature_text', (path, revision_id),
2242
if response[0] != 'ok':
2243
raise errors.UnexpectedSmartServerResponse(response)
1708
2245
def has_signature_for_revision_id(self, revision_id):
1710
return self._real_repository.has_signature_for_revision_id(revision_id)
2246
path = self.bzrdir._path_for_remote_call(self._client)
2248
response = self._call('Repository.has_signature_for_revision_id',
2250
except errors.UnknownSmartMethod:
2252
return self._real_repository.has_signature_for_revision_id(
2254
if response[0] not in ('yes', 'no'):
2255
raise SmartProtocolError('unexpected response code %s' % (response,))
2256
return (response[0] == 'yes')
2259
def verify_revision_signature(self, revision_id, gpg_strategy):
2260
if not self.has_signature_for_revision_id(revision_id):
2261
return gpg.SIGNATURE_NOT_SIGNED, None
2262
signature = self.get_signature_text(revision_id)
2264
testament = _mod_testament.Testament.from_revision(self, revision_id)
2265
plaintext = testament.as_short_text()
2267
return gpg_strategy.verify(signature, plaintext)
1712
2269
def item_keys_introduced_by(self, revision_ids, _files_pb=None):
1713
2270
self._ensure_real()
1714
2271
return self._real_repository.item_keys_introduced_by(revision_ids,
1715
2272
_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
2274
def _find_inconsistent_revision_parents(self, revisions_iterator=None):
1723
2275
self._ensure_real()
1724
2276
return self._real_repository._find_inconsistent_revision_parents(
2071
2630
if isinstance(a_bzrdir, RemoteBzrDir):
2072
2631
a_bzrdir._ensure_real()
2073
2632
result = self._custom_format.initialize(a_bzrdir._real_bzrdir,
2633
name, append_revisions_only=append_revisions_only)
2076
2635
# We assume the bzrdir is parameterised; it may not be.
2077
result = self._custom_format.initialize(a_bzrdir, name)
2636
result = self._custom_format.initialize(a_bzrdir, name,
2637
append_revisions_only=append_revisions_only)
2078
2638
if (isinstance(a_bzrdir, RemoteBzrDir) and
2079
2639
not isinstance(result, RemoteBranch)):
2080
2640
result = RemoteBranch(a_bzrdir, a_bzrdir.find_repository(), result,
2084
def initialize(self, a_bzrdir, name=None):
2644
def initialize(self, a_bzrdir, name=None, repository=None,
2645
append_revisions_only=None):
2085
2646
# 1) get the network name to use.
2086
2647
if self._custom_format:
2087
2648
network_name = self._custom_format.network_name()
2089
2650
# Select the current bzrlib default and ask for that.
2090
reference_bzrdir_format = bzrdir.format_registry.get('default')()
2651
reference_bzrdir_format = _mod_bzrdir.format_registry.get('default')()
2091
2652
reference_format = reference_bzrdir_format.get_branch_format()
2092
2653
self._custom_format = reference_format
2093
2654
network_name = reference_format.network_name()
2094
2655
# Being asked to create on a non RemoteBzrDir:
2095
2656
if not isinstance(a_bzrdir, RemoteBzrDir):
2096
return self._vfs_initialize(a_bzrdir, name=name)
2657
return self._vfs_initialize(a_bzrdir, name=name,
2658
append_revisions_only=append_revisions_only)
2097
2659
medium = a_bzrdir._client._medium
2098
2660
if medium._is_remote_before((1, 13)):
2099
return self._vfs_initialize(a_bzrdir, name=name)
2661
return self._vfs_initialize(a_bzrdir, name=name,
2662
append_revisions_only=append_revisions_only)
2100
2663
# Creating on a remote bzr dir.
2101
2664
# 2) try direct creation via RPC
2102
2665
path = a_bzrdir._path_for_remote_call(a_bzrdir._client)
2148
2726
self._ensure_real()
2149
2727
return self._custom_format.supports_set_append_revisions_only()
2729
def _use_default_local_heads_to_fetch(self):
2730
# If the branch format is a metadir format *and* its heads_to_fetch
2731
# implementation is not overridden vs the base class, we can use the
2732
# base class logic rather than use the heads_to_fetch RPC. This is
2733
# usually cheaper in terms of net round trips, as the last-revision and
2734
# tags info fetched is cached and would be fetched anyway.
2736
if isinstance(self._custom_format, branch.BranchFormatMetadir):
2737
branch_class = self._custom_format._branch_class()
2738
heads_to_fetch_impl = branch_class.heads_to_fetch.im_func
2739
if heads_to_fetch_impl is branch.Branch.heads_to_fetch.im_func:
2744
class RemoteBranchStore(config.IniFileStore):
2745
"""Branch store which attempts to use HPSS calls to retrieve branch store.
2747
Note that this is specific to bzr-based formats.
2750
def __init__(self, branch):
2751
super(RemoteBranchStore, self).__init__()
2752
self.branch = branch
2754
self._real_store = None
2756
def lock_write(self, token=None):
2757
return self.branch.lock_write(token)
2760
return self.branch.unlock()
2764
# We need to be able to override the undecorated implementation
2765
self.save_without_locking()
2767
def save_without_locking(self):
2768
super(RemoteBranchStore, self).save()
2770
def external_url(self):
2771
return self.branch.user_url
2773
def _load_content(self):
2774
path = self.branch._remote_path()
2776
response, handler = self.branch._call_expecting_body(
2777
'Branch.get_config_file', path)
2778
except errors.UnknownSmartMethod:
2780
return self._real_store._load_content()
2781
if len(response) and response[0] != 'ok':
2782
raise errors.UnexpectedSmartServerResponse(response)
2783
return handler.read_body_bytes()
2785
def _save_content(self, content):
2786
path = self.branch._remote_path()
2788
response, handler = self.branch._call_with_body_bytes_expecting_body(
2789
'Branch.put_config_file', (path,
2790
self.branch._lock_token, self.branch._repo_lock_token),
2792
except errors.UnknownSmartMethod:
2794
return self._real_store._save_content(content)
2795
handler.cancel_read_body()
2796
if response != ('ok', ):
2797
raise errors.UnexpectedSmartServerResponse(response)
2799
def _ensure_real(self):
2800
self.branch._ensure_real()
2801
if self._real_store is None:
2802
self._real_store = config.BranchStore(self.branch)
2152
2805
class RemoteBranch(branch.Branch, _RpcHelper, lock._RelockDebugMixin):
2153
2806
"""Branch stored on a server accessed by HPSS RPC.
2654
3355
_override_hook_target=self, **kwargs)
2656
3357
@needs_read_lock
2657
def push(self, target, overwrite=False, stop_revision=None):
3358
def push(self, target, overwrite=False, stop_revision=None, lossy=False):
2658
3359
self._ensure_real()
2659
3360
return self._real_branch.push(
2660
target, overwrite=overwrite, stop_revision=stop_revision,
3361
target, overwrite=overwrite, stop_revision=stop_revision, lossy=lossy,
2661
3362
_override_hook_source_branch=self)
2663
3364
def is_locked(self):
2664
3365
return self._lock_count >= 1
2666
3367
@needs_read_lock
3368
def revision_id_to_dotted_revno(self, revision_id):
3369
"""Given a revision id, return its dotted revno.
3371
:return: a tuple like (1,) or (400,1,3).
3374
response = self._call('Branch.revision_id_to_revno',
3375
self._remote_path(), revision_id)
3376
except errors.UnknownSmartMethod:
3378
return self._real_branch.revision_id_to_dotted_revno(revision_id)
3379
if response[0] == 'ok':
3380
return tuple([int(x) for x in response[1:]])
3382
raise errors.UnexpectedSmartServerResponse(response)
2667
3385
def revision_id_to_revno(self, revision_id):
2669
return self._real_branch.revision_id_to_revno(revision_id)
3386
"""Given a revision id on the branch mainline, return its revno.
3391
response = self._call('Branch.revision_id_to_revno',
3392
self._remote_path(), revision_id)
3393
except errors.UnknownSmartMethod:
3395
return self._real_branch.revision_id_to_revno(revision_id)
3396
if response[0] == 'ok':
3397
if len(response) == 2:
3398
return int(response[1])
3399
raise NoSuchRevision(self, revision_id)
3401
raise errors.UnexpectedSmartServerResponse(response)
2671
3403
@needs_write_lock
2672
3404
def set_last_revision_info(self, revno, revision_id):
2673
3405
# XXX: These should be returned by the set_last_revision_info verb
2674
3406
old_revno, old_revid = self.last_revision_info()
2675
3407
self._run_pre_change_branch_tip_hooks(revno, revision_id)
2676
revision_id = ensure_null(revision_id)
3408
if not revision_id or not isinstance(revision_id, basestring):
3409
raise errors.InvalidRevisionId(revision_id=revision_id, branch=self)
2678
3411
response = self._call('Branch.set_last_revision_info',
2679
3412
self._remote_path(), self._lock_token, self._repo_lock_token,
2774
3544
medium = self._branch._client._medium
2775
3545
if medium._is_remote_before((1, 14)):
2776
3546
return self._vfs_set_option(value, name, section)
3547
if isinstance(value, dict):
3548
if medium._is_remote_before((2, 2)):
3549
return self._vfs_set_option(value, name, section)
3550
return self._set_config_option_dict(value, name, section)
3552
return self._set_config_option(value, name, section)
3554
def _set_config_option(self, value, name, section):
2778
3556
path = self._branch._remote_path()
2779
3557
response = self._branch._client.call('Branch.set_config_option',
2780
3558
path, self._branch._lock_token, self._branch._repo_lock_token,
2781
3559
value.encode('utf8'), name, section or '')
2782
3560
except errors.UnknownSmartMethod:
3561
medium = self._branch._client._medium
2783
3562
medium._remember_remote_is_before((1, 14))
2784
3563
return self._vfs_set_option(value, name, section)
2785
3564
if response != ():
2786
3565
raise errors.UnexpectedSmartServerResponse(response)
3567
def _serialize_option_dict(self, option_dict):
3569
for key, value in option_dict.items():
3570
if isinstance(key, unicode):
3571
key = key.encode('utf8')
3572
if isinstance(value, unicode):
3573
value = value.encode('utf8')
3574
utf8_dict[key] = value
3575
return bencode.bencode(utf8_dict)
3577
def _set_config_option_dict(self, value, name, section):
3579
path = self._branch._remote_path()
3580
serialised_dict = self._serialize_option_dict(value)
3581
response = self._branch._client.call(
3582
'Branch.set_config_option_dict',
3583
path, self._branch._lock_token, self._branch._repo_lock_token,
3584
serialised_dict, name, section or '')
3585
except errors.UnknownSmartMethod:
3586
medium = self._branch._client._medium
3587
medium._remember_remote_is_before((2, 2))
3588
return self._vfs_set_option(value, name, section)
3590
raise errors.UnexpectedSmartServerResponse(response)
2788
3592
def _real_object(self):
2789
3593
self._branch._ensure_real()
2790
3594
return self._branch._real_branch
2873
3681
'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'):
3685
translator = error_translators.get(err.error_verb)
3689
raise translator(err, find, get_path)
3691
translator = no_context_error_translators.get(err.error_verb)
3693
raise errors.UnknownErrorFromSmartServer(err)
3695
raise translator(err)
3698
error_translators.register('NoSuchRevision',
3699
lambda err, find, get_path: NoSuchRevision(
3700
find('branch'), err.error_args[0]))
3701
error_translators.register('nosuchrevision',
3702
lambda err, find, get_path: NoSuchRevision(
3703
find('repository'), err.error_args[0]))
3705
def _translate_nobranch_error(err, find, get_path):
3706
if len(err.error_args) >= 1:
3707
extra = err.error_args[0]
3710
return errors.NotBranchError(path=find('bzrdir').root_transport.base,
3713
error_translators.register('nobranch', _translate_nobranch_error)
3714
error_translators.register('norepository',
3715
lambda err, find, get_path: errors.NoRepositoryPresent(
3717
error_translators.register('UnlockableTransport',
3718
lambda err, find, get_path: errors.UnlockableTransport(
3719
find('bzrdir').root_transport))
3720
error_translators.register('TokenMismatch',
3721
lambda err, find, get_path: errors.TokenMismatch(
3722
find('token'), '(remote token)'))
3723
error_translators.register('Diverged',
3724
lambda err, find, get_path: errors.DivergedBranches(
3725
find('branch'), find('other_branch')))
3726
error_translators.register('NotStacked',
3727
lambda err, find, get_path: errors.NotStacked(branch=find('branch')))
3729
def _translate_PermissionDenied(err, find, get_path):
3731
if len(err.error_args) >= 2:
3732
extra = err.error_args[1]
3735
return errors.PermissionDenied(path, extra=extra)
3737
error_translators.register('PermissionDenied', _translate_PermissionDenied)
3738
error_translators.register('ReadError',
3739
lambda err, find, get_path: errors.ReadError(get_path()))
3740
error_translators.register('NoSuchFile',
3741
lambda err, find, get_path: errors.NoSuchFile(get_path()))
3742
no_context_error_translators.register('IncompatibleRepositories',
3743
lambda err: errors.IncompatibleRepositories(
3744
err.error_args[0], err.error_args[1], err.error_args[2]))
3745
no_context_error_translators.register('LockContention',
3746
lambda err: errors.LockContention('(remote lock)'))
3747
no_context_error_translators.register('LockFailed',
3748
lambda err: errors.LockFailed(err.error_args[0], err.error_args[1]))
3749
no_context_error_translators.register('TipChangeRejected',
3750
lambda err: errors.TipChangeRejected(err.error_args[0].decode('utf8')))
3751
no_context_error_translators.register('UnstackableBranchFormat',
3752
lambda err: errors.UnstackableBranchFormat(*err.error_args))
3753
no_context_error_translators.register('UnstackableRepositoryFormat',
3754
lambda err: errors.UnstackableRepositoryFormat(*err.error_args))
3755
no_context_error_translators.register('FileExists',
3756
lambda err: errors.FileExists(err.error_args[0]))
3757
no_context_error_translators.register('DirectoryNotEmpty',
3758
lambda err: errors.DirectoryNotEmpty(err.error_args[0]))
3760
def _translate_short_readv_error(err):
3761
args = err.error_args
3762
return errors.ShortReadvError(args[0], int(args[1]), int(args[2]),
3765
no_context_error_translators.register('ShortReadvError',
3766
_translate_short_readv_error)
3768
def _translate_unicode_error(err):
2932
3769
encoding = str(err.error_args[0]) # encoding must always be a string
2933
3770
val = err.error_args[1]
2934
3771
start = int(err.error_args[2])