87
# Note: RemoteBzrDirFormat is in bzrdir.py
89
class RemoteBzrDir(BzrDir, _RpcHelper):
107
# Note that RemoteBzrDirProber lives in bzrlib.bzrdir so bzrlib.remote
108
# does not have to be imported unless a remote format is involved.
110
class RemoteBzrDirFormat(_mod_bzrdir.BzrDirMetaFormat1):
111
"""Format representing bzrdirs accessed via a smart server"""
113
supports_workingtrees = False
116
_mod_bzrdir.BzrDirMetaFormat1.__init__(self)
117
# XXX: It's a bit ugly that the network name is here, because we'd
118
# like to believe that format objects are stateless or at least
119
# immutable, However, we do at least avoid mutating the name after
120
# it's returned. See <https://bugs.launchpad.net/bzr/+bug/504102>
121
self._network_name = None
124
return "%s(_network_name=%r)" % (self.__class__.__name__,
127
def get_format_description(self):
128
if self._network_name:
130
real_format = controldir.network_format_registry.get(
135
return 'Remote: ' + real_format.get_format_description()
136
return 'bzr remote bzrdir'
138
def get_format_string(self):
139
raise NotImplementedError(self.get_format_string)
141
def network_name(self):
142
if self._network_name:
143
return self._network_name
145
raise AssertionError("No network name set.")
147
def initialize_on_transport(self, transport):
149
# hand off the request to the smart server
150
client_medium = transport.get_smart_medium()
151
except errors.NoSmartMedium:
152
# TODO: lookup the local format from a server hint.
153
local_dir_format = _mod_bzrdir.BzrDirMetaFormat1()
154
return local_dir_format.initialize_on_transport(transport)
155
client = _SmartClient(client_medium)
156
path = client.remote_path_from_transport(transport)
158
response = client.call('BzrDirFormat.initialize', path)
159
except errors.ErrorFromSmartServer, err:
160
_translate_error(err, path=path)
161
if response[0] != 'ok':
162
raise errors.SmartProtocolError('unexpected response code %s' % (response,))
163
format = RemoteBzrDirFormat()
164
self._supply_sub_formats_to(format)
165
return RemoteBzrDir(transport, format)
167
def parse_NoneTrueFalse(self, arg):
174
raise AssertionError("invalid arg %r" % arg)
176
def _serialize_NoneTrueFalse(self, arg):
183
def _serialize_NoneString(self, arg):
186
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
187
create_prefix=False, force_new_repo=False, stacked_on=None,
188
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
191
# hand off the request to the smart server
192
client_medium = transport.get_smart_medium()
193
except errors.NoSmartMedium:
196
# Decline to open it if the server doesn't support our required
197
# version (3) so that the VFS-based transport will do it.
198
if client_medium.should_probe():
200
server_version = client_medium.protocol_version()
201
if server_version != '2':
205
except errors.SmartProtocolError:
206
# Apparently there's no usable smart server there, even though
207
# the medium supports the smart protocol.
212
client = _SmartClient(client_medium)
213
path = client.remote_path_from_transport(transport)
214
if client_medium._is_remote_before((1, 16)):
217
# TODO: lookup the local format from a server hint.
218
local_dir_format = _mod_bzrdir.BzrDirMetaFormat1()
219
self._supply_sub_formats_to(local_dir_format)
220
return local_dir_format.initialize_on_transport_ex(transport,
221
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
222
force_new_repo=force_new_repo, stacked_on=stacked_on,
223
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
224
make_working_trees=make_working_trees, shared_repo=shared_repo,
226
return self._initialize_on_transport_ex_rpc(client, path, transport,
227
use_existing_dir, create_prefix, force_new_repo, stacked_on,
228
stack_on_pwd, repo_format_name, make_working_trees, shared_repo)
230
def _initialize_on_transport_ex_rpc(self, client, path, transport,
231
use_existing_dir, create_prefix, force_new_repo, stacked_on,
232
stack_on_pwd, repo_format_name, make_working_trees, shared_repo):
234
args.append(self._serialize_NoneTrueFalse(use_existing_dir))
235
args.append(self._serialize_NoneTrueFalse(create_prefix))
236
args.append(self._serialize_NoneTrueFalse(force_new_repo))
237
args.append(self._serialize_NoneString(stacked_on))
238
# stack_on_pwd is often/usually our transport
241
stack_on_pwd = transport.relpath(stack_on_pwd)
244
except errors.PathNotChild:
246
args.append(self._serialize_NoneString(stack_on_pwd))
247
args.append(self._serialize_NoneString(repo_format_name))
248
args.append(self._serialize_NoneTrueFalse(make_working_trees))
249
args.append(self._serialize_NoneTrueFalse(shared_repo))
250
request_network_name = self._network_name or \
251
_mod_bzrdir.BzrDirFormat.get_default_format().network_name()
253
response = client.call('BzrDirFormat.initialize_ex_1.16',
254
request_network_name, path, *args)
255
except errors.UnknownSmartMethod:
256
client._medium._remember_remote_is_before((1,16))
257
local_dir_format = _mod_bzrdir.BzrDirMetaFormat1()
258
self._supply_sub_formats_to(local_dir_format)
259
return local_dir_format.initialize_on_transport_ex(transport,
260
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
261
force_new_repo=force_new_repo, stacked_on=stacked_on,
262
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
263
make_working_trees=make_working_trees, shared_repo=shared_repo,
265
except errors.ErrorFromSmartServer, err:
266
_translate_error(err, path=path)
267
repo_path = response[0]
268
bzrdir_name = response[6]
269
require_stacking = response[7]
270
require_stacking = self.parse_NoneTrueFalse(require_stacking)
271
format = RemoteBzrDirFormat()
272
format._network_name = bzrdir_name
273
self._supply_sub_formats_to(format)
274
bzrdir = RemoteBzrDir(transport, format, _client=client)
276
repo_format = response_tuple_to_repo_format(response[1:])
280
repo_bzrdir_format = RemoteBzrDirFormat()
281
repo_bzrdir_format._network_name = response[5]
282
repo_bzr = RemoteBzrDir(transport.clone(repo_path),
286
final_stack = response[8] or None
287
final_stack_pwd = response[9] or None
289
final_stack_pwd = urlutils.join(
290
transport.base, final_stack_pwd)
291
remote_repo = RemoteRepository(repo_bzr, repo_format)
292
if len(response) > 10:
293
# Updated server verb that locks remotely.
294
repo_lock_token = response[10] or None
295
remote_repo.lock_write(repo_lock_token, _skip_rpc=True)
297
remote_repo.dont_leave_lock_in_place()
299
remote_repo.lock_write()
300
policy = _mod_bzrdir.UseExistingRepository(remote_repo, final_stack,
301
final_stack_pwd, require_stacking)
302
policy.acquire_repository()
306
bzrdir._format.set_branch_format(self.get_branch_format())
308
# The repo has already been created, but we need to make sure that
309
# we'll make a stackable branch.
310
bzrdir._format.require_stacking(_skip_repo=True)
311
return remote_repo, bzrdir, require_stacking, policy
313
def _open(self, transport):
314
return RemoteBzrDir(transport, self)
316
def __eq__(self, other):
317
if not isinstance(other, RemoteBzrDirFormat):
319
return self.get_format_description() == other.get_format_description()
321
def __return_repository_format(self):
322
# Always return a RemoteRepositoryFormat object, but if a specific bzr
323
# repository format has been asked for, tell the RemoteRepositoryFormat
324
# that it should use that for init() etc.
325
result = RemoteRepositoryFormat()
326
custom_format = getattr(self, '_repository_format', None)
328
if isinstance(custom_format, RemoteRepositoryFormat):
331
# We will use the custom format to create repositories over the
332
# wire; expose its details like rich_root_data for code to
334
result._custom_format = custom_format
337
def get_branch_format(self):
338
result = _mod_bzrdir.BzrDirMetaFormat1.get_branch_format(self)
339
if not isinstance(result, RemoteBranchFormat):
340
new_result = RemoteBranchFormat()
341
new_result._custom_format = result
343
self.set_branch_format(new_result)
347
repository_format = property(__return_repository_format,
348
_mod_bzrdir.BzrDirMetaFormat1._set_repository_format) #.im_func)
351
class RemoteControlStore(config.IniFileStore):
352
"""Control store which attempts to use HPSS calls to retrieve control store.
354
Note that this is specific to bzr-based formats.
357
def __init__(self, bzrdir):
358
super(RemoteControlStore, self).__init__()
360
self._real_store = None
362
def lock_write(self, token=None):
364
return self._real_store.lock_write(token)
368
return self._real_store.unlock()
372
# We need to be able to override the undecorated implementation
373
self.save_without_locking()
375
def save_without_locking(self):
376
super(RemoteControlStore, self).save()
378
def _ensure_real(self):
379
self.bzrdir._ensure_real()
380
if self._real_store is None:
381
self._real_store = config.ControlStore(self.bzrdir)
383
def external_url(self):
384
return self.bzrdir.user_url
386
def _load_content(self):
387
medium = self.bzrdir._client._medium
388
path = self.bzrdir._path_for_remote_call(self.bzrdir._client)
390
response, handler = self.bzrdir._call_expecting_body(
391
'BzrDir.get_config_file', path)
392
except errors.UnknownSmartMethod:
394
return self._real_store._load_content()
395
if len(response) and response[0] != 'ok':
396
raise errors.UnexpectedSmartServerResponse(response)
397
return handler.read_body_bytes()
399
def _save_content(self, content):
400
# FIXME JRV 2011-11-22: Ideally this should use a
401
# HPSS call too, but at the moment it is not possible
402
# to write lock control directories.
404
return self._real_store._save_content(content)
407
class RemoteBzrDir(_mod_bzrdir.BzrDir, _RpcHelper):
90
408
"""Control directory on a remote server, accessed via bzr:// or similar."""
92
410
def __init__(self, transport, format, _client=None, _force_probe=False):
284
690
def _get_branch_reference(self):
285
691
path = self._path_for_remote_call(self._client)
286
692
medium = self._client._medium
287
if not medium._is_remote_before((1, 13)):
694
('BzrDir.open_branchV3', (2, 1)),
695
('BzrDir.open_branchV2', (1, 13)),
696
('BzrDir.open_branch', None),
698
for verb, required_version in candidate_calls:
699
if required_version and medium._is_remote_before(required_version):
289
response = self._call('BzrDir.open_branchV2', path)
290
if response[0] not in ('ref', 'branch'):
291
raise errors.UnexpectedSmartServerResponse(response)
702
response = self._call(verb, path)
293
703
except errors.UnknownSmartMethod:
294
medium._remember_remote_is_before((1, 13))
295
response = self._call('BzrDir.open_branch', path)
296
if response[0] != 'ok':
704
if required_version is None:
706
medium._remember_remote_is_before(required_version)
709
if verb == 'BzrDir.open_branch':
710
if response[0] != 'ok':
711
raise errors.UnexpectedSmartServerResponse(response)
712
if response[1] != '':
713
return ('ref', response[1])
715
return ('branch', '')
716
if response[0] not in ('ref', 'branch'):
297
717
raise errors.UnexpectedSmartServerResponse(response)
298
if response[1] != '':
299
return ('ref', response[1])
301
return ('branch', '')
303
def _get_tree_branch(self):
720
def _get_tree_branch(self, name=None):
304
721
"""See BzrDir._get_tree_branch()."""
305
return None, self.open_branch()
722
return None, self.open_branch(name=name)
307
def open_branch(self, _unsupported=False, ignore_fallbacks=False):
724
def open_branch(self, name=None, unsupported=False,
725
ignore_fallbacks=False, possible_transports=None):
309
727
raise NotImplementedError('unsupported flag support not implemented yet.')
310
728
if self._next_open_branch_result is not None:
311
729
# See create_branch for details.
1150
1717
raise errors.UnexpectedSmartServerResponse(response)
1152
1720
def sprout(self, to_bzrdir, revision_id=None):
1153
# TODO: Option to control what format is created?
1155
dest_repo = self._real_repository._format.initialize(to_bzrdir,
1721
"""Create a descendent repository for new development.
1723
Unlike clone, this does not copy the settings of the repository.
1725
dest_repo = self._create_sprouting_repo(to_bzrdir, shared=False)
1157
1726
dest_repo.fetch(self, revision_id=revision_id)
1158
1727
return dest_repo
1729
def _create_sprouting_repo(self, a_bzrdir, shared):
1730
if not isinstance(a_bzrdir._format, self.bzrdir._format.__class__):
1731
# use target default format.
1732
dest_repo = a_bzrdir.create_repository()
1734
# Most control formats need the repository to be specifically
1735
# created, but on some old all-in-one formats it's not needed
1737
dest_repo = self._format.initialize(a_bzrdir, shared=shared)
1738
except errors.UninitializableFormat:
1739
dest_repo = a_bzrdir.open_repository()
1160
1742
### These methods are just thin shims to the VFS object for now.
1162
1745
def revision_tree(self, revision_id):
1164
return self._real_repository.revision_tree(revision_id)
1746
revision_id = _mod_revision.ensure_null(revision_id)
1747
if revision_id == _mod_revision.NULL_REVISION:
1748
return InventoryRevisionTree(self,
1749
Inventory(root_id=None), _mod_revision.NULL_REVISION)
1751
return list(self.revision_trees([revision_id]))[0]
1166
1753
def get_serializer_format(self):
1168
return self._real_repository.get_serializer_format()
1754
path = self.bzrdir._path_for_remote_call(self._client)
1756
response = self._call('VersionedFileRepository.get_serializer_format',
1758
except errors.UnknownSmartMethod:
1760
return self._real_repository.get_serializer_format()
1761
if response[0] != 'ok':
1762
raise errors.UnexpectedSmartServerResponse(response)
1170
1765
def get_commit_builder(self, branch, parents, config, timestamp=None,
1171
1766
timezone=None, committer=None, revprops=None,
1767
revision_id=None, lossy=False):
1173
1768
# FIXME: It ought to be possible to call this without immediately
1174
1769
# triggering _ensure_real. For now it's the easiest thing to do.
1175
1770
self._ensure_real()
1176
1771
real_repo = self._real_repository
1177
1772
builder = real_repo.get_commit_builder(branch, parents,
1178
1773
config, timestamp=timestamp, timezone=timezone,
1179
committer=committer, revprops=revprops, revision_id=revision_id)
1774
committer=committer, revprops=revprops,
1775
revision_id=revision_id, lossy=lossy)
1182
1778
def add_fallback_repository(self, repository):
1223
1832
@needs_read_lock
1224
1833
def get_inventory(self, revision_id):
1834
return list(self.iter_inventories([revision_id]))[0]
1836
def _iter_inventories_rpc(self, revision_ids, ordering):
1837
if ordering is None:
1838
ordering = 'unordered'
1839
path = self.bzrdir._path_for_remote_call(self._client)
1840
body = "\n".join(revision_ids)
1841
response_tuple, response_handler = (
1842
self._call_with_body_bytes_expecting_body(
1843
"VersionedFileRepository.get_inventories",
1844
(path, ordering), body))
1845
if response_tuple[0] != "ok":
1846
raise errors.UnexpectedSmartServerResponse(response_tuple)
1847
deserializer = inventory_delta.InventoryDeltaDeserializer()
1848
byte_stream = response_handler.read_streamed_body()
1849
decoded = smart_repo._byte_stream_to_stream(byte_stream)
1851
# no results whatsoever
1853
src_format, stream = decoded
1854
if src_format.network_name() != self._format.network_name():
1855
raise AssertionError(
1856
"Mismatched RemoteRepository and stream src %r, %r" % (
1857
src_format.network_name(), self._format.network_name()))
1858
# ignore the src format, it's not really relevant
1859
prev_inv = Inventory(root_id=None,
1860
revision_id=_mod_revision.NULL_REVISION)
1861
# there should be just one substream, with inventory deltas
1862
substream_kind, substream = stream.next()
1863
if substream_kind != "inventory-deltas":
1864
raise AssertionError(
1865
"Unexpected stream %r received" % substream_kind)
1866
for record in substream:
1867
(parent_id, new_id, versioned_root, tree_references, invdelta) = (
1868
deserializer.parse_text_bytes(record.get_bytes_as("fulltext")))
1869
if parent_id != prev_inv.revision_id:
1870
raise AssertionError("invalid base %r != %r" % (parent_id,
1871
prev_inv.revision_id))
1872
inv = prev_inv.create_by_apply_delta(invdelta, new_id)
1873
yield inv, inv.revision_id
1876
def _iter_inventories_vfs(self, revision_ids, ordering=None):
1225
1877
self._ensure_real()
1226
return self._real_repository.get_inventory(revision_id)
1878
return self._real_repository._iter_inventories(revision_ids, ordering)
1228
1880
def iter_inventories(self, revision_ids, ordering=None):
1230
return self._real_repository.iter_inventories(revision_ids, ordering)
1881
"""Get many inventories by revision_ids.
1883
This will buffer some or all of the texts used in constructing the
1884
inventories in memory, but will only parse a single inventory at a
1887
:param revision_ids: The expected revision ids of the inventories.
1888
:param ordering: optional ordering, e.g. 'topological'. If not
1889
specified, the order of revision_ids will be preserved (by
1890
buffering if necessary).
1891
:return: An iterator of inventories.
1893
if ((None in revision_ids)
1894
or (_mod_revision.NULL_REVISION in revision_ids)):
1895
raise ValueError('cannot get null revision inventory')
1896
for inv, revid in self._iter_inventories(revision_ids, ordering):
1898
raise errors.NoSuchRevision(self, revid)
1901
def _iter_inventories(self, revision_ids, ordering=None):
1902
if len(revision_ids) == 0:
1904
missing = set(revision_ids)
1905
if ordering is None:
1906
order_as_requested = True
1908
order = list(revision_ids)
1910
next_revid = order.pop()
1912
order_as_requested = False
1913
if ordering != 'unordered' and self._fallback_repositories:
1914
raise ValueError('unsupported ordering %r' % ordering)
1915
iter_inv_fns = [self._iter_inventories_rpc] + [
1916
fallback._iter_inventories for fallback in
1917
self._fallback_repositories]
1919
for iter_inv in iter_inv_fns:
1920
request = [revid for revid in revision_ids if revid in missing]
1921
for inv, revid in iter_inv(request, ordering):
1924
missing.remove(inv.revision_id)
1925
if ordering != 'unordered':
1929
if order_as_requested:
1930
# Yield as many results as we can while preserving order.
1931
while next_revid in invs:
1932
inv = invs.pop(next_revid)
1933
yield inv, inv.revision_id
1935
next_revid = order.pop()
1937
# We still want to fully consume the stream, just
1938
# in case it is not actually finished at this point
1941
except errors.UnknownSmartMethod:
1942
for inv, revid in self._iter_inventories_vfs(revision_ids, ordering):
1946
if order_as_requested:
1947
if next_revid is not None:
1948
yield None, next_revid
1951
yield invs.get(revid), revid
1954
yield None, missing.pop()
1232
1956
@needs_read_lock
1233
1957
def get_revision(self, revision_id):
1235
return self._real_repository.get_revision(revision_id)
1958
return self.get_revisions([revision_id])[0]
1237
1960
def get_transaction(self):
1238
1961
self._ensure_real()
1271
2003
included_keys = result_set.intersection(result_parents)
1272
2004
start_keys = result_set.difference(included_keys)
1273
2005
exclude_keys = result_parents.difference(result_set)
1274
result = graph.SearchResult(start_keys, exclude_keys,
2006
result = vf_search.SearchResult(start_keys, exclude_keys,
1275
2007
len(result_set), result_set)
1278
2010
@needs_read_lock
1279
def search_missing_revision_ids(self, other, revision_id=None, find_ghosts=True):
2011
def search_missing_revision_ids(self, other,
2012
revision_id=symbol_versioning.DEPRECATED_PARAMETER,
2013
find_ghosts=True, revision_ids=None, if_present_ids=None,
1280
2015
"""Return the revision ids that other has that this does not.
1282
2017
These are returned in topological order.
1284
2019
revision_id: only return revision ids included by revision_id.
1286
return repository.InterRepository.get(
1287
other, self).search_missing_revision_ids(revision_id, find_ghosts)
2021
if symbol_versioning.deprecated_passed(revision_id):
2022
symbol_versioning.warn(
2023
'search_missing_revision_ids(revision_id=...) was '
2024
'deprecated in 2.4. Use revision_ids=[...] instead.',
2025
DeprecationWarning, stacklevel=2)
2026
if revision_ids is not None:
2027
raise AssertionError(
2028
'revision_ids is mutually exclusive with revision_id')
2029
if revision_id is not None:
2030
revision_ids = [revision_id]
2031
inter_repo = _mod_repository.InterRepository.get(other, self)
2032
return inter_repo.search_missing_revision_ids(
2033
find_ghosts=find_ghosts, revision_ids=revision_ids,
2034
if_present_ids=if_present_ids, limit=limit)
1289
def fetch(self, source, revision_id=None, pb=None, find_ghosts=False,
2036
def fetch(self, source, revision_id=None, find_ghosts=False,
1290
2037
fetch_spec=None):
1291
2038
# No base implementation to use as RemoteRepository is not a subclass
1292
2039
# of Repository; so this is a copy of Repository.fetch().
1331
2084
return self._real_repository._get_versioned_file_checker(
1332
2085
revisions, revision_versions_cache)
2087
def _iter_files_bytes_rpc(self, desired_files, absent):
2088
path = self.bzrdir._path_for_remote_call(self._client)
2091
for (file_id, revid, identifier) in desired_files:
2092
lines.append("%s\0%s" % (
2093
osutils.safe_file_id(file_id),
2094
osutils.safe_revision_id(revid)))
2095
identifiers.append(identifier)
2096
(response_tuple, response_handler) = (
2097
self._call_with_body_bytes_expecting_body(
2098
"Repository.iter_files_bytes", (path, ), "\n".join(lines)))
2099
if response_tuple != ('ok', ):
2100
response_handler.cancel_read_body()
2101
raise errors.UnexpectedSmartServerResponse(response_tuple)
2102
byte_stream = response_handler.read_streamed_body()
2103
def decompress_stream(start, byte_stream, unused):
2104
decompressor = zlib.decompressobj()
2105
yield decompressor.decompress(start)
2106
while decompressor.unused_data == "":
2108
data = byte_stream.next()
2109
except StopIteration:
2111
yield decompressor.decompress(data)
2112
yield decompressor.flush()
2113
unused.append(decompressor.unused_data)
2116
while not "\n" in unused:
2117
unused += byte_stream.next()
2118
header, rest = unused.split("\n", 1)
2119
args = header.split("\0")
2120
if args[0] == "absent":
2121
absent[identifiers[int(args[3])]] = (args[1], args[2])
2124
elif args[0] == "ok":
2127
raise errors.UnexpectedSmartServerResponse(args)
2129
yield (identifiers[idx],
2130
decompress_stream(rest, byte_stream, unused_chunks))
2131
unused = "".join(unused_chunks)
1334
2133
def iter_files_bytes(self, desired_files):
1335
2134
"""See Repository.iter_file_bytes.
1338
return self._real_repository.iter_files_bytes(desired_files)
2138
for (identifier, bytes_iterator) in self._iter_files_bytes_rpc(
2139
desired_files, absent):
2140
yield identifier, bytes_iterator
2141
for fallback in self._fallback_repositories:
2144
desired_files = [(key[0], key[1], identifier) for
2145
(identifier, key) in absent.iteritems()]
2146
for (identifier, bytes_iterator) in fallback.iter_files_bytes(desired_files):
2147
del absent[identifier]
2148
yield identifier, bytes_iterator
2150
# There may be more missing items, but raise an exception
2152
missing_identifier = absent.keys()[0]
2153
missing_key = absent[missing_identifier]
2154
raise errors.RevisionNotPresent(revision_id=missing_key[1],
2155
file_id=missing_key[0])
2156
except errors.UnknownSmartMethod:
2158
for (identifier, bytes_iterator) in (
2159
self._real_repository.iter_files_bytes(desired_files)):
2160
yield identifier, bytes_iterator
2162
def get_cached_parent_map(self, revision_ids):
2163
"""See bzrlib.CachingParentsProvider.get_cached_parent_map"""
2164
return self._unstacked_provider.get_cached_parent_map(revision_ids)
1340
2166
def get_parent_map(self, revision_ids):
1341
2167
"""See bzrlib.Graph.get_parent_map()."""
1475
2290
@needs_read_lock
1476
2291
def get_signature_text(self, revision_id):
1478
return self._real_repository.get_signature_text(revision_id)
2292
path = self.bzrdir._path_for_remote_call(self._client)
2294
response_tuple, response_handler = self._call_expecting_body(
2295
'Repository.get_revision_signature_text', path, revision_id)
2296
except errors.UnknownSmartMethod:
2298
return self._real_repository.get_signature_text(revision_id)
2299
except errors.NoSuchRevision, err:
2300
for fallback in self._fallback_repositories:
2302
return fallback.get_signature_text(revision_id)
2303
except errors.NoSuchRevision:
2307
if response_tuple[0] != 'ok':
2308
raise errors.UnexpectedSmartServerResponse(response_tuple)
2309
return response_handler.read_body_bytes()
1480
2311
@needs_read_lock
1481
def get_inventory_xml(self, revision_id):
1483
return self._real_repository.get_inventory_xml(revision_id)
1485
def deserialise_inventory(self, revision_id, xml):
1487
return self._real_repository.deserialise_inventory(revision_id, xml)
2312
def _get_inventory_xml(self, revision_id):
2313
# This call is used by older working tree formats,
2314
# which stored a serialized basis inventory.
2316
return self._real_repository._get_inventory_xml(revision_id)
1489
2319
def reconcile(self, other=None, thorough=False):
1491
return self._real_repository.reconcile(other=other, thorough=thorough)
2320
from bzrlib.reconcile import RepoReconciler
2321
path = self.bzrdir._path_for_remote_call(self._client)
2323
response, handler = self._call_expecting_body(
2324
'Repository.reconcile', path, self._lock_token)
2325
except (errors.UnknownSmartMethod, errors.TokenLockingNotSupported):
2327
return self._real_repository.reconcile(other=other, thorough=thorough)
2328
if response != ('ok', ):
2329
raise errors.UnexpectedSmartServerResponse(response)
2330
body = handler.read_body_bytes()
2331
result = RepoReconciler(self)
2332
for line in body.split('\n'):
2335
key, val_text = line.split(':')
2336
if key == "garbage_inventories":
2337
result.garbage_inventories = int(val_text)
2338
elif key == "inconsistent_parents":
2339
result.inconsistent_parents = int(val_text)
2341
mutter("unknown reconcile key %r" % key)
1493
2344
def all_revision_ids(self):
1495
return self._real_repository.all_revision_ids()
2345
path = self.bzrdir._path_for_remote_call(self._client)
2347
response_tuple, response_handler = self._call_expecting_body(
2348
"Repository.all_revision_ids", path)
2349
except errors.UnknownSmartMethod:
2351
return self._real_repository.all_revision_ids()
2352
if response_tuple != ("ok", ):
2353
raise errors.UnexpectedSmartServerResponse(response_tuple)
2354
revids = set(response_handler.read_body_bytes().splitlines())
2355
for fallback in self._fallback_repositories:
2356
revids.update(set(fallback.all_revision_ids()))
2359
def _filtered_revision_trees(self, revision_ids, file_ids):
2360
"""Return Tree for a revision on this branch with only some files.
2362
:param revision_ids: a sequence of revision-ids;
2363
a revision-id may not be None or 'null:'
2364
:param file_ids: if not None, the result is filtered
2365
so that only those file-ids, their parents and their
2366
children are included.
2368
inventories = self.iter_inventories(revision_ids)
2369
for inv in inventories:
2370
# Should we introduce a FilteredRevisionTree class rather
2371
# than pre-filter the inventory here?
2372
filtered_inv = inv.filter(file_ids)
2373
yield InventoryRevisionTree(self, filtered_inv, filtered_inv.revision_id)
1497
2375
@needs_read_lock
1498
2376
def get_deltas_for_revisions(self, revisions, specific_fileids=None):
1500
return self._real_repository.get_deltas_for_revisions(revisions,
1501
specific_fileids=specific_fileids)
2377
medium = self._client._medium
2378
if medium._is_remote_before((1, 2)):
2380
for delta in self._real_repository.get_deltas_for_revisions(
2381
revisions, specific_fileids):
2384
# Get the revision-ids of interest
2385
required_trees = set()
2386
for revision in revisions:
2387
required_trees.add(revision.revision_id)
2388
required_trees.update(revision.parent_ids[:1])
2390
# Get the matching filtered trees. Note that it's more
2391
# efficient to pass filtered trees to changes_from() rather
2392
# than doing the filtering afterwards. changes_from() could
2393
# arguably do the filtering itself but it's path-based, not
2394
# file-id based, so filtering before or afterwards is
2396
if specific_fileids is None:
2397
trees = dict((t.get_revision_id(), t) for
2398
t in self.revision_trees(required_trees))
2400
trees = dict((t.get_revision_id(), t) for
2401
t in self._filtered_revision_trees(required_trees,
2404
# Calculate the deltas
2405
for revision in revisions:
2406
if not revision.parent_ids:
2407
old_tree = self.revision_tree(_mod_revision.NULL_REVISION)
2409
old_tree = trees[revision.parent_ids[0]]
2410
yield trees[revision.revision_id].changes_from(old_tree)
1503
2412
@needs_read_lock
1504
2413
def get_revision_delta(self, revision_id, specific_fileids=None):
1506
return self._real_repository.get_revision_delta(revision_id,
1507
specific_fileids=specific_fileids)
2414
r = self.get_revision(revision_id)
2415
return list(self.get_deltas_for_revisions([r],
2416
specific_fileids=specific_fileids))[0]
1509
2418
@needs_read_lock
1510
2419
def revision_trees(self, revision_ids):
1512
return self._real_repository.revision_trees(revision_ids)
2420
inventories = self.iter_inventories(revision_ids)
2421
for inv in inventories:
2422
yield InventoryRevisionTree(self, inv, inv.revision_id)
1514
2424
@needs_read_lock
1515
2425
def get_revision_reconcile(self, revision_id):
1627
2550
self._ensure_real()
1628
2551
return self._real_repository.texts
2553
def _iter_revisions_rpc(self, revision_ids):
2554
body = "\n".join(revision_ids)
2555
path = self.bzrdir._path_for_remote_call(self._client)
2556
response_tuple, response_handler = (
2557
self._call_with_body_bytes_expecting_body(
2558
"Repository.iter_revisions", (path, ), body))
2559
if response_tuple[0] != "ok":
2560
raise errors.UnexpectedSmartServerResponse(response_tuple)
2561
serializer_format = response_tuple[1]
2562
serializer = serializer_format_registry.get(serializer_format)
2563
byte_stream = response_handler.read_streamed_body()
2564
decompressor = zlib.decompressobj()
2566
for bytes in byte_stream:
2567
chunks.append(decompressor.decompress(bytes))
2568
if decompressor.unused_data != "":
2569
chunks.append(decompressor.flush())
2570
yield serializer.read_revision_from_string("".join(chunks))
2571
unused = decompressor.unused_data
2572
decompressor = zlib.decompressobj()
2573
chunks = [decompressor.decompress(unused)]
2574
chunks.append(decompressor.flush())
2575
text = "".join(chunks)
2577
yield serializer.read_revision_from_string("".join(chunks))
1630
2579
@needs_read_lock
1631
2580
def get_revisions(self, revision_ids):
1633
return self._real_repository.get_revisions(revision_ids)
2581
if revision_ids is None:
2582
revision_ids = self.all_revision_ids()
2584
for rev_id in revision_ids:
2585
if not rev_id or not isinstance(rev_id, basestring):
2586
raise errors.InvalidRevisionId(
2587
revision_id=rev_id, branch=self)
2589
missing = set(revision_ids)
2591
for rev in self._iter_revisions_rpc(revision_ids):
2592
missing.remove(rev.revision_id)
2593
revs[rev.revision_id] = rev
2594
except errors.UnknownSmartMethod:
2596
return self._real_repository.get_revisions(revision_ids)
2597
for fallback in self._fallback_repositories:
2600
for revid in list(missing):
2601
# XXX JRV 2011-11-20: It would be nice if there was a
2602
# public method on Repository that could be used to query
2603
# for revision objects *without* failing completely if one
2604
# was missing. There is VersionedFileRepository._iter_revisions,
2605
# but unfortunately that's private and not provided by
2606
# all repository implementations.
2608
revs[revid] = fallback.get_revision(revid)
2609
except errors.NoSuchRevision:
2612
missing.remove(revid)
2614
raise errors.NoSuchRevision(self, list(missing)[0])
2615
return [revs[revid] for revid in revision_ids]
1635
2617
def supports_rich_root(self):
1636
2618
return self._format.rich_root_data
2620
@symbol_versioning.deprecated_method(symbol_versioning.deprecated_in((2, 4, 0)))
1638
2621
def iter_reverse_revision_history(self, revision_id):
1639
2622
self._ensure_real()
1640
2623
return self._real_repository.iter_reverse_revision_history(revision_id)
1643
2626
def _serializer(self):
1644
2627
return self._format._serializer
1646
2630
def store_revision_signature(self, gpg_strategy, plaintext, revision_id):
1648
return self._real_repository.store_revision_signature(
1649
gpg_strategy, plaintext, revision_id)
2631
signature = gpg_strategy.sign(plaintext)
2632
self.add_signature_text(revision_id, signature)
1651
2634
def add_signature_text(self, revision_id, signature):
1653
return self._real_repository.add_signature_text(revision_id, signature)
2635
if self._real_repository:
2636
# If there is a real repository the write group will
2637
# be in the real repository as well, so use that:
2639
return self._real_repository.add_signature_text(
2640
revision_id, signature)
2641
path = self.bzrdir._path_for_remote_call(self._client)
2642
response, handler = self._call_with_body_bytes_expecting_body(
2643
'Repository.add_signature_text', (path, self._lock_token,
2644
revision_id) + tuple(self._write_group_tokens), signature)
2645
handler.cancel_read_body()
2647
if response[0] != 'ok':
2648
raise errors.UnexpectedSmartServerResponse(response)
2649
self._write_group_tokens = response[1:]
1655
2651
def has_signature_for_revision_id(self, revision_id):
1657
return self._real_repository.has_signature_for_revision_id(revision_id)
2652
path = self.bzrdir._path_for_remote_call(self._client)
2654
response = self._call('Repository.has_signature_for_revision_id',
2656
except errors.UnknownSmartMethod:
2658
return self._real_repository.has_signature_for_revision_id(
2660
if response[0] not in ('yes', 'no'):
2661
raise SmartProtocolError('unexpected response code %s' % (response,))
2662
if response[0] == 'yes':
2664
for fallback in self._fallback_repositories:
2665
if fallback.has_signature_for_revision_id(revision_id):
2670
def verify_revision_signature(self, revision_id, gpg_strategy):
2671
if not self.has_signature_for_revision_id(revision_id):
2672
return gpg.SIGNATURE_NOT_SIGNED, None
2673
signature = self.get_signature_text(revision_id)
2675
testament = _mod_testament.Testament.from_revision(self, revision_id)
2676
plaintext = testament.as_short_text()
2678
return gpg_strategy.verify(signature, plaintext)
1659
2680
def item_keys_introduced_by(self, revision_ids, _files_pb=None):
1660
2681
self._ensure_real()
1661
2682
return self._real_repository.item_keys_introduced_by(revision_ids,
1662
2683
_files_pb=_files_pb)
1664
def revision_graph_can_have_wrong_parents(self):
1665
# The answer depends on the remote repo format.
1667
return self._real_repository.revision_graph_can_have_wrong_parents()
1669
2685
def _find_inconsistent_revision_parents(self, revisions_iterator=None):
1670
2686
self._ensure_real()
1671
2687
return self._real_repository._find_inconsistent_revision_parents(
2006
3033
def network_name(self):
2007
3034
return self._network_name
2009
def open(self, a_bzrdir, ignore_fallbacks=False):
2010
return a_bzrdir.open_branch(ignore_fallbacks=ignore_fallbacks)
3036
def open(self, a_bzrdir, name=None, ignore_fallbacks=False):
3037
return a_bzrdir.open_branch(name=name,
3038
ignore_fallbacks=ignore_fallbacks)
2012
def _vfs_initialize(self, a_bzrdir):
3040
def _vfs_initialize(self, a_bzrdir, name, append_revisions_only):
2013
3041
# Initialisation when using a local bzrdir object, or a non-vfs init
2014
3042
# method is not available on the server.
2015
3043
# self._custom_format is always set - the start of initialize ensures
2017
3045
if isinstance(a_bzrdir, RemoteBzrDir):
2018
3046
a_bzrdir._ensure_real()
2019
result = self._custom_format.initialize(a_bzrdir._real_bzrdir)
3047
result = self._custom_format.initialize(a_bzrdir._real_bzrdir,
3048
name, append_revisions_only=append_revisions_only)
2021
3050
# We assume the bzrdir is parameterised; it may not be.
2022
result = self._custom_format.initialize(a_bzrdir)
3051
result = self._custom_format.initialize(a_bzrdir, name,
3052
append_revisions_only=append_revisions_only)
2023
3053
if (isinstance(a_bzrdir, RemoteBzrDir) and
2024
3054
not isinstance(result, RemoteBranch)):
2025
result = RemoteBranch(a_bzrdir, a_bzrdir.find_repository(), result)
3055
result = RemoteBranch(a_bzrdir, a_bzrdir.find_repository(), result,
2028
def initialize(self, a_bzrdir):
3059
def initialize(self, a_bzrdir, name=None, repository=None,
3060
append_revisions_only=None):
2029
3061
# 1) get the network name to use.
2030
3062
if self._custom_format:
2031
3063
network_name = self._custom_format.network_name()
2033
3065
# Select the current bzrlib default and ask for that.
2034
reference_bzrdir_format = bzrdir.format_registry.get('default')()
3066
reference_bzrdir_format = _mod_bzrdir.format_registry.get('default')()
2035
3067
reference_format = reference_bzrdir_format.get_branch_format()
2036
3068
self._custom_format = reference_format
2037
3069
network_name = reference_format.network_name()
2038
3070
# Being asked to create on a non RemoteBzrDir:
2039
3071
if not isinstance(a_bzrdir, RemoteBzrDir):
2040
return self._vfs_initialize(a_bzrdir)
3072
return self._vfs_initialize(a_bzrdir, name=name,
3073
append_revisions_only=append_revisions_only)
2041
3074
medium = a_bzrdir._client._medium
2042
3075
if medium._is_remote_before((1, 13)):
2043
return self._vfs_initialize(a_bzrdir)
3076
return self._vfs_initialize(a_bzrdir, name=name,
3077
append_revisions_only=append_revisions_only)
2044
3078
# Creating on a remote bzr dir.
2045
3079
# 2) try direct creation via RPC
2046
3080
path = a_bzrdir._path_for_remote_call(a_bzrdir._client)
3081
if name is not None:
3082
# XXX JRV20100304: Support creating colocated branches
3083
raise errors.NoColocatedBranchSupport(self)
2047
3084
verb = 'BzrDir.create_branch'
2049
3086
response = a_bzrdir._call(verb, path, network_name)
2050
3087
except errors.UnknownSmartMethod:
2051
3088
# Fallback - use vfs methods
2052
3089
medium._remember_remote_is_before((1, 13))
2053
return self._vfs_initialize(a_bzrdir)
3090
return self._vfs_initialize(a_bzrdir, name=name,
3091
append_revisions_only=append_revisions_only)
2054
3092
if response[0] != 'ok':
2055
3093
raise errors.UnexpectedSmartServerResponse(response)
2056
3094
# Turn the response into a RemoteRepository object.
2057
3095
format = RemoteBranchFormat(network_name=response[1])
2058
3096
repo_format = response_tuple_to_repo_format(response[3:])
2059
if response[2] == '':
2060
repo_bzrdir = a_bzrdir
3097
repo_path = response[2]
3098
if repository is not None:
3099
remote_repo_url = urlutils.join(a_bzrdir.user_url, repo_path)
3100
url_diff = urlutils.relative_url(repository.user_url,
3103
raise AssertionError(
3104
'repository.user_url %r does not match URL from server '
3105
'response (%r + %r)'
3106
% (repository.user_url, a_bzrdir.user_url, repo_path))
3107
remote_repo = repository
2062
repo_bzrdir = RemoteBzrDir(
2063
a_bzrdir.root_transport.clone(response[2]), a_bzrdir._format,
2065
remote_repo = RemoteRepository(repo_bzrdir, repo_format)
3110
repo_bzrdir = a_bzrdir
3112
repo_bzrdir = RemoteBzrDir(
3113
a_bzrdir.root_transport.clone(repo_path), a_bzrdir._format,
3115
remote_repo = RemoteRepository(repo_bzrdir, repo_format)
2066
3116
remote_branch = RemoteBranch(a_bzrdir, remote_repo,
2067
format=format, setup_stacking=False)
3117
format=format, setup_stacking=False, name=name)
3118
if append_revisions_only:
3119
remote_branch.set_append_revisions_only(append_revisions_only)
2068
3120
# XXX: We know this is a new branch, so it must have revno 0, revid
2069
3121
# NULL_REVISION. Creating the branch locked would make this be unable
2070
3122
# to be wrong; here its simply very unlikely to be wrong. RBC 20090225
2089
3141
self._ensure_real()
2090
3142
return self._custom_format.supports_set_append_revisions_only()
3144
def _use_default_local_heads_to_fetch(self):
3145
# If the branch format is a metadir format *and* its heads_to_fetch
3146
# implementation is not overridden vs the base class, we can use the
3147
# base class logic rather than use the heads_to_fetch RPC. This is
3148
# usually cheaper in terms of net round trips, as the last-revision and
3149
# tags info fetched is cached and would be fetched anyway.
3151
if isinstance(self._custom_format, branch.BranchFormatMetadir):
3152
branch_class = self._custom_format._branch_class()
3153
heads_to_fetch_impl = branch_class.heads_to_fetch.im_func
3154
if heads_to_fetch_impl is branch.Branch.heads_to_fetch.im_func:
3159
class RemoteBranchStore(config.IniFileStore):
3160
"""Branch store which attempts to use HPSS calls to retrieve branch store.
3162
Note that this is specific to bzr-based formats.
3165
def __init__(self, branch):
3166
super(RemoteBranchStore, self).__init__()
3167
self.branch = branch
3169
self._real_store = None
3171
def lock_write(self, token=None):
3172
return self.branch.lock_write(token)
3175
return self.branch.unlock()
3179
# We need to be able to override the undecorated implementation
3180
self.save_without_locking()
3182
def save_without_locking(self):
3183
super(RemoteBranchStore, self).save()
3185
def external_url(self):
3186
return self.branch.user_url
3188
def _load_content(self):
3189
path = self.branch._remote_path()
3191
response, handler = self.branch._call_expecting_body(
3192
'Branch.get_config_file', path)
3193
except errors.UnknownSmartMethod:
3195
return self._real_store._load_content()
3196
if len(response) and response[0] != 'ok':
3197
raise errors.UnexpectedSmartServerResponse(response)
3198
return handler.read_body_bytes()
3200
def _save_content(self, content):
3201
path = self.branch._remote_path()
3203
response, handler = self.branch._call_with_body_bytes_expecting_body(
3204
'Branch.put_config_file', (path,
3205
self.branch._lock_token, self.branch._repo_lock_token),
3207
except errors.UnknownSmartMethod:
3209
return self._real_store._save_content(content)
3210
handler.cancel_read_body()
3211
if response != ('ok', ):
3212
raise errors.UnexpectedSmartServerResponse(response)
3214
def _ensure_real(self):
3215
self.branch._ensure_real()
3216
if self._real_store is None:
3217
self._real_store = config.BranchStore(self.branch)
2093
3220
class RemoteBranch(branch.Branch, _RpcHelper, lock._RelockDebugMixin):
2094
3221
"""Branch stored on a server accessed by HPSS RPC.
2592
3766
_override_hook_target=self, **kwargs)
2594
3768
@needs_read_lock
2595
def push(self, target, overwrite=False, stop_revision=None):
3769
def push(self, target, overwrite=False, stop_revision=None, lossy=False):
2596
3770
self._ensure_real()
2597
3771
return self._real_branch.push(
2598
target, overwrite=overwrite, stop_revision=stop_revision,
3772
target, overwrite=overwrite, stop_revision=stop_revision, lossy=lossy,
2599
3773
_override_hook_source_branch=self)
2601
3775
def is_locked(self):
2602
3776
return self._lock_count >= 1
2604
3778
@needs_read_lock
3779
def revision_id_to_dotted_revno(self, revision_id):
3780
"""Given a revision id, return its dotted revno.
3782
:return: a tuple like (1,) or (400,1,3).
3785
response = self._call('Branch.revision_id_to_revno',
3786
self._remote_path(), revision_id)
3787
except errors.UnknownSmartMethod:
3789
return self._real_branch.revision_id_to_dotted_revno(revision_id)
3790
if response[0] == 'ok':
3791
return tuple([int(x) for x in response[1:]])
3793
raise errors.UnexpectedSmartServerResponse(response)
2605
3796
def revision_id_to_revno(self, revision_id):
2607
return self._real_branch.revision_id_to_revno(revision_id)
3797
"""Given a revision id on the branch mainline, return its revno.
3802
response = self._call('Branch.revision_id_to_revno',
3803
self._remote_path(), revision_id)
3804
except errors.UnknownSmartMethod:
3806
return self._real_branch.revision_id_to_revno(revision_id)
3807
if response[0] == 'ok':
3808
if len(response) == 2:
3809
return int(response[1])
3810
raise NoSuchRevision(self, revision_id)
3812
raise errors.UnexpectedSmartServerResponse(response)
2609
3814
@needs_write_lock
2610
3815
def set_last_revision_info(self, revno, revision_id):
2611
3816
# XXX: These should be returned by the set_last_revision_info verb
2612
3817
old_revno, old_revid = self.last_revision_info()
2613
3818
self._run_pre_change_branch_tip_hooks(revno, revision_id)
2614
revision_id = ensure_null(revision_id)
3819
if not revision_id or not isinstance(revision_id, basestring):
3820
raise errors.InvalidRevisionId(revision_id=revision_id, branch=self)
2616
3822
response = self._call('Branch.set_last_revision_info',
2617
3823
self._remote_path(), self._lock_token, self._repo_lock_token,
2712
3955
medium = self._branch._client._medium
2713
3956
if medium._is_remote_before((1, 14)):
2714
3957
return self._vfs_set_option(value, name, section)
3958
if isinstance(value, dict):
3959
if medium._is_remote_before((2, 2)):
3960
return self._vfs_set_option(value, name, section)
3961
return self._set_config_option_dict(value, name, section)
3963
return self._set_config_option(value, name, section)
3965
def _set_config_option(self, value, name, section):
2716
3967
path = self._branch._remote_path()
2717
3968
response = self._branch._client.call('Branch.set_config_option',
2718
3969
path, self._branch._lock_token, self._branch._repo_lock_token,
2719
3970
value.encode('utf8'), name, section or '')
2720
3971
except errors.UnknownSmartMethod:
3972
medium = self._branch._client._medium
2721
3973
medium._remember_remote_is_before((1, 14))
2722
3974
return self._vfs_set_option(value, name, section)
2723
3975
if response != ():
2724
3976
raise errors.UnexpectedSmartServerResponse(response)
3978
def _serialize_option_dict(self, option_dict):
3980
for key, value in option_dict.items():
3981
if isinstance(key, unicode):
3982
key = key.encode('utf8')
3983
if isinstance(value, unicode):
3984
value = value.encode('utf8')
3985
utf8_dict[key] = value
3986
return bencode.bencode(utf8_dict)
3988
def _set_config_option_dict(self, value, name, section):
3990
path = self._branch._remote_path()
3991
serialised_dict = self._serialize_option_dict(value)
3992
response = self._branch._client.call(
3993
'Branch.set_config_option_dict',
3994
path, self._branch._lock_token, self._branch._repo_lock_token,
3995
serialised_dict, name, section or '')
3996
except errors.UnknownSmartMethod:
3997
medium = self._branch._client._medium
3998
medium._remember_remote_is_before((2, 2))
3999
return self._vfs_set_option(value, name, section)
4001
raise errors.UnexpectedSmartServerResponse(response)
2726
4003
def _real_object(self):
2727
4004
self._branch._ensure_real()
2728
4005
return self._branch._real_branch
2811
4091
'Missing key %r in context %r', key_err.args[0], context)
2814
if err.error_verb == 'IncompatibleRepositories':
2815
raise errors.IncompatibleRepositories(err.error_args[0],
2816
err.error_args[1], err.error_args[2])
2817
elif err.error_verb == 'NoSuchRevision':
2818
raise NoSuchRevision(find('branch'), err.error_args[0])
2819
elif err.error_verb == 'nosuchrevision':
2820
raise NoSuchRevision(find('repository'), err.error_args[0])
2821
elif err.error_tuple == ('nobranch',):
2822
raise errors.NotBranchError(path=find('bzrdir').root_transport.base)
2823
elif err.error_verb == 'norepository':
2824
raise errors.NoRepositoryPresent(find('bzrdir'))
2825
elif err.error_verb == 'LockContention':
2826
raise errors.LockContention('(remote lock)')
2827
elif err.error_verb == 'UnlockableTransport':
2828
raise errors.UnlockableTransport(find('bzrdir').root_transport)
2829
elif err.error_verb == 'LockFailed':
2830
raise errors.LockFailed(err.error_args[0], err.error_args[1])
2831
elif err.error_verb == 'TokenMismatch':
2832
raise errors.TokenMismatch(find('token'), '(remote token)')
2833
elif err.error_verb == 'Diverged':
2834
raise errors.DivergedBranches(find('branch'), find('other_branch'))
2835
elif err.error_verb == 'TipChangeRejected':
2836
raise errors.TipChangeRejected(err.error_args[0].decode('utf8'))
2837
elif err.error_verb == 'UnstackableBranchFormat':
2838
raise errors.UnstackableBranchFormat(*err.error_args)
2839
elif err.error_verb == 'UnstackableRepositoryFormat':
2840
raise errors.UnstackableRepositoryFormat(*err.error_args)
2841
elif err.error_verb == 'NotStacked':
2842
raise errors.NotStacked(branch=find('branch'))
2843
elif err.error_verb == 'PermissionDenied':
2845
if len(err.error_args) >= 2:
2846
extra = err.error_args[1]
2849
raise errors.PermissionDenied(path, extra=extra)
2850
elif err.error_verb == 'ReadError':
2852
raise errors.ReadError(path)
2853
elif err.error_verb == 'NoSuchFile':
2855
raise errors.NoSuchFile(path)
2856
elif err.error_verb == 'FileExists':
2857
raise errors.FileExists(err.error_args[0])
2858
elif err.error_verb == 'DirectoryNotEmpty':
2859
raise errors.DirectoryNotEmpty(err.error_args[0])
2860
elif err.error_verb == 'ShortReadvError':
2861
args = err.error_args
2862
raise errors.ShortReadvError(
2863
args[0], int(args[1]), int(args[2]), int(args[3]))
2864
elif err.error_verb in ('UnicodeEncodeError', 'UnicodeDecodeError'):
4095
translator = error_translators.get(err.error_verb)
4099
raise translator(err, find, get_path)
4101
translator = no_context_error_translators.get(err.error_verb)
4103
raise errors.UnknownErrorFromSmartServer(err)
4105
raise translator(err)
4108
error_translators.register('NoSuchRevision',
4109
lambda err, find, get_path: NoSuchRevision(
4110
find('branch'), err.error_args[0]))
4111
error_translators.register('nosuchrevision',
4112
lambda err, find, get_path: NoSuchRevision(
4113
find('repository'), err.error_args[0]))
4115
def _translate_nobranch_error(err, find, get_path):
4116
if len(err.error_args) >= 1:
4117
extra = err.error_args[0]
4120
return errors.NotBranchError(path=find('bzrdir').root_transport.base,
4123
error_translators.register('nobranch', _translate_nobranch_error)
4124
error_translators.register('norepository',
4125
lambda err, find, get_path: errors.NoRepositoryPresent(
4127
error_translators.register('UnlockableTransport',
4128
lambda err, find, get_path: errors.UnlockableTransport(
4129
find('bzrdir').root_transport))
4130
error_translators.register('TokenMismatch',
4131
lambda err, find, get_path: errors.TokenMismatch(
4132
find('token'), '(remote token)'))
4133
error_translators.register('Diverged',
4134
lambda err, find, get_path: errors.DivergedBranches(
4135
find('branch'), find('other_branch')))
4136
error_translators.register('NotStacked',
4137
lambda err, find, get_path: errors.NotStacked(branch=find('branch')))
4139
def _translate_PermissionDenied(err, find, get_path):
4141
if len(err.error_args) >= 2:
4142
extra = err.error_args[1]
4145
return errors.PermissionDenied(path, extra=extra)
4147
error_translators.register('PermissionDenied', _translate_PermissionDenied)
4148
error_translators.register('ReadError',
4149
lambda err, find, get_path: errors.ReadError(get_path()))
4150
error_translators.register('NoSuchFile',
4151
lambda err, find, get_path: errors.NoSuchFile(get_path()))
4152
error_translators.register('TokenLockingNotSupported',
4153
lambda err, find, get_path: errors.TokenLockingNotSupported(
4154
find('repository')))
4155
error_translators.register('UnsuspendableWriteGroup',
4156
lambda err, find, get_path: errors.UnsuspendableWriteGroup(
4157
repository=find('repository')))
4158
error_translators.register('UnresumableWriteGroup',
4159
lambda err, find, get_path: errors.UnresumableWriteGroup(
4160
repository=find('repository'), write_groups=err.error_args[0],
4161
reason=err.error_args[1]))
4162
no_context_error_translators.register('IncompatibleRepositories',
4163
lambda err: errors.IncompatibleRepositories(
4164
err.error_args[0], err.error_args[1], err.error_args[2]))
4165
no_context_error_translators.register('LockContention',
4166
lambda err: errors.LockContention('(remote lock)'))
4167
no_context_error_translators.register('LockFailed',
4168
lambda err: errors.LockFailed(err.error_args[0], err.error_args[1]))
4169
no_context_error_translators.register('TipChangeRejected',
4170
lambda err: errors.TipChangeRejected(err.error_args[0].decode('utf8')))
4171
no_context_error_translators.register('UnstackableBranchFormat',
4172
lambda err: errors.UnstackableBranchFormat(*err.error_args))
4173
no_context_error_translators.register('UnstackableRepositoryFormat',
4174
lambda err: errors.UnstackableRepositoryFormat(*err.error_args))
4175
no_context_error_translators.register('FileExists',
4176
lambda err: errors.FileExists(err.error_args[0]))
4177
no_context_error_translators.register('DirectoryNotEmpty',
4178
lambda err: errors.DirectoryNotEmpty(err.error_args[0]))
4180
def _translate_short_readv_error(err):
4181
args = err.error_args
4182
return errors.ShortReadvError(args[0], int(args[1]), int(args[2]),
4185
no_context_error_translators.register('ShortReadvError',
4186
_translate_short_readv_error)
4188
def _translate_unicode_error(err):
2865
4189
encoding = str(err.error_args[0]) # encoding must always be a string
2866
4190
val = err.error_args[1]
2867
4191
start = int(err.error_args[2])