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
1646
raise errors.UnexpectedSmartServerResponse(response)
1197
1649
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,
1650
"""Create a descendent repository for new development.
1652
Unlike clone, this does not copy the settings of the repository.
1654
dest_repo = self._create_sprouting_repo(to_bzrdir, shared=False)
1202
1655
dest_repo.fetch(self, revision_id=revision_id)
1203
1656
return dest_repo
1658
def _create_sprouting_repo(self, a_bzrdir, shared):
1659
if not isinstance(a_bzrdir._format, self.bzrdir._format.__class__):
1660
# use target default format.
1661
dest_repo = a_bzrdir.create_repository()
1663
# Most control formats need the repository to be specifically
1664
# created, but on some old all-in-one formats it's not needed
1666
dest_repo = self._format.initialize(a_bzrdir, shared=shared)
1667
except errors.UninitializableFormat:
1668
dest_repo = a_bzrdir.open_repository()
1205
1671
### These methods are just thin shims to the VFS object for now.
1207
1674
def revision_tree(self, revision_id):
1209
return self._real_repository.revision_tree(revision_id)
1675
revision_id = _mod_revision.ensure_null(revision_id)
1676
if revision_id == _mod_revision.NULL_REVISION:
1677
return InventoryRevisionTree(self,
1678
Inventory(root_id=None), _mod_revision.NULL_REVISION)
1680
return list(self.revision_trees([revision_id]))[0]
1211
1682
def get_serializer_format(self):
1213
return self._real_repository.get_serializer_format()
1683
path = self.bzrdir._path_for_remote_call(self._client)
1685
response = self._call('VersionedFileRepository.get_serializer_format',
1687
except errors.UnknownSmartMethod:
1689
return self._real_repository.get_serializer_format()
1690
if response[0] != 'ok':
1691
raise errors.UnexpectedSmartServerResponse(response)
1215
1694
def get_commit_builder(self, branch, parents, config, timestamp=None,
1216
1695
timezone=None, committer=None, revprops=None,
1696
revision_id=None, lossy=False):
1218
1697
# FIXME: It ought to be possible to call this without immediately
1219
1698
# triggering _ensure_real. For now it's the easiest thing to do.
1220
1699
self._ensure_real()
1221
1700
real_repo = self._real_repository
1222
1701
builder = real_repo.get_commit_builder(branch, parents,
1223
1702
config, timestamp=timestamp, timezone=timezone,
1224
committer=committer, revprops=revprops, revision_id=revision_id)
1703
committer=committer, revprops=revprops,
1704
revision_id=revision_id, lossy=lossy)
1227
1707
def add_fallback_repository(self, repository):
1696
2224
def _serializer(self):
1697
2225
return self._format._serializer
1699
2228
def store_revision_signature(self, gpg_strategy, plaintext, revision_id):
1701
return self._real_repository.store_revision_signature(
1702
gpg_strategy, plaintext, revision_id)
2229
signature = gpg_strategy.sign(plaintext)
2230
self.add_signature_text(revision_id, signature)
1704
2232
def add_signature_text(self, revision_id, signature):
1706
return self._real_repository.add_signature_text(revision_id, signature)
2233
if self._real_repository:
2234
# If there is a real repository the write group will
2235
# be in the real repository as well, so use that:
2237
return self._real_repository.add_signature_text(
2238
revision_id, signature)
2239
path = self.bzrdir._path_for_remote_call(self._client)
2240
response, response_handler = self._call_with_body_bytes(
2241
'Repository.add_signature_text', (path, revision_id),
2244
if response[0] != 'ok':
2245
raise errors.UnexpectedSmartServerResponse(response)
1708
2247
def has_signature_for_revision_id(self, revision_id):
1710
return self._real_repository.has_signature_for_revision_id(revision_id)
2248
path = self.bzrdir._path_for_remote_call(self._client)
2250
response = self._call('Repository.has_signature_for_revision_id',
2252
except errors.UnknownSmartMethod:
2254
return self._real_repository.has_signature_for_revision_id(
2256
if response[0] not in ('yes', 'no'):
2257
raise SmartProtocolError('unexpected response code %s' % (response,))
2258
return (response[0] == 'yes')
2261
def verify_revision_signature(self, revision_id, gpg_strategy):
2262
if not self.has_signature_for_revision_id(revision_id):
2263
return gpg.SIGNATURE_NOT_SIGNED, None
2264
signature = self.get_signature_text(revision_id)
2266
testament = _mod_testament.Testament.from_revision(self, revision_id)
2267
plaintext = testament.as_short_text()
2269
return gpg_strategy.verify(signature, plaintext)
1712
2271
def item_keys_introduced_by(self, revision_ids, _files_pb=None):
1713
2272
self._ensure_real()
1714
2273
return self._real_repository.item_keys_introduced_by(revision_ids,
1715
2274
_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
2276
def _find_inconsistent_revision_parents(self, revisions_iterator=None):
1723
2277
self._ensure_real()
1724
2278
return self._real_repository._find_inconsistent_revision_parents(
2071
2632
if isinstance(a_bzrdir, RemoteBzrDir):
2072
2633
a_bzrdir._ensure_real()
2073
2634
result = self._custom_format.initialize(a_bzrdir._real_bzrdir,
2635
name, append_revisions_only=append_revisions_only)
2076
2637
# We assume the bzrdir is parameterised; it may not be.
2077
result = self._custom_format.initialize(a_bzrdir, name)
2638
result = self._custom_format.initialize(a_bzrdir, name,
2639
append_revisions_only=append_revisions_only)
2078
2640
if (isinstance(a_bzrdir, RemoteBzrDir) and
2079
2641
not isinstance(result, RemoteBranch)):
2080
2642
result = RemoteBranch(a_bzrdir, a_bzrdir.find_repository(), result,
2084
def initialize(self, a_bzrdir, name=None):
2646
def initialize(self, a_bzrdir, name=None, repository=None,
2647
append_revisions_only=None):
2085
2648
# 1) get the network name to use.
2086
2649
if self._custom_format:
2087
2650
network_name = self._custom_format.network_name()
2089
2652
# Select the current bzrlib default and ask for that.
2090
reference_bzrdir_format = bzrdir.format_registry.get('default')()
2653
reference_bzrdir_format = _mod_bzrdir.format_registry.get('default')()
2091
2654
reference_format = reference_bzrdir_format.get_branch_format()
2092
2655
self._custom_format = reference_format
2093
2656
network_name = reference_format.network_name()
2094
2657
# Being asked to create on a non RemoteBzrDir:
2095
2658
if not isinstance(a_bzrdir, RemoteBzrDir):
2096
return self._vfs_initialize(a_bzrdir, name=name)
2659
return self._vfs_initialize(a_bzrdir, name=name,
2660
append_revisions_only=append_revisions_only)
2097
2661
medium = a_bzrdir._client._medium
2098
2662
if medium._is_remote_before((1, 13)):
2099
return self._vfs_initialize(a_bzrdir, name=name)
2663
return self._vfs_initialize(a_bzrdir, name=name,
2664
append_revisions_only=append_revisions_only)
2100
2665
# Creating on a remote bzr dir.
2101
2666
# 2) try direct creation via RPC
2102
2667
path = a_bzrdir._path_for_remote_call(a_bzrdir._client)
2148
2728
self._ensure_real()
2149
2729
return self._custom_format.supports_set_append_revisions_only()
2731
def _use_default_local_heads_to_fetch(self):
2732
# If the branch format is a metadir format *and* its heads_to_fetch
2733
# implementation is not overridden vs the base class, we can use the
2734
# base class logic rather than use the heads_to_fetch RPC. This is
2735
# usually cheaper in terms of net round trips, as the last-revision and
2736
# tags info fetched is cached and would be fetched anyway.
2738
if isinstance(self._custom_format, branch.BranchFormatMetadir):
2739
branch_class = self._custom_format._branch_class()
2740
heads_to_fetch_impl = branch_class.heads_to_fetch.im_func
2741
if heads_to_fetch_impl is branch.Branch.heads_to_fetch.im_func:
2746
class RemoteBranchStore(config.IniFileStore):
2747
"""Branch store which attempts to use HPSS calls to retrieve branch store.
2749
Note that this is specific to bzr-based formats.
2752
def __init__(self, branch):
2753
super(RemoteBranchStore, self).__init__()
2754
self.branch = branch
2756
self._real_store = None
2758
def lock_write(self, token=None):
2759
return self.branch.lock_write(token)
2762
return self.branch.unlock()
2766
# We need to be able to override the undecorated implementation
2767
self.save_without_locking()
2769
def save_without_locking(self):
2770
super(RemoteBranchStore, self).save()
2772
def external_url(self):
2773
return self.branch.user_url
2775
def _load_content(self):
2776
path = self.branch._remote_path()
2778
response, handler = self.branch._call_expecting_body(
2779
'Branch.get_config_file', path)
2780
except errors.UnknownSmartMethod:
2782
return self._real_store._load_content()
2783
if len(response) and response[0] != 'ok':
2784
raise errors.UnexpectedSmartServerResponse(response)
2785
return handler.read_body_bytes()
2787
def _save_content(self, content):
2788
path = self.branch._remote_path()
2790
response, handler = self.branch._call_with_body_bytes_expecting_body(
2791
'Branch.put_config_file', (path,
2792
self.branch._lock_token, self.branch._repo_lock_token),
2794
except errors.UnknownSmartMethod:
2796
return self._real_store._save_content(content)
2797
handler.cancel_read_body()
2798
if response != ('ok', ):
2799
raise errors.UnexpectedSmartServerResponse(response)
2801
def _ensure_real(self):
2802
self.branch._ensure_real()
2803
if self._real_store is None:
2804
self._real_store = config.BranchStore(self.branch)
2152
2807
class RemoteBranch(branch.Branch, _RpcHelper, lock._RelockDebugMixin):
2153
2808
"""Branch stored on a server accessed by HPSS RPC.
2654
3364
_override_hook_target=self, **kwargs)
2656
3366
@needs_read_lock
2657
def push(self, target, overwrite=False, stop_revision=None):
3367
def push(self, target, overwrite=False, stop_revision=None, lossy=False):
2658
3368
self._ensure_real()
2659
3369
return self._real_branch.push(
2660
target, overwrite=overwrite, stop_revision=stop_revision,
3370
target, overwrite=overwrite, stop_revision=stop_revision, lossy=lossy,
2661
3371
_override_hook_source_branch=self)
2663
3373
def is_locked(self):
2664
3374
return self._lock_count >= 1
2666
3376
@needs_read_lock
3377
def revision_id_to_dotted_revno(self, revision_id):
3378
"""Given a revision id, return its dotted revno.
3380
:return: a tuple like (1,) or (400,1,3).
3383
response = self._call('Branch.revision_id_to_revno',
3384
self._remote_path(), revision_id)
3385
except errors.UnknownSmartMethod:
3387
return self._real_branch.revision_id_to_dotted_revno(revision_id)
3388
if response[0] == 'ok':
3389
return tuple([int(x) for x in response[1:]])
3391
raise errors.UnexpectedSmartServerResponse(response)
2667
3394
def revision_id_to_revno(self, revision_id):
2669
return self._real_branch.revision_id_to_revno(revision_id)
3395
"""Given a revision id on the branch mainline, return its revno.
3400
response = self._call('Branch.revision_id_to_revno',
3401
self._remote_path(), revision_id)
3402
except errors.UnknownSmartMethod:
3404
return self._real_branch.revision_id_to_revno(revision_id)
3405
if response[0] == 'ok':
3406
if len(response) == 2:
3407
return int(response[1])
3408
raise NoSuchRevision(self, revision_id)
3410
raise errors.UnexpectedSmartServerResponse(response)
2671
3412
@needs_write_lock
2672
3413
def set_last_revision_info(self, revno, revision_id):
2673
3414
# XXX: These should be returned by the set_last_revision_info verb
2674
3415
old_revno, old_revid = self.last_revision_info()
2675
3416
self._run_pre_change_branch_tip_hooks(revno, revision_id)
2676
revision_id = ensure_null(revision_id)
3417
if not revision_id or not isinstance(revision_id, basestring):
3418
raise errors.InvalidRevisionId(revision_id=revision_id, branch=self)
2678
3420
response = self._call('Branch.set_last_revision_info',
2679
3421
self._remote_path(), self._lock_token, self._repo_lock_token,
2774
3553
medium = self._branch._client._medium
2775
3554
if medium._is_remote_before((1, 14)):
2776
3555
return self._vfs_set_option(value, name, section)
3556
if isinstance(value, dict):
3557
if medium._is_remote_before((2, 2)):
3558
return self._vfs_set_option(value, name, section)
3559
return self._set_config_option_dict(value, name, section)
3561
return self._set_config_option(value, name, section)
3563
def _set_config_option(self, value, name, section):
2778
3565
path = self._branch._remote_path()
2779
3566
response = self._branch._client.call('Branch.set_config_option',
2780
3567
path, self._branch._lock_token, self._branch._repo_lock_token,
2781
3568
value.encode('utf8'), name, section or '')
2782
3569
except errors.UnknownSmartMethod:
3570
medium = self._branch._client._medium
2783
3571
medium._remember_remote_is_before((1, 14))
2784
3572
return self._vfs_set_option(value, name, section)
2785
3573
if response != ():
2786
3574
raise errors.UnexpectedSmartServerResponse(response)
3576
def _serialize_option_dict(self, option_dict):
3578
for key, value in option_dict.items():
3579
if isinstance(key, unicode):
3580
key = key.encode('utf8')
3581
if isinstance(value, unicode):
3582
value = value.encode('utf8')
3583
utf8_dict[key] = value
3584
return bencode.bencode(utf8_dict)
3586
def _set_config_option_dict(self, value, name, section):
3588
path = self._branch._remote_path()
3589
serialised_dict = self._serialize_option_dict(value)
3590
response = self._branch._client.call(
3591
'Branch.set_config_option_dict',
3592
path, self._branch._lock_token, self._branch._repo_lock_token,
3593
serialised_dict, name, section or '')
3594
except errors.UnknownSmartMethod:
3595
medium = self._branch._client._medium
3596
medium._remember_remote_is_before((2, 2))
3597
return self._vfs_set_option(value, name, section)
3599
raise errors.UnexpectedSmartServerResponse(response)
2788
3601
def _real_object(self):
2789
3602
self._branch._ensure_real()
2790
3603
return self._branch._real_branch
2873
3690
'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'):
3694
translator = error_translators.get(err.error_verb)
3698
raise translator(err, find, get_path)
3700
translator = no_context_error_translators.get(err.error_verb)
3702
raise errors.UnknownErrorFromSmartServer(err)
3704
raise translator(err)
3707
error_translators.register('NoSuchRevision',
3708
lambda err, find, get_path: NoSuchRevision(
3709
find('branch'), err.error_args[0]))
3710
error_translators.register('nosuchrevision',
3711
lambda err, find, get_path: NoSuchRevision(
3712
find('repository'), err.error_args[0]))
3714
def _translate_nobranch_error(err, find, get_path):
3715
if len(err.error_args) >= 1:
3716
extra = err.error_args[0]
3719
return errors.NotBranchError(path=find('bzrdir').root_transport.base,
3722
error_translators.register('nobranch', _translate_nobranch_error)
3723
error_translators.register('norepository',
3724
lambda err, find, get_path: errors.NoRepositoryPresent(
3726
error_translators.register('UnlockableTransport',
3727
lambda err, find, get_path: errors.UnlockableTransport(
3728
find('bzrdir').root_transport))
3729
error_translators.register('TokenMismatch',
3730
lambda err, find, get_path: errors.TokenMismatch(
3731
find('token'), '(remote token)'))
3732
error_translators.register('Diverged',
3733
lambda err, find, get_path: errors.DivergedBranches(
3734
find('branch'), find('other_branch')))
3735
error_translators.register('NotStacked',
3736
lambda err, find, get_path: errors.NotStacked(branch=find('branch')))
3738
def _translate_PermissionDenied(err, find, get_path):
3740
if len(err.error_args) >= 2:
3741
extra = err.error_args[1]
3744
return errors.PermissionDenied(path, extra=extra)
3746
error_translators.register('PermissionDenied', _translate_PermissionDenied)
3747
error_translators.register('ReadError',
3748
lambda err, find, get_path: errors.ReadError(get_path()))
3749
error_translators.register('NoSuchFile',
3750
lambda err, find, get_path: errors.NoSuchFile(get_path()))
3751
no_context_error_translators.register('IncompatibleRepositories',
3752
lambda err: errors.IncompatibleRepositories(
3753
err.error_args[0], err.error_args[1], err.error_args[2]))
3754
no_context_error_translators.register('LockContention',
3755
lambda err: errors.LockContention('(remote lock)'))
3756
no_context_error_translators.register('LockFailed',
3757
lambda err: errors.LockFailed(err.error_args[0], err.error_args[1]))
3758
no_context_error_translators.register('TipChangeRejected',
3759
lambda err: errors.TipChangeRejected(err.error_args[0].decode('utf8')))
3760
no_context_error_translators.register('UnstackableBranchFormat',
3761
lambda err: errors.UnstackableBranchFormat(*err.error_args))
3762
no_context_error_translators.register('UnstackableRepositoryFormat',
3763
lambda err: errors.UnstackableRepositoryFormat(*err.error_args))
3764
no_context_error_translators.register('FileExists',
3765
lambda err: errors.FileExists(err.error_args[0]))
3766
no_context_error_translators.register('DirectoryNotEmpty',
3767
lambda err: errors.DirectoryNotEmpty(err.error_args[0]))
3769
def _translate_short_readv_error(err):
3770
args = err.error_args
3771
return errors.ShortReadvError(args[0], int(args[1]), int(args[2]),
3774
no_context_error_translators.register('ShortReadvError',
3775
_translate_short_readv_error)
3777
def _translate_unicode_error(err):
2932
3778
encoding = str(err.error_args[0]) # encoding must always be a string
2933
3779
val = err.error_args[1]
2934
3780
start = int(err.error_args[2])