89
# Note: RemoteBzrDirFormat is in bzrdir.py
91
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):
92
408
"""Control directory on a remote server, accessed via bzr:// or similar."""
94
410
def __init__(self, transport, format, _client=None, _force_probe=False):
1195
1719
raise errors.UnexpectedSmartServerResponse(response)
1197
1722
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,
1723
"""Create a descendent repository for new development.
1725
Unlike clone, this does not copy the settings of the repository.
1727
dest_repo = self._create_sprouting_repo(to_bzrdir, shared=False)
1202
1728
dest_repo.fetch(self, revision_id=revision_id)
1203
1729
return dest_repo
1731
def _create_sprouting_repo(self, a_bzrdir, shared):
1732
if not isinstance(a_bzrdir._format, self.bzrdir._format.__class__):
1733
# use target default format.
1734
dest_repo = a_bzrdir.create_repository()
1736
# Most control formats need the repository to be specifically
1737
# created, but on some old all-in-one formats it's not needed
1739
dest_repo = self._format.initialize(a_bzrdir, shared=shared)
1740
except errors.UninitializableFormat:
1741
dest_repo = a_bzrdir.open_repository()
1205
1744
### These methods are just thin shims to the VFS object for now.
1207
1747
def revision_tree(self, revision_id):
1209
return self._real_repository.revision_tree(revision_id)
1748
revision_id = _mod_revision.ensure_null(revision_id)
1749
if revision_id == _mod_revision.NULL_REVISION:
1750
return InventoryRevisionTree(self,
1751
Inventory(root_id=None), _mod_revision.NULL_REVISION)
1753
return list(self.revision_trees([revision_id]))[0]
1211
1755
def get_serializer_format(self):
1213
return self._real_repository.get_serializer_format()
1756
path = self.bzrdir._path_for_remote_call(self._client)
1758
response = self._call('VersionedFileRepository.get_serializer_format',
1760
except errors.UnknownSmartMethod:
1762
return self._real_repository.get_serializer_format()
1763
if response[0] != 'ok':
1764
raise errors.UnexpectedSmartServerResponse(response)
1215
1767
def get_commit_builder(self, branch, parents, config, timestamp=None,
1216
1768
timezone=None, committer=None, revprops=None,
1218
# FIXME: It ought to be possible to call this without immediately
1219
# triggering _ensure_real. For now it's the easiest thing to do.
1221
real_repo = self._real_repository
1222
builder = real_repo.get_commit_builder(branch, parents,
1223
config, timestamp=timestamp, timezone=timezone,
1224
committer=committer, revprops=revprops, revision_id=revision_id)
1769
revision_id=None, lossy=False):
1770
"""Obtain a CommitBuilder for this repository.
1772
:param branch: Branch to commit to.
1773
:param parents: Revision ids of the parents of the new revision.
1774
:param config: Configuration to use.
1775
:param timestamp: Optional timestamp recorded for commit.
1776
:param timezone: Optional timezone for timestamp.
1777
:param committer: Optional committer to set for commit.
1778
:param revprops: Optional dictionary of revision properties.
1779
:param revision_id: Optional revision id.
1780
:param lossy: Whether to discard data that can not be natively
1781
represented, when pushing to a foreign VCS
1783
if self._fallback_repositories and not self._format.supports_chks:
1784
raise errors.BzrError("Cannot commit directly to a stacked branch"
1785
" in pre-2a formats. See "
1786
"https://bugs.launchpad.net/bzr/+bug/375013 for details.")
1787
if self._format.rich_root_data:
1788
commit_builder_kls = vf_repository.VersionedFileRootCommitBuilder
1790
commit_builder_kls = vf_repository.VersionedFileCommitBuilder
1791
result = commit_builder_kls(self, parents, config,
1792
timestamp, timezone, committer, revprops, revision_id,
1794
self.start_write_group()
1227
1797
def add_fallback_repository(self, repository):
1228
1798
"""Add a repository to use for looking up data not held locally.
1280
1851
@needs_read_lock
1281
1852
def get_inventory(self, revision_id):
1853
return list(self.iter_inventories([revision_id]))[0]
1855
def _iter_inventories_rpc(self, revision_ids, ordering):
1856
if ordering is None:
1857
ordering = 'unordered'
1858
path = self.bzrdir._path_for_remote_call(self._client)
1859
body = "\n".join(revision_ids)
1860
response_tuple, response_handler = (
1861
self._call_with_body_bytes_expecting_body(
1862
"VersionedFileRepository.get_inventories",
1863
(path, ordering), body))
1864
if response_tuple[0] != "ok":
1865
raise errors.UnexpectedSmartServerResponse(response_tuple)
1866
deserializer = inventory_delta.InventoryDeltaDeserializer()
1867
byte_stream = response_handler.read_streamed_body()
1868
decoded = smart_repo._byte_stream_to_stream(byte_stream)
1870
# no results whatsoever
1872
src_format, stream = decoded
1873
if src_format.network_name() != self._format.network_name():
1874
raise AssertionError(
1875
"Mismatched RemoteRepository and stream src %r, %r" % (
1876
src_format.network_name(), self._format.network_name()))
1877
# ignore the src format, it's not really relevant
1878
prev_inv = Inventory(root_id=None,
1879
revision_id=_mod_revision.NULL_REVISION)
1880
# there should be just one substream, with inventory deltas
1881
substream_kind, substream = stream.next()
1882
if substream_kind != "inventory-deltas":
1883
raise AssertionError(
1884
"Unexpected stream %r received" % substream_kind)
1885
for record in substream:
1886
(parent_id, new_id, versioned_root, tree_references, invdelta) = (
1887
deserializer.parse_text_bytes(record.get_bytes_as("fulltext")))
1888
if parent_id != prev_inv.revision_id:
1889
raise AssertionError("invalid base %r != %r" % (parent_id,
1890
prev_inv.revision_id))
1891
inv = prev_inv.create_by_apply_delta(invdelta, new_id)
1892
yield inv, inv.revision_id
1895
def _iter_inventories_vfs(self, revision_ids, ordering=None):
1282
1896
self._ensure_real()
1283
return self._real_repository.get_inventory(revision_id)
1897
return self._real_repository._iter_inventories(revision_ids, ordering)
1285
1899
def iter_inventories(self, revision_ids, ordering=None):
1287
return self._real_repository.iter_inventories(revision_ids, ordering)
1900
"""Get many inventories by revision_ids.
1902
This will buffer some or all of the texts used in constructing the
1903
inventories in memory, but will only parse a single inventory at a
1906
:param revision_ids: The expected revision ids of the inventories.
1907
:param ordering: optional ordering, e.g. 'topological'. If not
1908
specified, the order of revision_ids will be preserved (by
1909
buffering if necessary).
1910
:return: An iterator of inventories.
1912
if ((None in revision_ids)
1913
or (_mod_revision.NULL_REVISION in revision_ids)):
1914
raise ValueError('cannot get null revision inventory')
1915
for inv, revid in self._iter_inventories(revision_ids, ordering):
1917
raise errors.NoSuchRevision(self, revid)
1920
def _iter_inventories(self, revision_ids, ordering=None):
1921
if len(revision_ids) == 0:
1923
missing = set(revision_ids)
1924
if ordering is None:
1925
order_as_requested = True
1927
order = list(revision_ids)
1929
next_revid = order.pop()
1931
order_as_requested = False
1932
if ordering != 'unordered' and self._fallback_repositories:
1933
raise ValueError('unsupported ordering %r' % ordering)
1934
iter_inv_fns = [self._iter_inventories_rpc] + [
1935
fallback._iter_inventories for fallback in
1936
self._fallback_repositories]
1938
for iter_inv in iter_inv_fns:
1939
request = [revid for revid in revision_ids if revid in missing]
1940
for inv, revid in iter_inv(request, ordering):
1943
missing.remove(inv.revision_id)
1944
if ordering != 'unordered':
1948
if order_as_requested:
1949
# Yield as many results as we can while preserving order.
1950
while next_revid in invs:
1951
inv = invs.pop(next_revid)
1952
yield inv, inv.revision_id
1954
next_revid = order.pop()
1956
# We still want to fully consume the stream, just
1957
# in case it is not actually finished at this point
1960
except errors.UnknownSmartMethod:
1961
for inv, revid in self._iter_inventories_vfs(revision_ids, ordering):
1965
if order_as_requested:
1966
if next_revid is not None:
1967
yield None, next_revid
1970
yield invs.get(revid), revid
1973
yield None, missing.pop()
1289
1975
@needs_read_lock
1290
1976
def get_revision(self, revision_id):
1292
return self._real_repository.get_revision(revision_id)
1977
return self.get_revisions([revision_id])[0]
1294
1979
def get_transaction(self):
1295
1980
self._ensure_real()
1328
2025
included_keys = result_set.intersection(result_parents)
1329
2026
start_keys = result_set.difference(included_keys)
1330
2027
exclude_keys = result_parents.difference(result_set)
1331
result = graph.SearchResult(start_keys, exclude_keys,
2028
result = vf_search.SearchResult(start_keys, exclude_keys,
1332
2029
len(result_set), result_set)
1335
2032
@needs_read_lock
1336
def search_missing_revision_ids(self, other, revision_id=None, find_ghosts=True):
2033
def search_missing_revision_ids(self, other,
2034
revision_id=symbol_versioning.DEPRECATED_PARAMETER,
2035
find_ghosts=True, revision_ids=None, if_present_ids=None,
1337
2037
"""Return the revision ids that other has that this does not.
1339
2039
These are returned in topological order.
1341
2041
revision_id: only return revision ids included by revision_id.
1343
return repository.InterRepository.get(
1344
other, self).search_missing_revision_ids(revision_id, find_ghosts)
2043
if symbol_versioning.deprecated_passed(revision_id):
2044
symbol_versioning.warn(
2045
'search_missing_revision_ids(revision_id=...) was '
2046
'deprecated in 2.4. Use revision_ids=[...] instead.',
2047
DeprecationWarning, stacklevel=2)
2048
if revision_ids is not None:
2049
raise AssertionError(
2050
'revision_ids is mutually exclusive with revision_id')
2051
if revision_id is not None:
2052
revision_ids = [revision_id]
2053
inter_repo = _mod_repository.InterRepository.get(other, self)
2054
return inter_repo.search_missing_revision_ids(
2055
find_ghosts=find_ghosts, revision_ids=revision_ids,
2056
if_present_ids=if_present_ids, limit=limit)
1346
def fetch(self, source, revision_id=None, pb=None, find_ghosts=False,
2058
def fetch(self, source, revision_id=None, find_ghosts=False,
1347
2059
fetch_spec=None):
1348
2060
# No base implementation to use as RemoteRepository is not a subclass
1349
2061
# of Repository; so this is a copy of Repository.fetch().
1388
2106
return self._real_repository._get_versioned_file_checker(
1389
2107
revisions, revision_versions_cache)
2109
def _iter_files_bytes_rpc(self, desired_files, absent):
2110
path = self.bzrdir._path_for_remote_call(self._client)
2113
for (file_id, revid, identifier) in desired_files:
2114
lines.append("%s\0%s" % (
2115
osutils.safe_file_id(file_id),
2116
osutils.safe_revision_id(revid)))
2117
identifiers.append(identifier)
2118
(response_tuple, response_handler) = (
2119
self._call_with_body_bytes_expecting_body(
2120
"Repository.iter_files_bytes", (path, ), "\n".join(lines)))
2121
if response_tuple != ('ok', ):
2122
response_handler.cancel_read_body()
2123
raise errors.UnexpectedSmartServerResponse(response_tuple)
2124
byte_stream = response_handler.read_streamed_body()
2125
def decompress_stream(start, byte_stream, unused):
2126
decompressor = zlib.decompressobj()
2127
yield decompressor.decompress(start)
2128
while decompressor.unused_data == "":
2130
data = byte_stream.next()
2131
except StopIteration:
2133
yield decompressor.decompress(data)
2134
yield decompressor.flush()
2135
unused.append(decompressor.unused_data)
2138
while not "\n" in unused:
2139
unused += byte_stream.next()
2140
header, rest = unused.split("\n", 1)
2141
args = header.split("\0")
2142
if args[0] == "absent":
2143
absent[identifiers[int(args[3])]] = (args[1], args[2])
2146
elif args[0] == "ok":
2149
raise errors.UnexpectedSmartServerResponse(args)
2151
yield (identifiers[idx],
2152
decompress_stream(rest, byte_stream, unused_chunks))
2153
unused = "".join(unused_chunks)
1391
2155
def iter_files_bytes(self, desired_files):
1392
2156
"""See Repository.iter_file_bytes.
1395
return self._real_repository.iter_files_bytes(desired_files)
2160
for (identifier, bytes_iterator) in self._iter_files_bytes_rpc(
2161
desired_files, absent):
2162
yield identifier, bytes_iterator
2163
for fallback in self._fallback_repositories:
2166
desired_files = [(key[0], key[1], identifier) for
2167
(identifier, key) in absent.iteritems()]
2168
for (identifier, bytes_iterator) in fallback.iter_files_bytes(desired_files):
2169
del absent[identifier]
2170
yield identifier, bytes_iterator
2172
# There may be more missing items, but raise an exception
2174
missing_identifier = absent.keys()[0]
2175
missing_key = absent[missing_identifier]
2176
raise errors.RevisionNotPresent(revision_id=missing_key[1],
2177
file_id=missing_key[0])
2178
except errors.UnknownSmartMethod:
2180
for (identifier, bytes_iterator) in (
2181
self._real_repository.iter_files_bytes(desired_files)):
2182
yield identifier, bytes_iterator
2184
def get_cached_parent_map(self, revision_ids):
2185
"""See bzrlib.CachingParentsProvider.get_cached_parent_map"""
2186
return self._unstacked_provider.get_cached_parent_map(revision_ids)
1397
2188
def get_parent_map(self, revision_ids):
1398
2189
"""See bzrlib.Graph.get_parent_map()."""
1532
2312
@needs_read_lock
1533
2313
def get_signature_text(self, revision_id):
1535
return self._real_repository.get_signature_text(revision_id)
2314
path = self.bzrdir._path_for_remote_call(self._client)
2316
response_tuple, response_handler = self._call_expecting_body(
2317
'Repository.get_revision_signature_text', path, revision_id)
2318
except errors.UnknownSmartMethod:
2320
return self._real_repository.get_signature_text(revision_id)
2321
except errors.NoSuchRevision, err:
2322
for fallback in self._fallback_repositories:
2324
return fallback.get_signature_text(revision_id)
2325
except errors.NoSuchRevision:
2329
if response_tuple[0] != 'ok':
2330
raise errors.UnexpectedSmartServerResponse(response_tuple)
2331
return response_handler.read_body_bytes()
1537
2333
@needs_read_lock
1538
2334
def _get_inventory_xml(self, revision_id):
2335
# This call is used by older working tree formats,
2336
# which stored a serialized basis inventory.
1539
2337
self._ensure_real()
1540
2338
return self._real_repository._get_inventory_xml(revision_id)
1542
2341
def reconcile(self, other=None, thorough=False):
1544
return self._real_repository.reconcile(other=other, thorough=thorough)
2342
from bzrlib.reconcile import RepoReconciler
2343
path = self.bzrdir._path_for_remote_call(self._client)
2345
response, handler = self._call_expecting_body(
2346
'Repository.reconcile', path, self._lock_token)
2347
except (errors.UnknownSmartMethod, errors.TokenLockingNotSupported):
2349
return self._real_repository.reconcile(other=other, thorough=thorough)
2350
if response != ('ok', ):
2351
raise errors.UnexpectedSmartServerResponse(response)
2352
body = handler.read_body_bytes()
2353
result = RepoReconciler(self)
2354
for line in body.split('\n'):
2357
key, val_text = line.split(':')
2358
if key == "garbage_inventories":
2359
result.garbage_inventories = int(val_text)
2360
elif key == "inconsistent_parents":
2361
result.inconsistent_parents = int(val_text)
2363
mutter("unknown reconcile key %r" % key)
1546
2366
def all_revision_ids(self):
1548
return self._real_repository.all_revision_ids()
2367
path = self.bzrdir._path_for_remote_call(self._client)
2369
response_tuple, response_handler = self._call_expecting_body(
2370
"Repository.all_revision_ids", path)
2371
except errors.UnknownSmartMethod:
2373
return self._real_repository.all_revision_ids()
2374
if response_tuple != ("ok", ):
2375
raise errors.UnexpectedSmartServerResponse(response_tuple)
2376
revids = set(response_handler.read_body_bytes().splitlines())
2377
for fallback in self._fallback_repositories:
2378
revids.update(set(fallback.all_revision_ids()))
2381
def _filtered_revision_trees(self, revision_ids, file_ids):
2382
"""Return Tree for a revision on this branch with only some files.
2384
:param revision_ids: a sequence of revision-ids;
2385
a revision-id may not be None or 'null:'
2386
:param file_ids: if not None, the result is filtered
2387
so that only those file-ids, their parents and their
2388
children are included.
2390
inventories = self.iter_inventories(revision_ids)
2391
for inv in inventories:
2392
# Should we introduce a FilteredRevisionTree class rather
2393
# than pre-filter the inventory here?
2394
filtered_inv = inv.filter(file_ids)
2395
yield InventoryRevisionTree(self, filtered_inv, filtered_inv.revision_id)
1550
2397
@needs_read_lock
1551
2398
def get_deltas_for_revisions(self, revisions, specific_fileids=None):
1553
return self._real_repository.get_deltas_for_revisions(revisions,
1554
specific_fileids=specific_fileids)
2399
medium = self._client._medium
2400
if medium._is_remote_before((1, 2)):
2402
for delta in self._real_repository.get_deltas_for_revisions(
2403
revisions, specific_fileids):
2406
# Get the revision-ids of interest
2407
required_trees = set()
2408
for revision in revisions:
2409
required_trees.add(revision.revision_id)
2410
required_trees.update(revision.parent_ids[:1])
2412
# Get the matching filtered trees. Note that it's more
2413
# efficient to pass filtered trees to changes_from() rather
2414
# than doing the filtering afterwards. changes_from() could
2415
# arguably do the filtering itself but it's path-based, not
2416
# file-id based, so filtering before or afterwards is
2418
if specific_fileids is None:
2419
trees = dict((t.get_revision_id(), t) for
2420
t in self.revision_trees(required_trees))
2422
trees = dict((t.get_revision_id(), t) for
2423
t in self._filtered_revision_trees(required_trees,
2426
# Calculate the deltas
2427
for revision in revisions:
2428
if not revision.parent_ids:
2429
old_tree = self.revision_tree(_mod_revision.NULL_REVISION)
2431
old_tree = trees[revision.parent_ids[0]]
2432
yield trees[revision.revision_id].changes_from(old_tree)
1556
2434
@needs_read_lock
1557
2435
def get_revision_delta(self, revision_id, specific_fileids=None):
1559
return self._real_repository.get_revision_delta(revision_id,
1560
specific_fileids=specific_fileids)
2436
r = self.get_revision(revision_id)
2437
return list(self.get_deltas_for_revisions([r],
2438
specific_fileids=specific_fileids))[0]
1562
2440
@needs_read_lock
1563
2441
def revision_trees(self, revision_ids):
1565
return self._real_repository.revision_trees(revision_ids)
2442
inventories = self.iter_inventories(revision_ids)
2443
for inv in inventories:
2444
yield InventoryRevisionTree(self, inv, inv.revision_id)
1567
2446
@needs_read_lock
1568
2447
def get_revision_reconcile(self, revision_id):
1680
2572
self._ensure_real()
1681
2573
return self._real_repository.texts
2575
def _iter_revisions_rpc(self, revision_ids):
2576
body = "\n".join(revision_ids)
2577
path = self.bzrdir._path_for_remote_call(self._client)
2578
response_tuple, response_handler = (
2579
self._call_with_body_bytes_expecting_body(
2580
"Repository.iter_revisions", (path, ), body))
2581
if response_tuple[0] != "ok":
2582
raise errors.UnexpectedSmartServerResponse(response_tuple)
2583
serializer_format = response_tuple[1]
2584
serializer = serializer_format_registry.get(serializer_format)
2585
byte_stream = response_handler.read_streamed_body()
2586
decompressor = zlib.decompressobj()
2588
for bytes in byte_stream:
2589
chunks.append(decompressor.decompress(bytes))
2590
if decompressor.unused_data != "":
2591
chunks.append(decompressor.flush())
2592
yield serializer.read_revision_from_string("".join(chunks))
2593
unused = decompressor.unused_data
2594
decompressor = zlib.decompressobj()
2595
chunks = [decompressor.decompress(unused)]
2596
chunks.append(decompressor.flush())
2597
text = "".join(chunks)
2599
yield serializer.read_revision_from_string("".join(chunks))
1683
2601
@needs_read_lock
1684
2602
def get_revisions(self, revision_ids):
1686
return self._real_repository.get_revisions(revision_ids)
2603
if revision_ids is None:
2604
revision_ids = self.all_revision_ids()
2606
for rev_id in revision_ids:
2607
if not rev_id or not isinstance(rev_id, basestring):
2608
raise errors.InvalidRevisionId(
2609
revision_id=rev_id, branch=self)
2611
missing = set(revision_ids)
2613
for rev in self._iter_revisions_rpc(revision_ids):
2614
missing.remove(rev.revision_id)
2615
revs[rev.revision_id] = rev
2616
except errors.UnknownSmartMethod:
2618
return self._real_repository.get_revisions(revision_ids)
2619
for fallback in self._fallback_repositories:
2622
for revid in list(missing):
2623
# XXX JRV 2011-11-20: It would be nice if there was a
2624
# public method on Repository that could be used to query
2625
# for revision objects *without* failing completely if one
2626
# was missing. There is VersionedFileRepository._iter_revisions,
2627
# but unfortunately that's private and not provided by
2628
# all repository implementations.
2630
revs[revid] = fallback.get_revision(revid)
2631
except errors.NoSuchRevision:
2634
missing.remove(revid)
2636
raise errors.NoSuchRevision(self, list(missing)[0])
2637
return [revs[revid] for revid in revision_ids]
1688
2639
def supports_rich_root(self):
1689
2640
return self._format.rich_root_data
2642
@symbol_versioning.deprecated_method(symbol_versioning.deprecated_in((2, 4, 0)))
1691
2643
def iter_reverse_revision_history(self, revision_id):
1692
2644
self._ensure_real()
1693
2645
return self._real_repository.iter_reverse_revision_history(revision_id)
1696
2648
def _serializer(self):
1697
2649
return self._format._serializer
1699
2652
def store_revision_signature(self, gpg_strategy, plaintext, revision_id):
1701
return self._real_repository.store_revision_signature(
1702
gpg_strategy, plaintext, revision_id)
2653
signature = gpg_strategy.sign(plaintext)
2654
self.add_signature_text(revision_id, signature)
1704
2656
def add_signature_text(self, revision_id, signature):
1706
return self._real_repository.add_signature_text(revision_id, signature)
2657
if self._real_repository:
2658
# If there is a real repository the write group will
2659
# be in the real repository as well, so use that:
2661
return self._real_repository.add_signature_text(
2662
revision_id, signature)
2663
path = self.bzrdir._path_for_remote_call(self._client)
2664
response, handler = self._call_with_body_bytes_expecting_body(
2665
'Repository.add_signature_text', (path, self._lock_token,
2666
revision_id) + tuple(self._write_group_tokens), signature)
2667
handler.cancel_read_body()
2669
if response[0] != 'ok':
2670
raise errors.UnexpectedSmartServerResponse(response)
2671
self._write_group_tokens = response[1:]
1708
2673
def has_signature_for_revision_id(self, revision_id):
1710
return self._real_repository.has_signature_for_revision_id(revision_id)
2674
path = self.bzrdir._path_for_remote_call(self._client)
2676
response = self._call('Repository.has_signature_for_revision_id',
2678
except errors.UnknownSmartMethod:
2680
return self._real_repository.has_signature_for_revision_id(
2682
if response[0] not in ('yes', 'no'):
2683
raise SmartProtocolError('unexpected response code %s' % (response,))
2684
if response[0] == 'yes':
2686
for fallback in self._fallback_repositories:
2687
if fallback.has_signature_for_revision_id(revision_id):
2692
def verify_revision_signature(self, revision_id, gpg_strategy):
2693
if not self.has_signature_for_revision_id(revision_id):
2694
return gpg.SIGNATURE_NOT_SIGNED, None
2695
signature = self.get_signature_text(revision_id)
2697
testament = _mod_testament.Testament.from_revision(self, revision_id)
2698
plaintext = testament.as_short_text()
2700
return gpg_strategy.verify(signature, plaintext)
1712
2702
def item_keys_introduced_by(self, revision_ids, _files_pb=None):
1713
2703
self._ensure_real()
1714
2704
return self._real_repository.item_keys_introduced_by(revision_ids,
1715
2705
_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
2707
def _find_inconsistent_revision_parents(self, revisions_iterator=None):
1723
2708
self._ensure_real()
1724
2709
return self._real_repository._find_inconsistent_revision_parents(
2071
3067
if isinstance(a_bzrdir, RemoteBzrDir):
2072
3068
a_bzrdir._ensure_real()
2073
3069
result = self._custom_format.initialize(a_bzrdir._real_bzrdir,
3070
name, append_revisions_only=append_revisions_only)
2076
3072
# We assume the bzrdir is parameterised; it may not be.
2077
result = self._custom_format.initialize(a_bzrdir, name)
3073
result = self._custom_format.initialize(a_bzrdir, name,
3074
append_revisions_only=append_revisions_only)
2078
3075
if (isinstance(a_bzrdir, RemoteBzrDir) and
2079
3076
not isinstance(result, RemoteBranch)):
2080
3077
result = RemoteBranch(a_bzrdir, a_bzrdir.find_repository(), result,
2084
def initialize(self, a_bzrdir, name=None):
3081
def initialize(self, a_bzrdir, name=None, repository=None,
3082
append_revisions_only=None):
2085
3083
# 1) get the network name to use.
2086
3084
if self._custom_format:
2087
3085
network_name = self._custom_format.network_name()
2089
3087
# Select the current bzrlib default and ask for that.
2090
reference_bzrdir_format = bzrdir.format_registry.get('default')()
3088
reference_bzrdir_format = _mod_bzrdir.format_registry.get('default')()
2091
3089
reference_format = reference_bzrdir_format.get_branch_format()
2092
3090
self._custom_format = reference_format
2093
3091
network_name = reference_format.network_name()
2094
3092
# Being asked to create on a non RemoteBzrDir:
2095
3093
if not isinstance(a_bzrdir, RemoteBzrDir):
2096
return self._vfs_initialize(a_bzrdir, name=name)
3094
return self._vfs_initialize(a_bzrdir, name=name,
3095
append_revisions_only=append_revisions_only)
2097
3096
medium = a_bzrdir._client._medium
2098
3097
if medium._is_remote_before((1, 13)):
2099
return self._vfs_initialize(a_bzrdir, name=name)
3098
return self._vfs_initialize(a_bzrdir, name=name,
3099
append_revisions_only=append_revisions_only)
2100
3100
# Creating on a remote bzr dir.
2101
3101
# 2) try direct creation via RPC
2102
3102
path = a_bzrdir._path_for_remote_call(a_bzrdir._client)
2148
3163
self._ensure_real()
2149
3164
return self._custom_format.supports_set_append_revisions_only()
3166
def _use_default_local_heads_to_fetch(self):
3167
# If the branch format is a metadir format *and* its heads_to_fetch
3168
# implementation is not overridden vs the base class, we can use the
3169
# base class logic rather than use the heads_to_fetch RPC. This is
3170
# usually cheaper in terms of net round trips, as the last-revision and
3171
# tags info fetched is cached and would be fetched anyway.
3173
if isinstance(self._custom_format, branch.BranchFormatMetadir):
3174
branch_class = self._custom_format._branch_class()
3175
heads_to_fetch_impl = branch_class.heads_to_fetch.im_func
3176
if heads_to_fetch_impl is branch.Branch.heads_to_fetch.im_func:
3181
class RemoteBranchStore(config.IniFileStore):
3182
"""Branch store which attempts to use HPSS calls to retrieve branch store.
3184
Note that this is specific to bzr-based formats.
3187
def __init__(self, branch):
3188
super(RemoteBranchStore, self).__init__()
3189
self.branch = branch
3191
self._real_store = None
3193
def lock_write(self, token=None):
3194
return self.branch.lock_write(token)
3197
return self.branch.unlock()
3201
# We need to be able to override the undecorated implementation
3202
self.save_without_locking()
3204
def save_without_locking(self):
3205
super(RemoteBranchStore, self).save()
3207
def external_url(self):
3208
return self.branch.user_url
3210
def _load_content(self):
3211
path = self.branch._remote_path()
3213
response, handler = self.branch._call_expecting_body(
3214
'Branch.get_config_file', path)
3215
except errors.UnknownSmartMethod:
3217
return self._real_store._load_content()
3218
if len(response) and response[0] != 'ok':
3219
raise errors.UnexpectedSmartServerResponse(response)
3220
return handler.read_body_bytes()
3222
def _save_content(self, content):
3223
path = self.branch._remote_path()
3225
response, handler = self.branch._call_with_body_bytes_expecting_body(
3226
'Branch.put_config_file', (path,
3227
self.branch._lock_token, self.branch._repo_lock_token),
3229
except errors.UnknownSmartMethod:
3231
return self._real_store._save_content(content)
3232
handler.cancel_read_body()
3233
if response != ('ok', ):
3234
raise errors.UnexpectedSmartServerResponse(response)
3236
def _ensure_real(self):
3237
self.branch._ensure_real()
3238
if self._real_store is None:
3239
self._real_store = config.BranchStore(self.branch)
2152
3242
class RemoteBranch(branch.Branch, _RpcHelper, lock._RelockDebugMixin):
2153
3243
"""Branch stored on a server accessed by HPSS RPC.
2654
3788
_override_hook_target=self, **kwargs)
2656
3790
@needs_read_lock
2657
def push(self, target, overwrite=False, stop_revision=None):
3791
def push(self, target, overwrite=False, stop_revision=None, lossy=False):
2658
3792
self._ensure_real()
2659
3793
return self._real_branch.push(
2660
target, overwrite=overwrite, stop_revision=stop_revision,
3794
target, overwrite=overwrite, stop_revision=stop_revision, lossy=lossy,
2661
3795
_override_hook_source_branch=self)
2663
3797
def is_locked(self):
2664
3798
return self._lock_count >= 1
2666
3800
@needs_read_lock
3801
def revision_id_to_dotted_revno(self, revision_id):
3802
"""Given a revision id, return its dotted revno.
3804
:return: a tuple like (1,) or (400,1,3).
3807
response = self._call('Branch.revision_id_to_revno',
3808
self._remote_path(), revision_id)
3809
except errors.UnknownSmartMethod:
3811
return self._real_branch.revision_id_to_dotted_revno(revision_id)
3812
if response[0] == 'ok':
3813
return tuple([int(x) for x in response[1:]])
3815
raise errors.UnexpectedSmartServerResponse(response)
2667
3818
def revision_id_to_revno(self, revision_id):
2669
return self._real_branch.revision_id_to_revno(revision_id)
3819
"""Given a revision id on the branch mainline, return its revno.
3824
response = self._call('Branch.revision_id_to_revno',
3825
self._remote_path(), revision_id)
3826
except errors.UnknownSmartMethod:
3828
return self._real_branch.revision_id_to_revno(revision_id)
3829
if response[0] == 'ok':
3830
if len(response) == 2:
3831
return int(response[1])
3832
raise NoSuchRevision(self, revision_id)
3834
raise errors.UnexpectedSmartServerResponse(response)
2671
3836
@needs_write_lock
2672
3837
def set_last_revision_info(self, revno, revision_id):
2673
3838
# XXX: These should be returned by the set_last_revision_info verb
2674
3839
old_revno, old_revid = self.last_revision_info()
2675
3840
self._run_pre_change_branch_tip_hooks(revno, revision_id)
2676
revision_id = ensure_null(revision_id)
3841
if not revision_id or not isinstance(revision_id, basestring):
3842
raise errors.InvalidRevisionId(revision_id=revision_id, branch=self)
2678
3844
response = self._call('Branch.set_last_revision_info',
2679
3845
self._remote_path(), self._lock_token, self._repo_lock_token,
2774
3977
medium = self._branch._client._medium
2775
3978
if medium._is_remote_before((1, 14)):
2776
3979
return self._vfs_set_option(value, name, section)
3980
if isinstance(value, dict):
3981
if medium._is_remote_before((2, 2)):
3982
return self._vfs_set_option(value, name, section)
3983
return self._set_config_option_dict(value, name, section)
3985
return self._set_config_option(value, name, section)
3987
def _set_config_option(self, value, name, section):
2778
3989
path = self._branch._remote_path()
2779
3990
response = self._branch._client.call('Branch.set_config_option',
2780
3991
path, self._branch._lock_token, self._branch._repo_lock_token,
2781
3992
value.encode('utf8'), name, section or '')
2782
3993
except errors.UnknownSmartMethod:
3994
medium = self._branch._client._medium
2783
3995
medium._remember_remote_is_before((1, 14))
2784
3996
return self._vfs_set_option(value, name, section)
2785
3997
if response != ():
2786
3998
raise errors.UnexpectedSmartServerResponse(response)
4000
def _serialize_option_dict(self, option_dict):
4002
for key, value in option_dict.items():
4003
if isinstance(key, unicode):
4004
key = key.encode('utf8')
4005
if isinstance(value, unicode):
4006
value = value.encode('utf8')
4007
utf8_dict[key] = value
4008
return bencode.bencode(utf8_dict)
4010
def _set_config_option_dict(self, value, name, section):
4012
path = self._branch._remote_path()
4013
serialised_dict = self._serialize_option_dict(value)
4014
response = self._branch._client.call(
4015
'Branch.set_config_option_dict',
4016
path, self._branch._lock_token, self._branch._repo_lock_token,
4017
serialised_dict, name, section or '')
4018
except errors.UnknownSmartMethod:
4019
medium = self._branch._client._medium
4020
medium._remember_remote_is_before((2, 2))
4021
return self._vfs_set_option(value, name, section)
4023
raise errors.UnexpectedSmartServerResponse(response)
2788
4025
def _real_object(self):
2789
4026
self._branch._ensure_real()
2790
4027
return self._branch._real_branch
2873
4113
'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'):
4117
translator = error_translators.get(err.error_verb)
4121
raise translator(err, find, get_path)
4123
translator = no_context_error_translators.get(err.error_verb)
4125
raise errors.UnknownErrorFromSmartServer(err)
4127
raise translator(err)
4130
error_translators.register('NoSuchRevision',
4131
lambda err, find, get_path: NoSuchRevision(
4132
find('branch'), err.error_args[0]))
4133
error_translators.register('nosuchrevision',
4134
lambda err, find, get_path: NoSuchRevision(
4135
find('repository'), err.error_args[0]))
4137
def _translate_nobranch_error(err, find, get_path):
4138
if len(err.error_args) >= 1:
4139
extra = err.error_args[0]
4142
return errors.NotBranchError(path=find('bzrdir').root_transport.base,
4145
error_translators.register('nobranch', _translate_nobranch_error)
4146
error_translators.register('norepository',
4147
lambda err, find, get_path: errors.NoRepositoryPresent(
4149
error_translators.register('UnlockableTransport',
4150
lambda err, find, get_path: errors.UnlockableTransport(
4151
find('bzrdir').root_transport))
4152
error_translators.register('TokenMismatch',
4153
lambda err, find, get_path: errors.TokenMismatch(
4154
find('token'), '(remote token)'))
4155
error_translators.register('Diverged',
4156
lambda err, find, get_path: errors.DivergedBranches(
4157
find('branch'), find('other_branch')))
4158
error_translators.register('NotStacked',
4159
lambda err, find, get_path: errors.NotStacked(branch=find('branch')))
4161
def _translate_PermissionDenied(err, find, get_path):
4163
if len(err.error_args) >= 2:
4164
extra = err.error_args[1]
4167
return errors.PermissionDenied(path, extra=extra)
4169
error_translators.register('PermissionDenied', _translate_PermissionDenied)
4170
error_translators.register('ReadError',
4171
lambda err, find, get_path: errors.ReadError(get_path()))
4172
error_translators.register('NoSuchFile',
4173
lambda err, find, get_path: errors.NoSuchFile(get_path()))
4174
error_translators.register('TokenLockingNotSupported',
4175
lambda err, find, get_path: errors.TokenLockingNotSupported(
4176
find('repository')))
4177
error_translators.register('UnsuspendableWriteGroup',
4178
lambda err, find, get_path: errors.UnsuspendableWriteGroup(
4179
repository=find('repository')))
4180
error_translators.register('UnresumableWriteGroup',
4181
lambda err, find, get_path: errors.UnresumableWriteGroup(
4182
repository=find('repository'), write_groups=err.error_args[0],
4183
reason=err.error_args[1]))
4184
no_context_error_translators.register('IncompatibleRepositories',
4185
lambda err: errors.IncompatibleRepositories(
4186
err.error_args[0], err.error_args[1], err.error_args[2]))
4187
no_context_error_translators.register('LockContention',
4188
lambda err: errors.LockContention('(remote lock)'))
4189
no_context_error_translators.register('LockFailed',
4190
lambda err: errors.LockFailed(err.error_args[0], err.error_args[1]))
4191
no_context_error_translators.register('TipChangeRejected',
4192
lambda err: errors.TipChangeRejected(err.error_args[0].decode('utf8')))
4193
no_context_error_translators.register('UnstackableBranchFormat',
4194
lambda err: errors.UnstackableBranchFormat(*err.error_args))
4195
no_context_error_translators.register('UnstackableRepositoryFormat',
4196
lambda err: errors.UnstackableRepositoryFormat(*err.error_args))
4197
no_context_error_translators.register('FileExists',
4198
lambda err: errors.FileExists(err.error_args[0]))
4199
no_context_error_translators.register('DirectoryNotEmpty',
4200
lambda err: errors.DirectoryNotEmpty(err.error_args[0]))
4202
def _translate_short_readv_error(err):
4203
args = err.error_args
4204
return errors.ShortReadvError(args[0], int(args[1]), int(args[2]),
4207
no_context_error_translators.register('ShortReadvError',
4208
_translate_short_readv_error)
4210
def _translate_unicode_error(err):
2932
4211
encoding = str(err.error_args[0]) # encoding must always be a string
2933
4212
val = err.error_args[1]
2934
4213
start = int(err.error_args[2])