87
# Note: RemoteBzrDirFormat is in bzrdir.py
89
class RemoteBzrDir(BzrDir, _RpcHelper):
108
# Note that RemoteBzrDirProber lives in bzrlib.bzrdir so bzrlib.remote
109
# does not have to be imported unless a remote format is involved.
111
class RemoteBzrDirFormat(_mod_bzrdir.BzrDirMetaFormat1):
112
"""Format representing bzrdirs accessed via a smart server"""
114
supports_workingtrees = False
117
_mod_bzrdir.BzrDirMetaFormat1.__init__(self)
118
# XXX: It's a bit ugly that the network name is here, because we'd
119
# like to believe that format objects are stateless or at least
120
# immutable, However, we do at least avoid mutating the name after
121
# it's returned. See <https://bugs.launchpad.net/bzr/+bug/504102>
122
self._network_name = None
125
return "%s(_network_name=%r)" % (self.__class__.__name__,
128
def get_format_description(self):
129
if self._network_name:
131
real_format = controldir.network_format_registry.get(
136
return 'Remote: ' + real_format.get_format_description()
137
return 'bzr remote bzrdir'
139
def get_format_string(self):
140
raise NotImplementedError(self.get_format_string)
142
def network_name(self):
143
if self._network_name:
144
return self._network_name
146
raise AssertionError("No network name set.")
148
def initialize_on_transport(self, transport):
150
# hand off the request to the smart server
151
client_medium = transport.get_smart_medium()
152
except errors.NoSmartMedium:
153
# TODO: lookup the local format from a server hint.
154
local_dir_format = _mod_bzrdir.BzrDirMetaFormat1()
155
return local_dir_format.initialize_on_transport(transport)
156
client = _SmartClient(client_medium)
157
path = client.remote_path_from_transport(transport)
159
response = client.call('BzrDirFormat.initialize', path)
160
except errors.ErrorFromSmartServer, err:
161
_translate_error(err, path=path)
162
if response[0] != 'ok':
163
raise errors.SmartProtocolError('unexpected response code %s' % (response,))
164
format = RemoteBzrDirFormat()
165
self._supply_sub_formats_to(format)
166
return RemoteBzrDir(transport, format)
168
def parse_NoneTrueFalse(self, arg):
175
raise AssertionError("invalid arg %r" % arg)
177
def _serialize_NoneTrueFalse(self, arg):
184
def _serialize_NoneString(self, arg):
187
def initialize_on_transport_ex(self, transport, use_existing_dir=False,
188
create_prefix=False, force_new_repo=False, stacked_on=None,
189
stack_on_pwd=None, repo_format_name=None, make_working_trees=None,
192
# hand off the request to the smart server
193
client_medium = transport.get_smart_medium()
194
except errors.NoSmartMedium:
197
# Decline to open it if the server doesn't support our required
198
# version (3) so that the VFS-based transport will do it.
199
if client_medium.should_probe():
201
server_version = client_medium.protocol_version()
202
if server_version != '2':
206
except errors.SmartProtocolError:
207
# Apparently there's no usable smart server there, even though
208
# the medium supports the smart protocol.
213
client = _SmartClient(client_medium)
214
path = client.remote_path_from_transport(transport)
215
if client_medium._is_remote_before((1, 16)):
218
# TODO: lookup the local format from a server hint.
219
local_dir_format = _mod_bzrdir.BzrDirMetaFormat1()
220
self._supply_sub_formats_to(local_dir_format)
221
return local_dir_format.initialize_on_transport_ex(transport,
222
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
223
force_new_repo=force_new_repo, stacked_on=stacked_on,
224
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
225
make_working_trees=make_working_trees, shared_repo=shared_repo,
227
return self._initialize_on_transport_ex_rpc(client, path, transport,
228
use_existing_dir, create_prefix, force_new_repo, stacked_on,
229
stack_on_pwd, repo_format_name, make_working_trees, shared_repo)
231
def _initialize_on_transport_ex_rpc(self, client, path, transport,
232
use_existing_dir, create_prefix, force_new_repo, stacked_on,
233
stack_on_pwd, repo_format_name, make_working_trees, shared_repo):
235
args.append(self._serialize_NoneTrueFalse(use_existing_dir))
236
args.append(self._serialize_NoneTrueFalse(create_prefix))
237
args.append(self._serialize_NoneTrueFalse(force_new_repo))
238
args.append(self._serialize_NoneString(stacked_on))
239
# stack_on_pwd is often/usually our transport
242
stack_on_pwd = transport.relpath(stack_on_pwd)
245
except errors.PathNotChild:
247
args.append(self._serialize_NoneString(stack_on_pwd))
248
args.append(self._serialize_NoneString(repo_format_name))
249
args.append(self._serialize_NoneTrueFalse(make_working_trees))
250
args.append(self._serialize_NoneTrueFalse(shared_repo))
251
request_network_name = self._network_name or \
252
_mod_bzrdir.BzrDirFormat.get_default_format().network_name()
254
response = client.call('BzrDirFormat.initialize_ex_1.16',
255
request_network_name, path, *args)
256
except errors.UnknownSmartMethod:
257
client._medium._remember_remote_is_before((1,16))
258
local_dir_format = _mod_bzrdir.BzrDirMetaFormat1()
259
self._supply_sub_formats_to(local_dir_format)
260
return local_dir_format.initialize_on_transport_ex(transport,
261
use_existing_dir=use_existing_dir, create_prefix=create_prefix,
262
force_new_repo=force_new_repo, stacked_on=stacked_on,
263
stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
264
make_working_trees=make_working_trees, shared_repo=shared_repo,
266
except errors.ErrorFromSmartServer, err:
267
_translate_error(err, path=path)
268
repo_path = response[0]
269
bzrdir_name = response[6]
270
require_stacking = response[7]
271
require_stacking = self.parse_NoneTrueFalse(require_stacking)
272
format = RemoteBzrDirFormat()
273
format._network_name = bzrdir_name
274
self._supply_sub_formats_to(format)
275
bzrdir = RemoteBzrDir(transport, format, _client=client)
277
repo_format = response_tuple_to_repo_format(response[1:])
281
repo_bzrdir_format = RemoteBzrDirFormat()
282
repo_bzrdir_format._network_name = response[5]
283
repo_bzr = RemoteBzrDir(transport.clone(repo_path),
287
final_stack = response[8] or None
288
final_stack_pwd = response[9] or None
290
final_stack_pwd = urlutils.join(
291
transport.base, final_stack_pwd)
292
remote_repo = RemoteRepository(repo_bzr, repo_format)
293
if len(response) > 10:
294
# Updated server verb that locks remotely.
295
repo_lock_token = response[10] or None
296
remote_repo.lock_write(repo_lock_token, _skip_rpc=True)
298
remote_repo.dont_leave_lock_in_place()
300
remote_repo.lock_write()
301
policy = _mod_bzrdir.UseExistingRepository(remote_repo, final_stack,
302
final_stack_pwd, require_stacking)
303
policy.acquire_repository()
307
bzrdir._format.set_branch_format(self.get_branch_format())
309
# The repo has already been created, but we need to make sure that
310
# we'll make a stackable branch.
311
bzrdir._format.require_stacking(_skip_repo=True)
312
return remote_repo, bzrdir, require_stacking, policy
314
def _open(self, transport):
315
return RemoteBzrDir(transport, self)
317
def __eq__(self, other):
318
if not isinstance(other, RemoteBzrDirFormat):
320
return self.get_format_description() == other.get_format_description()
322
def __return_repository_format(self):
323
# Always return a RemoteRepositoryFormat object, but if a specific bzr
324
# repository format has been asked for, tell the RemoteRepositoryFormat
325
# that it should use that for init() etc.
326
result = RemoteRepositoryFormat()
327
custom_format = getattr(self, '_repository_format', None)
329
if isinstance(custom_format, RemoteRepositoryFormat):
332
# We will use the custom format to create repositories over the
333
# wire; expose its details like rich_root_data for code to
335
result._custom_format = custom_format
338
def get_branch_format(self):
339
result = _mod_bzrdir.BzrDirMetaFormat1.get_branch_format(self)
340
if not isinstance(result, RemoteBranchFormat):
341
new_result = RemoteBranchFormat()
342
new_result._custom_format = result
344
self.set_branch_format(new_result)
348
repository_format = property(__return_repository_format,
349
_mod_bzrdir.BzrDirMetaFormat1._set_repository_format) #.im_func)
352
class RemoteControlStore(_mod_config.IniFileStore):
353
"""Control store which attempts to use HPSS calls to retrieve control store.
355
Note that this is specific to bzr-based formats.
358
def __init__(self, bzrdir):
359
super(RemoteControlStore, self).__init__()
361
self._real_store = None
363
def lock_write(self, token=None):
365
return self._real_store.lock_write(token)
369
return self._real_store.unlock()
373
# We need to be able to override the undecorated implementation
374
self.save_without_locking()
376
def save_without_locking(self):
377
super(RemoteControlStore, self).save()
379
def _ensure_real(self):
380
self.bzrdir._ensure_real()
381
if self._real_store is None:
382
self._real_store = _mod_config.ControlStore(self.bzrdir)
384
def external_url(self):
385
return self.bzrdir.user_url
387
def _load_content(self):
388
medium = self.bzrdir._client._medium
389
path = self.bzrdir._path_for_remote_call(self.bzrdir._client)
391
response, handler = self.bzrdir._call_expecting_body(
392
'BzrDir.get_config_file', path)
393
except errors.UnknownSmartMethod:
395
return self._real_store._load_content()
396
if len(response) and response[0] != 'ok':
397
raise errors.UnexpectedSmartServerResponse(response)
398
return handler.read_body_bytes()
400
def _save_content(self, content):
401
# FIXME JRV 2011-11-22: Ideally this should use a
402
# HPSS call too, but at the moment it is not possible
403
# to write lock control directories.
405
return self._real_store._save_content(content)
408
class RemoteBzrDir(_mod_bzrdir.BzrDir, _RpcHelper):
90
409
"""Control directory on a remote server, accessed via bzr:// or similar."""
92
411
def __init__(self, transport, format, _client=None, _force_probe=False):
259
649
self._next_open_branch_result = result
262
def destroy_branch(self):
652
def destroy_branch(self, name=None):
263
653
"""See BzrDir.destroy_branch"""
265
self._real_bzrdir.destroy_branch()
654
path = self._path_for_remote_call(self._client)
660
response = self._call('BzrDir.destroy_branch', path, *args)
661
except errors.UnknownSmartMethod:
663
self._real_bzrdir.destroy_branch(name=name)
664
self._next_open_branch_result = None
266
666
self._next_open_branch_result = None
667
if response[0] != 'ok':
668
raise SmartProtocolError('unexpected response code %s' % (response,))
268
def create_workingtree(self, revision_id=None, from_branch=None):
670
def create_workingtree(self, revision_id=None, from_branch=None,
671
accelerator_tree=None, hardlink=False):
269
672
raise errors.NotLocalUrl(self.transport.base)
271
def find_branch_format(self):
674
def find_branch_format(self, name=None):
272
675
"""Find the branch 'format' for this bzrdir.
274
677
This might be a synthetic object for e.g. RemoteBranch and SVN.
276
b = self.open_branch()
679
b = self.open_branch(name=name)
279
def get_branch_reference(self):
682
def get_branches(self, possible_transports=None, ignore_fallbacks=False):
683
path = self._path_for_remote_call(self._client)
685
response, handler = self._call_expecting_body(
686
'BzrDir.get_branches', path)
687
except errors.UnknownSmartMethod:
689
return self._real_bzrdir.get_branches()
690
if response[0] != "success":
691
raise errors.UnexpectedSmartServerResponse(response)
692
body = bencode.bdecode(handler.read_body_bytes())
694
for (name, value) in body.iteritems():
695
ret[name] = self._open_branch(name, value[0], value[1],
696
possible_transports=possible_transports,
697
ignore_fallbacks=ignore_fallbacks)
700
def set_branch_reference(self, target_branch, name=None):
701
"""See BzrDir.set_branch_reference()."""
703
return self._real_bzrdir.set_branch_reference(target_branch, name=name)
705
def get_branch_reference(self, name=None):
280
706
"""See BzrDir.get_branch_reference()."""
708
# XXX JRV20100304: Support opening colocated branches
709
raise errors.NoColocatedBranchSupport(self)
281
710
response = self._get_branch_reference()
282
711
if response[0] == 'ref':
283
712
return response[1]
314
743
raise errors.UnexpectedSmartServerResponse(response)
317
def _get_tree_branch(self):
746
def _get_tree_branch(self, name=None):
318
747
"""See BzrDir._get_tree_branch()."""
319
return None, self.open_branch()
748
return None, self.open_branch(name=name)
321
def open_branch(self, _unsupported=False, ignore_fallbacks=False):
323
raise NotImplementedError('unsupported flag support not implemented yet.')
324
if self._next_open_branch_result is not None:
325
# See create_branch for details.
326
result = self._next_open_branch_result
327
self._next_open_branch_result = None
329
response = self._get_branch_reference()
330
if response[0] == 'ref':
750
def _open_branch(self, name, kind, location_or_format,
751
ignore_fallbacks=False, possible_transports=None):
331
753
# a branch reference, use the existing BranchReference logic.
332
754
format = BranchReferenceFormat()
333
return format.open(self, _found=True, location=response[1],
334
ignore_fallbacks=ignore_fallbacks)
335
branch_format_name = response[1]
755
return format.open(self, name=name, _found=True,
756
location=location_or_format, ignore_fallbacks=ignore_fallbacks,
757
possible_transports=possible_transports)
758
branch_format_name = location_or_format
336
759
if not branch_format_name:
337
760
branch_format_name = None
338
761
format = RemoteBranchFormat(network_name=branch_format_name)
339
762
return RemoteBranch(self, self.find_repository(), format=format,
340
setup_stacking=not ignore_fallbacks)
763
setup_stacking=not ignore_fallbacks, name=name,
764
possible_transports=possible_transports)
766
def open_branch(self, name=None, unsupported=False,
767
ignore_fallbacks=False, possible_transports=None):
769
raise NotImplementedError('unsupported flag support not implemented yet.')
770
if self._next_open_branch_result is not None:
771
# See create_branch for details.
772
result = self._next_open_branch_result
773
self._next_open_branch_result = None
775
response = self._get_branch_reference()
777
name = self._get_selected_branch()
778
return self._open_branch(name, response[0], response[1],
779
possible_transports=possible_transports,
780
ignore_fallbacks=ignore_fallbacks)
342
782
def _open_repo_v1(self, path):
343
783
verb = 'BzrDir.find_repository'
1169
1753
raise errors.UnexpectedSmartServerResponse(response)
1171
1756
def sprout(self, to_bzrdir, revision_id=None):
1172
# TODO: Option to control what format is created?
1174
dest_repo = self._real_repository._format.initialize(to_bzrdir,
1757
"""Create a descendent repository for new development.
1759
Unlike clone, this does not copy the settings of the repository.
1761
dest_repo = self._create_sprouting_repo(to_bzrdir, shared=False)
1176
1762
dest_repo.fetch(self, revision_id=revision_id)
1177
1763
return dest_repo
1765
def _create_sprouting_repo(self, a_bzrdir, shared):
1766
if not isinstance(a_bzrdir._format, self.bzrdir._format.__class__):
1767
# use target default format.
1768
dest_repo = a_bzrdir.create_repository()
1770
# Most control formats need the repository to be specifically
1771
# created, but on some old all-in-one formats it's not needed
1773
dest_repo = self._format.initialize(a_bzrdir, shared=shared)
1774
except errors.UninitializableFormat:
1775
dest_repo = a_bzrdir.open_repository()
1179
1778
### These methods are just thin shims to the VFS object for now.
1181
1781
def revision_tree(self, revision_id):
1183
return self._real_repository.revision_tree(revision_id)
1782
revision_id = _mod_revision.ensure_null(revision_id)
1783
if revision_id == _mod_revision.NULL_REVISION:
1784
return InventoryRevisionTree(self,
1785
Inventory(root_id=None), _mod_revision.NULL_REVISION)
1787
return list(self.revision_trees([revision_id]))[0]
1185
1789
def get_serializer_format(self):
1187
return self._real_repository.get_serializer_format()
1790
path = self.bzrdir._path_for_remote_call(self._client)
1792
response = self._call('VersionedFileRepository.get_serializer_format',
1794
except errors.UnknownSmartMethod:
1796
return self._real_repository.get_serializer_format()
1797
if response[0] != 'ok':
1798
raise errors.UnexpectedSmartServerResponse(response)
1189
1801
def get_commit_builder(self, branch, parents, config, timestamp=None,
1190
1802
timezone=None, committer=None, revprops=None,
1192
# FIXME: It ought to be possible to call this without immediately
1193
# triggering _ensure_real. For now it's the easiest thing to do.
1195
real_repo = self._real_repository
1196
builder = real_repo.get_commit_builder(branch, parents,
1197
config, timestamp=timestamp, timezone=timezone,
1198
committer=committer, revprops=revprops, revision_id=revision_id)
1803
revision_id=None, lossy=False):
1804
"""Obtain a CommitBuilder for this repository.
1806
:param branch: Branch to commit to.
1807
:param parents: Revision ids of the parents of the new revision.
1808
:param config: Configuration to use.
1809
:param timestamp: Optional timestamp recorded for commit.
1810
:param timezone: Optional timezone for timestamp.
1811
:param committer: Optional committer to set for commit.
1812
:param revprops: Optional dictionary of revision properties.
1813
:param revision_id: Optional revision id.
1814
:param lossy: Whether to discard data that can not be natively
1815
represented, when pushing to a foreign VCS
1817
if self._fallback_repositories and not self._format.supports_chks:
1818
raise errors.BzrError("Cannot commit directly to a stacked branch"
1819
" in pre-2a formats. See "
1820
"https://bugs.launchpad.net/bzr/+bug/375013 for details.")
1821
if self._format.rich_root_data:
1822
commit_builder_kls = vf_repository.VersionedFileRootCommitBuilder
1824
commit_builder_kls = vf_repository.VersionedFileCommitBuilder
1825
result = commit_builder_kls(self, parents, config,
1826
timestamp, timezone, committer, revprops, revision_id,
1828
self.start_write_group()
1201
1831
def add_fallback_repository(self, repository):
1202
1832
"""Add a repository to use for looking up data not held locally.
1219
1851
# _real_branch had its get_stacked_on_url method called), then the
1220
1852
# repository to be added may already be in the _real_repositories list.
1221
1853
if self._real_repository is not None:
1222
fallback_locations = [repo.bzrdir.root_transport.base for repo in
1854
fallback_locations = [repo.user_url for repo in
1223
1855
self._real_repository._fallback_repositories]
1224
if repository.bzrdir.root_transport.base not in fallback_locations:
1856
if repository.user_url not in fallback_locations:
1225
1857
self._real_repository.add_fallback_repository(repository)
1859
def _check_fallback_repository(self, repository):
1860
"""Check that this repository can fallback to repository safely.
1862
Raise an error if not.
1864
:param repository: A repository to fallback to.
1866
return _mod_repository.InterRepository._assert_same_model(
1227
1869
def add_inventory(self, revid, inv, parents):
1228
1870
self._ensure_real()
1229
1871
return self._real_repository.add_inventory(revid, inv, parents)
1231
1873
def add_inventory_by_delta(self, basis_revision_id, delta, new_revision_id,
1874
parents, basis_inv=None, propagate_caches=False):
1233
1875
self._ensure_real()
1234
1876
return self._real_repository.add_inventory_by_delta(basis_revision_id,
1235
delta, new_revision_id, parents)
1237
def add_revision(self, rev_id, rev, inv=None, config=None):
1239
return self._real_repository.add_revision(
1240
rev_id, rev, inv=inv, config=config)
1877
delta, new_revision_id, parents, basis_inv=basis_inv,
1878
propagate_caches=propagate_caches)
1880
def add_revision(self, revision_id, rev, inv=None):
1881
_mod_revision.check_not_reserved_id(revision_id)
1882
key = (revision_id,)
1883
# check inventory present
1884
if not self.inventories.get_parent_map([key]):
1886
raise errors.WeaveRevisionNotPresent(revision_id,
1889
# yes, this is not suitable for adding with ghosts.
1890
rev.inventory_sha1 = self.add_inventory(revision_id, inv,
1893
rev.inventory_sha1 = self.inventories.get_sha1s([key])[key]
1894
self._add_revision(rev)
1896
def _add_revision(self, rev):
1897
if self._real_repository is not None:
1898
return self._real_repository._add_revision(rev)
1899
text = self._serializer.write_revision_to_string(rev)
1900
key = (rev.revision_id,)
1901
parents = tuple((parent,) for parent in rev.parent_ids)
1902
self._write_group_tokens, missing_keys = self._get_sink().insert_stream(
1903
[('revisions', [FulltextContentFactory(key, parents, None, text)])],
1904
self._format, self._write_group_tokens)
1242
1906
@needs_read_lock
1243
1907
def get_inventory(self, revision_id):
1908
return list(self.iter_inventories([revision_id]))[0]
1910
def _iter_inventories_rpc(self, revision_ids, ordering):
1911
if ordering is None:
1912
ordering = 'unordered'
1913
path = self.bzrdir._path_for_remote_call(self._client)
1914
body = "\n".join(revision_ids)
1915
response_tuple, response_handler = (
1916
self._call_with_body_bytes_expecting_body(
1917
"VersionedFileRepository.get_inventories",
1918
(path, ordering), body))
1919
if response_tuple[0] != "ok":
1920
raise errors.UnexpectedSmartServerResponse(response_tuple)
1921
deserializer = inventory_delta.InventoryDeltaDeserializer()
1922
byte_stream = response_handler.read_streamed_body()
1923
decoded = smart_repo._byte_stream_to_stream(byte_stream)
1925
# no results whatsoever
1927
src_format, stream = decoded
1928
if src_format.network_name() != self._format.network_name():
1929
raise AssertionError(
1930
"Mismatched RemoteRepository and stream src %r, %r" % (
1931
src_format.network_name(), self._format.network_name()))
1932
# ignore the src format, it's not really relevant
1933
prev_inv = Inventory(root_id=None,
1934
revision_id=_mod_revision.NULL_REVISION)
1935
# there should be just one substream, with inventory deltas
1936
substream_kind, substream = stream.next()
1937
if substream_kind != "inventory-deltas":
1938
raise AssertionError(
1939
"Unexpected stream %r received" % substream_kind)
1940
for record in substream:
1941
(parent_id, new_id, versioned_root, tree_references, invdelta) = (
1942
deserializer.parse_text_bytes(record.get_bytes_as("fulltext")))
1943
if parent_id != prev_inv.revision_id:
1944
raise AssertionError("invalid base %r != %r" % (parent_id,
1945
prev_inv.revision_id))
1946
inv = prev_inv.create_by_apply_delta(invdelta, new_id)
1947
yield inv, inv.revision_id
1950
def _iter_inventories_vfs(self, revision_ids, ordering=None):
1244
1951
self._ensure_real()
1245
return self._real_repository.get_inventory(revision_id)
1952
return self._real_repository._iter_inventories(revision_ids, ordering)
1247
1954
def iter_inventories(self, revision_ids, ordering=None):
1249
return self._real_repository.iter_inventories(revision_ids, ordering)
1955
"""Get many inventories by revision_ids.
1957
This will buffer some or all of the texts used in constructing the
1958
inventories in memory, but will only parse a single inventory at a
1961
:param revision_ids: The expected revision ids of the inventories.
1962
:param ordering: optional ordering, e.g. 'topological'. If not
1963
specified, the order of revision_ids will be preserved (by
1964
buffering if necessary).
1965
:return: An iterator of inventories.
1967
if ((None in revision_ids)
1968
or (_mod_revision.NULL_REVISION in revision_ids)):
1969
raise ValueError('cannot get null revision inventory')
1970
for inv, revid in self._iter_inventories(revision_ids, ordering):
1972
raise errors.NoSuchRevision(self, revid)
1975
def _iter_inventories(self, revision_ids, ordering=None):
1976
if len(revision_ids) == 0:
1978
missing = set(revision_ids)
1979
if ordering is None:
1980
order_as_requested = True
1982
order = list(revision_ids)
1984
next_revid = order.pop()
1986
order_as_requested = False
1987
if ordering != 'unordered' and self._fallback_repositories:
1988
raise ValueError('unsupported ordering %r' % ordering)
1989
iter_inv_fns = [self._iter_inventories_rpc] + [
1990
fallback._iter_inventories for fallback in
1991
self._fallback_repositories]
1993
for iter_inv in iter_inv_fns:
1994
request = [revid for revid in revision_ids if revid in missing]
1995
for inv, revid in iter_inv(request, ordering):
1998
missing.remove(inv.revision_id)
1999
if ordering != 'unordered':
2003
if order_as_requested:
2004
# Yield as many results as we can while preserving order.
2005
while next_revid in invs:
2006
inv = invs.pop(next_revid)
2007
yield inv, inv.revision_id
2009
next_revid = order.pop()
2011
# We still want to fully consume the stream, just
2012
# in case it is not actually finished at this point
2015
except errors.UnknownSmartMethod:
2016
for inv, revid in self._iter_inventories_vfs(revision_ids, ordering):
2020
if order_as_requested:
2021
if next_revid is not None:
2022
yield None, next_revid
2025
yield invs.get(revid), revid
2028
yield None, missing.pop()
1251
2030
@needs_read_lock
1252
2031
def get_revision(self, revision_id):
1254
return self._real_repository.get_revision(revision_id)
2032
return self.get_revisions([revision_id])[0]
1256
2034
def get_transaction(self):
1257
2035
self._ensure_real()
1290
2080
included_keys = result_set.intersection(result_parents)
1291
2081
start_keys = result_set.difference(included_keys)
1292
2082
exclude_keys = result_parents.difference(result_set)
1293
result = graph.SearchResult(start_keys, exclude_keys,
2083
result = vf_search.SearchResult(start_keys, exclude_keys,
1294
2084
len(result_set), result_set)
1297
2087
@needs_read_lock
1298
def search_missing_revision_ids(self, other, revision_id=None, find_ghosts=True):
2088
def search_missing_revision_ids(self, other,
2089
revision_id=symbol_versioning.DEPRECATED_PARAMETER,
2090
find_ghosts=True, revision_ids=None, if_present_ids=None,
1299
2092
"""Return the revision ids that other has that this does not.
1301
2094
These are returned in topological order.
1303
2096
revision_id: only return revision ids included by revision_id.
1305
return repository.InterRepository.get(
1306
other, self).search_missing_revision_ids(revision_id, find_ghosts)
2098
if symbol_versioning.deprecated_passed(revision_id):
2099
symbol_versioning.warn(
2100
'search_missing_revision_ids(revision_id=...) was '
2101
'deprecated in 2.4. Use revision_ids=[...] instead.',
2102
DeprecationWarning, stacklevel=2)
2103
if revision_ids is not None:
2104
raise AssertionError(
2105
'revision_ids is mutually exclusive with revision_id')
2106
if revision_id is not None:
2107
revision_ids = [revision_id]
2108
inter_repo = _mod_repository.InterRepository.get(other, self)
2109
return inter_repo.search_missing_revision_ids(
2110
find_ghosts=find_ghosts, revision_ids=revision_ids,
2111
if_present_ids=if_present_ids, limit=limit)
1308
def fetch(self, source, revision_id=None, pb=None, find_ghosts=False,
2113
def fetch(self, source, revision_id=None, find_ghosts=False,
1309
2114
fetch_spec=None):
1310
2115
# No base implementation to use as RemoteRepository is not a subclass
1311
2116
# of Repository; so this is a copy of Repository.fetch().
1350
2161
return self._real_repository._get_versioned_file_checker(
1351
2162
revisions, revision_versions_cache)
2164
def _iter_files_bytes_rpc(self, desired_files, absent):
2165
path = self.bzrdir._path_for_remote_call(self._client)
2168
for (file_id, revid, identifier) in desired_files:
2169
lines.append("%s\0%s" % (
2170
osutils.safe_file_id(file_id),
2171
osutils.safe_revision_id(revid)))
2172
identifiers.append(identifier)
2173
(response_tuple, response_handler) = (
2174
self._call_with_body_bytes_expecting_body(
2175
"Repository.iter_files_bytes", (path, ), "\n".join(lines)))
2176
if response_tuple != ('ok', ):
2177
response_handler.cancel_read_body()
2178
raise errors.UnexpectedSmartServerResponse(response_tuple)
2179
byte_stream = response_handler.read_streamed_body()
2180
def decompress_stream(start, byte_stream, unused):
2181
decompressor = zlib.decompressobj()
2182
yield decompressor.decompress(start)
2183
while decompressor.unused_data == "":
2185
data = byte_stream.next()
2186
except StopIteration:
2188
yield decompressor.decompress(data)
2189
yield decompressor.flush()
2190
unused.append(decompressor.unused_data)
2193
while not "\n" in unused:
2194
unused += byte_stream.next()
2195
header, rest = unused.split("\n", 1)
2196
args = header.split("\0")
2197
if args[0] == "absent":
2198
absent[identifiers[int(args[3])]] = (args[1], args[2])
2201
elif args[0] == "ok":
2204
raise errors.UnexpectedSmartServerResponse(args)
2206
yield (identifiers[idx],
2207
decompress_stream(rest, byte_stream, unused_chunks))
2208
unused = "".join(unused_chunks)
1353
2210
def iter_files_bytes(self, desired_files):
1354
2211
"""See Repository.iter_file_bytes.
1357
return self._real_repository.iter_files_bytes(desired_files)
2215
for (identifier, bytes_iterator) in self._iter_files_bytes_rpc(
2216
desired_files, absent):
2217
yield identifier, bytes_iterator
2218
for fallback in self._fallback_repositories:
2221
desired_files = [(key[0], key[1], identifier) for
2222
(identifier, key) in absent.iteritems()]
2223
for (identifier, bytes_iterator) in fallback.iter_files_bytes(desired_files):
2224
del absent[identifier]
2225
yield identifier, bytes_iterator
2227
# There may be more missing items, but raise an exception
2229
missing_identifier = absent.keys()[0]
2230
missing_key = absent[missing_identifier]
2231
raise errors.RevisionNotPresent(revision_id=missing_key[1],
2232
file_id=missing_key[0])
2233
except errors.UnknownSmartMethod:
2235
for (identifier, bytes_iterator) in (
2236
self._real_repository.iter_files_bytes(desired_files)):
2237
yield identifier, bytes_iterator
2239
def get_cached_parent_map(self, revision_ids):
2240
"""See bzrlib.CachingParentsProvider.get_cached_parent_map"""
2241
return self._unstacked_provider.get_cached_parent_map(revision_ids)
1359
2243
def get_parent_map(self, revision_ids):
1360
2244
"""See bzrlib.Graph.get_parent_map()."""
1494
2367
@needs_read_lock
1495
2368
def get_signature_text(self, revision_id):
1497
return self._real_repository.get_signature_text(revision_id)
2369
path = self.bzrdir._path_for_remote_call(self._client)
2371
response_tuple, response_handler = self._call_expecting_body(
2372
'Repository.get_revision_signature_text', path, revision_id)
2373
except errors.UnknownSmartMethod:
2375
return self._real_repository.get_signature_text(revision_id)
2376
except errors.NoSuchRevision, err:
2377
for fallback in self._fallback_repositories:
2379
return fallback.get_signature_text(revision_id)
2380
except errors.NoSuchRevision:
2384
if response_tuple[0] != 'ok':
2385
raise errors.UnexpectedSmartServerResponse(response_tuple)
2386
return response_handler.read_body_bytes()
1499
2388
@needs_read_lock
1500
2389
def _get_inventory_xml(self, revision_id):
2390
# This call is used by older working tree formats,
2391
# which stored a serialized basis inventory.
1501
2392
self._ensure_real()
1502
2393
return self._real_repository._get_inventory_xml(revision_id)
1504
def _deserialise_inventory(self, revision_id, xml):
1506
return self._real_repository._deserialise_inventory(revision_id, xml)
1508
2396
def reconcile(self, other=None, thorough=False):
1510
return self._real_repository.reconcile(other=other, thorough=thorough)
2397
from bzrlib.reconcile import RepoReconciler
2398
path = self.bzrdir._path_for_remote_call(self._client)
2400
response, handler = self._call_expecting_body(
2401
'Repository.reconcile', path, self._lock_token)
2402
except (errors.UnknownSmartMethod, errors.TokenLockingNotSupported):
2404
return self._real_repository.reconcile(other=other, thorough=thorough)
2405
if response != ('ok', ):
2406
raise errors.UnexpectedSmartServerResponse(response)
2407
body = handler.read_body_bytes()
2408
result = RepoReconciler(self)
2409
for line in body.split('\n'):
2412
key, val_text = line.split(':')
2413
if key == "garbage_inventories":
2414
result.garbage_inventories = int(val_text)
2415
elif key == "inconsistent_parents":
2416
result.inconsistent_parents = int(val_text)
2418
mutter("unknown reconcile key %r" % key)
1512
2421
def all_revision_ids(self):
1514
return self._real_repository.all_revision_ids()
2422
path = self.bzrdir._path_for_remote_call(self._client)
2424
response_tuple, response_handler = self._call_expecting_body(
2425
"Repository.all_revision_ids", path)
2426
except errors.UnknownSmartMethod:
2428
return self._real_repository.all_revision_ids()
2429
if response_tuple != ("ok", ):
2430
raise errors.UnexpectedSmartServerResponse(response_tuple)
2431
revids = set(response_handler.read_body_bytes().splitlines())
2432
for fallback in self._fallback_repositories:
2433
revids.update(set(fallback.all_revision_ids()))
2436
def _filtered_revision_trees(self, revision_ids, file_ids):
2437
"""Return Tree for a revision on this branch with only some files.
2439
:param revision_ids: a sequence of revision-ids;
2440
a revision-id may not be None or 'null:'
2441
:param file_ids: if not None, the result is filtered
2442
so that only those file-ids, their parents and their
2443
children are included.
2445
inventories = self.iter_inventories(revision_ids)
2446
for inv in inventories:
2447
# Should we introduce a FilteredRevisionTree class rather
2448
# than pre-filter the inventory here?
2449
filtered_inv = inv.filter(file_ids)
2450
yield InventoryRevisionTree(self, filtered_inv, filtered_inv.revision_id)
1516
2452
@needs_read_lock
1517
2453
def get_deltas_for_revisions(self, revisions, specific_fileids=None):
1519
return self._real_repository.get_deltas_for_revisions(revisions,
1520
specific_fileids=specific_fileids)
2454
medium = self._client._medium
2455
if medium._is_remote_before((1, 2)):
2457
for delta in self._real_repository.get_deltas_for_revisions(
2458
revisions, specific_fileids):
2461
# Get the revision-ids of interest
2462
required_trees = set()
2463
for revision in revisions:
2464
required_trees.add(revision.revision_id)
2465
required_trees.update(revision.parent_ids[:1])
2467
# Get the matching filtered trees. Note that it's more
2468
# efficient to pass filtered trees to changes_from() rather
2469
# than doing the filtering afterwards. changes_from() could
2470
# arguably do the filtering itself but it's path-based, not
2471
# file-id based, so filtering before or afterwards is
2473
if specific_fileids is None:
2474
trees = dict((t.get_revision_id(), t) for
2475
t in self.revision_trees(required_trees))
2477
trees = dict((t.get_revision_id(), t) for
2478
t in self._filtered_revision_trees(required_trees,
2481
# Calculate the deltas
2482
for revision in revisions:
2483
if not revision.parent_ids:
2484
old_tree = self.revision_tree(_mod_revision.NULL_REVISION)
2486
old_tree = trees[revision.parent_ids[0]]
2487
yield trees[revision.revision_id].changes_from(old_tree)
1522
2489
@needs_read_lock
1523
2490
def get_revision_delta(self, revision_id, specific_fileids=None):
1525
return self._real_repository.get_revision_delta(revision_id,
1526
specific_fileids=specific_fileids)
2491
r = self.get_revision(revision_id)
2492
return list(self.get_deltas_for_revisions([r],
2493
specific_fileids=specific_fileids))[0]
1528
2495
@needs_read_lock
1529
2496
def revision_trees(self, revision_ids):
1531
return self._real_repository.revision_trees(revision_ids)
2497
inventories = self.iter_inventories(revision_ids)
2498
for inv in inventories:
2499
yield InventoryRevisionTree(self, inv, inv.revision_id)
1533
2501
@needs_read_lock
1534
2502
def get_revision_reconcile(self, revision_id):
1646
2627
self._ensure_real()
1647
2628
return self._real_repository.texts
2630
def _iter_revisions_rpc(self, revision_ids):
2631
body = "\n".join(revision_ids)
2632
path = self.bzrdir._path_for_remote_call(self._client)
2633
response_tuple, response_handler = (
2634
self._call_with_body_bytes_expecting_body(
2635
"Repository.iter_revisions", (path, ), body))
2636
if response_tuple[0] != "ok":
2637
raise errors.UnexpectedSmartServerResponse(response_tuple)
2638
serializer_format = response_tuple[1]
2639
serializer = serializer_format_registry.get(serializer_format)
2640
byte_stream = response_handler.read_streamed_body()
2641
decompressor = zlib.decompressobj()
2643
for bytes in byte_stream:
2644
chunks.append(decompressor.decompress(bytes))
2645
if decompressor.unused_data != "":
2646
chunks.append(decompressor.flush())
2647
yield serializer.read_revision_from_string("".join(chunks))
2648
unused = decompressor.unused_data
2649
decompressor = zlib.decompressobj()
2650
chunks = [decompressor.decompress(unused)]
2651
chunks.append(decompressor.flush())
2652
text = "".join(chunks)
2654
yield serializer.read_revision_from_string("".join(chunks))
1649
2656
@needs_read_lock
1650
2657
def get_revisions(self, revision_ids):
1652
return self._real_repository.get_revisions(revision_ids)
2658
if revision_ids is None:
2659
revision_ids = self.all_revision_ids()
2661
for rev_id in revision_ids:
2662
if not rev_id or not isinstance(rev_id, basestring):
2663
raise errors.InvalidRevisionId(
2664
revision_id=rev_id, branch=self)
2666
missing = set(revision_ids)
2668
for rev in self._iter_revisions_rpc(revision_ids):
2669
missing.remove(rev.revision_id)
2670
revs[rev.revision_id] = rev
2671
except errors.UnknownSmartMethod:
2673
return self._real_repository.get_revisions(revision_ids)
2674
for fallback in self._fallback_repositories:
2677
for revid in list(missing):
2678
# XXX JRV 2011-11-20: It would be nice if there was a
2679
# public method on Repository that could be used to query
2680
# for revision objects *without* failing completely if one
2681
# was missing. There is VersionedFileRepository._iter_revisions,
2682
# but unfortunately that's private and not provided by
2683
# all repository implementations.
2685
revs[revid] = fallback.get_revision(revid)
2686
except errors.NoSuchRevision:
2689
missing.remove(revid)
2691
raise errors.NoSuchRevision(self, list(missing)[0])
2692
return [revs[revid] for revid in revision_ids]
1654
2694
def supports_rich_root(self):
1655
2695
return self._format.rich_root_data
2697
@symbol_versioning.deprecated_method(symbol_versioning.deprecated_in((2, 4, 0)))
1657
2698
def iter_reverse_revision_history(self, revision_id):
1658
2699
self._ensure_real()
1659
2700
return self._real_repository.iter_reverse_revision_history(revision_id)
1662
2703
def _serializer(self):
1663
2704
return self._format._serializer
1665
2707
def store_revision_signature(self, gpg_strategy, plaintext, revision_id):
1667
return self._real_repository.store_revision_signature(
1668
gpg_strategy, plaintext, revision_id)
2708
signature = gpg_strategy.sign(plaintext)
2709
self.add_signature_text(revision_id, signature)
1670
2711
def add_signature_text(self, revision_id, signature):
1672
return self._real_repository.add_signature_text(revision_id, signature)
2712
if self._real_repository:
2713
# If there is a real repository the write group will
2714
# be in the real repository as well, so use that:
2716
return self._real_repository.add_signature_text(
2717
revision_id, signature)
2718
path = self.bzrdir._path_for_remote_call(self._client)
2719
response, handler = self._call_with_body_bytes_expecting_body(
2720
'Repository.add_signature_text', (path, self._lock_token,
2721
revision_id) + tuple(self._write_group_tokens), signature)
2722
handler.cancel_read_body()
2724
if response[0] != 'ok':
2725
raise errors.UnexpectedSmartServerResponse(response)
2726
self._write_group_tokens = response[1:]
1674
2728
def has_signature_for_revision_id(self, revision_id):
1676
return self._real_repository.has_signature_for_revision_id(revision_id)
2729
path = self.bzrdir._path_for_remote_call(self._client)
2731
response = self._call('Repository.has_signature_for_revision_id',
2733
except errors.UnknownSmartMethod:
2735
return self._real_repository.has_signature_for_revision_id(
2737
if response[0] not in ('yes', 'no'):
2738
raise SmartProtocolError('unexpected response code %s' % (response,))
2739
if response[0] == 'yes':
2741
for fallback in self._fallback_repositories:
2742
if fallback.has_signature_for_revision_id(revision_id):
2747
def verify_revision_signature(self, revision_id, gpg_strategy):
2748
if not self.has_signature_for_revision_id(revision_id):
2749
return gpg.SIGNATURE_NOT_SIGNED, None
2750
signature = self.get_signature_text(revision_id)
2752
testament = _mod_testament.Testament.from_revision(self, revision_id)
2753
plaintext = testament.as_short_text()
2755
return gpg_strategy.verify(signature, plaintext)
1678
2757
def item_keys_introduced_by(self, revision_ids, _files_pb=None):
1679
2758
self._ensure_real()
1680
2759
return self._real_repository.item_keys_introduced_by(revision_ids,
1681
2760
_files_pb=_files_pb)
1683
def revision_graph_can_have_wrong_parents(self):
1684
# The answer depends on the remote repo format.
1686
return self._real_repository.revision_graph_can_have_wrong_parents()
1688
2762
def _find_inconsistent_revision_parents(self, revisions_iterator=None):
1689
2763
self._ensure_real()
1690
2764
return self._real_repository._find_inconsistent_revision_parents(
2025
3110
def network_name(self):
2026
3111
return self._network_name
2028
def open(self, a_bzrdir, ignore_fallbacks=False):
2029
return a_bzrdir.open_branch(ignore_fallbacks=ignore_fallbacks)
3113
def open(self, a_bzrdir, name=None, ignore_fallbacks=False):
3114
return a_bzrdir.open_branch(name=name,
3115
ignore_fallbacks=ignore_fallbacks)
2031
def _vfs_initialize(self, a_bzrdir):
3117
def _vfs_initialize(self, a_bzrdir, name, append_revisions_only):
2032
3118
# Initialisation when using a local bzrdir object, or a non-vfs init
2033
3119
# method is not available on the server.
2034
3120
# self._custom_format is always set - the start of initialize ensures
2036
3122
if isinstance(a_bzrdir, RemoteBzrDir):
2037
3123
a_bzrdir._ensure_real()
2038
result = self._custom_format.initialize(a_bzrdir._real_bzrdir)
3124
result = self._custom_format.initialize(a_bzrdir._real_bzrdir,
3125
name, append_revisions_only=append_revisions_only)
2040
3127
# We assume the bzrdir is parameterised; it may not be.
2041
result = self._custom_format.initialize(a_bzrdir)
3128
result = self._custom_format.initialize(a_bzrdir, name,
3129
append_revisions_only=append_revisions_only)
2042
3130
if (isinstance(a_bzrdir, RemoteBzrDir) and
2043
3131
not isinstance(result, RemoteBranch)):
2044
result = RemoteBranch(a_bzrdir, a_bzrdir.find_repository(), result)
3132
result = RemoteBranch(a_bzrdir, a_bzrdir.find_repository(), result,
2047
def initialize(self, a_bzrdir):
3136
def initialize(self, a_bzrdir, name=None, repository=None,
3137
append_revisions_only=None):
3139
name = a_bzrdir._get_selected_branch()
2048
3140
# 1) get the network name to use.
2049
3141
if self._custom_format:
2050
3142
network_name = self._custom_format.network_name()
2052
3144
# Select the current bzrlib default and ask for that.
2053
reference_bzrdir_format = bzrdir.format_registry.get('default')()
3145
reference_bzrdir_format = _mod_bzrdir.format_registry.get('default')()
2054
3146
reference_format = reference_bzrdir_format.get_branch_format()
2055
3147
self._custom_format = reference_format
2056
3148
network_name = reference_format.network_name()
2057
3149
# Being asked to create on a non RemoteBzrDir:
2058
3150
if not isinstance(a_bzrdir, RemoteBzrDir):
2059
return self._vfs_initialize(a_bzrdir)
3151
return self._vfs_initialize(a_bzrdir, name=name,
3152
append_revisions_only=append_revisions_only)
2060
3153
medium = a_bzrdir._client._medium
2061
3154
if medium._is_remote_before((1, 13)):
2062
return self._vfs_initialize(a_bzrdir)
3155
return self._vfs_initialize(a_bzrdir, name=name,
3156
append_revisions_only=append_revisions_only)
2063
3157
# Creating on a remote bzr dir.
2064
3158
# 2) try direct creation via RPC
2065
3159
path = a_bzrdir._path_for_remote_call(a_bzrdir._client)
3161
# XXX JRV20100304: Support creating colocated branches
3162
raise errors.NoColocatedBranchSupport(self)
2066
3163
verb = 'BzrDir.create_branch'
2068
3165
response = a_bzrdir._call(verb, path, network_name)
2069
3166
except errors.UnknownSmartMethod:
2070
3167
# Fallback - use vfs methods
2071
3168
medium._remember_remote_is_before((1, 13))
2072
return self._vfs_initialize(a_bzrdir)
3169
return self._vfs_initialize(a_bzrdir, name=name,
3170
append_revisions_only=append_revisions_only)
2073
3171
if response[0] != 'ok':
2074
3172
raise errors.UnexpectedSmartServerResponse(response)
2075
3173
# Turn the response into a RemoteRepository object.
2076
3174
format = RemoteBranchFormat(network_name=response[1])
2077
3175
repo_format = response_tuple_to_repo_format(response[3:])
2078
if response[2] == '':
2079
repo_bzrdir = a_bzrdir
3176
repo_path = response[2]
3177
if repository is not None:
3178
remote_repo_url = urlutils.join(a_bzrdir.user_url, repo_path)
3179
url_diff = urlutils.relative_url(repository.user_url,
3182
raise AssertionError(
3183
'repository.user_url %r does not match URL from server '
3184
'response (%r + %r)'
3185
% (repository.user_url, a_bzrdir.user_url, repo_path))
3186
remote_repo = repository
2081
repo_bzrdir = RemoteBzrDir(
2082
a_bzrdir.root_transport.clone(response[2]), a_bzrdir._format,
2084
remote_repo = RemoteRepository(repo_bzrdir, repo_format)
3189
repo_bzrdir = a_bzrdir
3191
repo_bzrdir = RemoteBzrDir(
3192
a_bzrdir.root_transport.clone(repo_path), a_bzrdir._format,
3194
remote_repo = RemoteRepository(repo_bzrdir, repo_format)
2085
3195
remote_branch = RemoteBranch(a_bzrdir, remote_repo,
2086
format=format, setup_stacking=False)
3196
format=format, setup_stacking=False, name=name)
3197
if append_revisions_only:
3198
remote_branch.set_append_revisions_only(append_revisions_only)
2087
3199
# XXX: We know this is a new branch, so it must have revno 0, revid
2088
3200
# NULL_REVISION. Creating the branch locked would make this be unable
2089
3201
# to be wrong; here its simply very unlikely to be wrong. RBC 20090225
2108
3220
self._ensure_real()
2109
3221
return self._custom_format.supports_set_append_revisions_only()
3223
def _use_default_local_heads_to_fetch(self):
3224
# If the branch format is a metadir format *and* its heads_to_fetch
3225
# implementation is not overridden vs the base class, we can use the
3226
# base class logic rather than use the heads_to_fetch RPC. This is
3227
# usually cheaper in terms of net round trips, as the last-revision and
3228
# tags info fetched is cached and would be fetched anyway.
3230
if isinstance(self._custom_format, branch.BranchFormatMetadir):
3231
branch_class = self._custom_format._branch_class()
3232
heads_to_fetch_impl = branch_class.heads_to_fetch.im_func
3233
if heads_to_fetch_impl is branch.Branch.heads_to_fetch.im_func:
3238
class RemoteBranchStore(_mod_config.IniFileStore):
3239
"""Branch store which attempts to use HPSS calls to retrieve branch store.
3241
Note that this is specific to bzr-based formats.
3244
def __init__(self, branch):
3245
super(RemoteBranchStore, self).__init__()
3246
self.branch = branch
3248
self._real_store = None
3250
def lock_write(self, token=None):
3251
return self.branch.lock_write(token)
3254
return self.branch.unlock()
3258
# We need to be able to override the undecorated implementation
3259
self.save_without_locking()
3261
def save_without_locking(self):
3262
super(RemoteBranchStore, self).save()
3264
def external_url(self):
3265
return self.branch.user_url
3267
def _load_content(self):
3268
path = self.branch._remote_path()
3270
response, handler = self.branch._call_expecting_body(
3271
'Branch.get_config_file', path)
3272
except errors.UnknownSmartMethod:
3274
return self._real_store._load_content()
3275
if len(response) and response[0] != 'ok':
3276
raise errors.UnexpectedSmartServerResponse(response)
3277
return handler.read_body_bytes()
3279
def _save_content(self, content):
3280
path = self.branch._remote_path()
3282
response, handler = self.branch._call_with_body_bytes_expecting_body(
3283
'Branch.put_config_file', (path,
3284
self.branch._lock_token, self.branch._repo_lock_token),
3286
except errors.UnknownSmartMethod:
3288
return self._real_store._save_content(content)
3289
handler.cancel_read_body()
3290
if response != ('ok', ):
3291
raise errors.UnexpectedSmartServerResponse(response)
3293
def _ensure_real(self):
3294
self.branch._ensure_real()
3295
if self._real_store is None:
3296
self._real_store = _mod_config.BranchStore(self.branch)
2112
3299
class RemoteBranch(branch.Branch, _RpcHelper, lock._RelockDebugMixin):
2113
3300
"""Branch stored on a server accessed by HPSS RPC.
2611
3845
_override_hook_target=self, **kwargs)
2613
3847
@needs_read_lock
2614
def push(self, target, overwrite=False, stop_revision=None):
3848
def push(self, target, overwrite=False, stop_revision=None, lossy=False):
2615
3849
self._ensure_real()
2616
3850
return self._real_branch.push(
2617
target, overwrite=overwrite, stop_revision=stop_revision,
3851
target, overwrite=overwrite, stop_revision=stop_revision, lossy=lossy,
2618
3852
_override_hook_source_branch=self)
2620
3854
def is_locked(self):
2621
3855
return self._lock_count >= 1
2623
3857
@needs_read_lock
3858
def revision_id_to_dotted_revno(self, revision_id):
3859
"""Given a revision id, return its dotted revno.
3861
:return: a tuple like (1,) or (400,1,3).
3864
response = self._call('Branch.revision_id_to_revno',
3865
self._remote_path(), revision_id)
3866
except errors.UnknownSmartMethod:
3868
return self._real_branch.revision_id_to_dotted_revno(revision_id)
3869
if response[0] == 'ok':
3870
return tuple([int(x) for x in response[1:]])
3872
raise errors.UnexpectedSmartServerResponse(response)
2624
3875
def revision_id_to_revno(self, revision_id):
2626
return self._real_branch.revision_id_to_revno(revision_id)
3876
"""Given a revision id on the branch mainline, return its revno.
3881
response = self._call('Branch.revision_id_to_revno',
3882
self._remote_path(), revision_id)
3883
except errors.UnknownSmartMethod:
3885
return self._real_branch.revision_id_to_revno(revision_id)
3886
if response[0] == 'ok':
3887
if len(response) == 2:
3888
return int(response[1])
3889
raise NoSuchRevision(self, revision_id)
3891
raise errors.UnexpectedSmartServerResponse(response)
2628
3893
@needs_write_lock
2629
3894
def set_last_revision_info(self, revno, revision_id):
2630
3895
# XXX: These should be returned by the set_last_revision_info verb
2631
3896
old_revno, old_revid = self.last_revision_info()
2632
3897
self._run_pre_change_branch_tip_hooks(revno, revision_id)
2633
revision_id = ensure_null(revision_id)
3898
if not revision_id or not isinstance(revision_id, basestring):
3899
raise errors.InvalidRevisionId(revision_id=revision_id, branch=self)
2635
3901
response = self._call('Branch.set_last_revision_info',
2636
3902
self._remote_path(), self._lock_token, self._repo_lock_token,
2731
4034
medium = self._branch._client._medium
2732
4035
if medium._is_remote_before((1, 14)):
2733
4036
return self._vfs_set_option(value, name, section)
4037
if isinstance(value, dict):
4038
if medium._is_remote_before((2, 2)):
4039
return self._vfs_set_option(value, name, section)
4040
return self._set_config_option_dict(value, name, section)
4042
return self._set_config_option(value, name, section)
4044
def _set_config_option(self, value, name, section):
2735
4046
path = self._branch._remote_path()
2736
4047
response = self._branch._client.call('Branch.set_config_option',
2737
4048
path, self._branch._lock_token, self._branch._repo_lock_token,
2738
4049
value.encode('utf8'), name, section or '')
2739
4050
except errors.UnknownSmartMethod:
4051
medium = self._branch._client._medium
2740
4052
medium._remember_remote_is_before((1, 14))
2741
4053
return self._vfs_set_option(value, name, section)
2742
4054
if response != ():
2743
4055
raise errors.UnexpectedSmartServerResponse(response)
4057
def _serialize_option_dict(self, option_dict):
4059
for key, value in option_dict.items():
4060
if isinstance(key, unicode):
4061
key = key.encode('utf8')
4062
if isinstance(value, unicode):
4063
value = value.encode('utf8')
4064
utf8_dict[key] = value
4065
return bencode.bencode(utf8_dict)
4067
def _set_config_option_dict(self, value, name, section):
4069
path = self._branch._remote_path()
4070
serialised_dict = self._serialize_option_dict(value)
4071
response = self._branch._client.call(
4072
'Branch.set_config_option_dict',
4073
path, self._branch._lock_token, self._branch._repo_lock_token,
4074
serialised_dict, name, section or '')
4075
except errors.UnknownSmartMethod:
4076
medium = self._branch._client._medium
4077
medium._remember_remote_is_before((2, 2))
4078
return self._vfs_set_option(value, name, section)
4080
raise errors.UnexpectedSmartServerResponse(response)
2745
4082
def _real_object(self):
2746
4083
self._branch._ensure_real()
2747
4084
return self._branch._real_branch
2830
4170
'Missing key %r in context %r', key_err.args[0], context)
2833
if err.error_verb == 'IncompatibleRepositories':
2834
raise errors.IncompatibleRepositories(err.error_args[0],
2835
err.error_args[1], err.error_args[2])
2836
elif err.error_verb == 'NoSuchRevision':
2837
raise NoSuchRevision(find('branch'), err.error_args[0])
2838
elif err.error_verb == 'nosuchrevision':
2839
raise NoSuchRevision(find('repository'), err.error_args[0])
2840
elif err.error_verb == 'nobranch':
2841
if len(err.error_args) >= 1:
2842
extra = err.error_args[0]
2845
raise errors.NotBranchError(path=find('bzrdir').root_transport.base,
2847
elif err.error_verb == 'norepository':
2848
raise errors.NoRepositoryPresent(find('bzrdir'))
2849
elif err.error_verb == 'LockContention':
2850
raise errors.LockContention('(remote lock)')
2851
elif err.error_verb == 'UnlockableTransport':
2852
raise errors.UnlockableTransport(find('bzrdir').root_transport)
2853
elif err.error_verb == 'LockFailed':
2854
raise errors.LockFailed(err.error_args[0], err.error_args[1])
2855
elif err.error_verb == 'TokenMismatch':
2856
raise errors.TokenMismatch(find('token'), '(remote token)')
2857
elif err.error_verb == 'Diverged':
2858
raise errors.DivergedBranches(find('branch'), find('other_branch'))
2859
elif err.error_verb == 'TipChangeRejected':
2860
raise errors.TipChangeRejected(err.error_args[0].decode('utf8'))
2861
elif err.error_verb == 'UnstackableBranchFormat':
2862
raise errors.UnstackableBranchFormat(*err.error_args)
2863
elif err.error_verb == 'UnstackableRepositoryFormat':
2864
raise errors.UnstackableRepositoryFormat(*err.error_args)
2865
elif err.error_verb == 'NotStacked':
2866
raise errors.NotStacked(branch=find('branch'))
2867
elif err.error_verb == 'PermissionDenied':
2869
if len(err.error_args) >= 2:
2870
extra = err.error_args[1]
2873
raise errors.PermissionDenied(path, extra=extra)
2874
elif err.error_verb == 'ReadError':
2876
raise errors.ReadError(path)
2877
elif err.error_verb == 'NoSuchFile':
2879
raise errors.NoSuchFile(path)
2880
elif err.error_verb == 'FileExists':
2881
raise errors.FileExists(err.error_args[0])
2882
elif err.error_verb == 'DirectoryNotEmpty':
2883
raise errors.DirectoryNotEmpty(err.error_args[0])
2884
elif err.error_verb == 'ShortReadvError':
2885
args = err.error_args
2886
raise errors.ShortReadvError(
2887
args[0], int(args[1]), int(args[2]), int(args[3]))
2888
elif err.error_verb in ('UnicodeEncodeError', 'UnicodeDecodeError'):
4174
translator = error_translators.get(err.error_verb)
4178
raise translator(err, find, get_path)
4180
translator = no_context_error_translators.get(err.error_verb)
4182
raise errors.UnknownErrorFromSmartServer(err)
4184
raise translator(err)
4187
error_translators.register('NoSuchRevision',
4188
lambda err, find, get_path: NoSuchRevision(
4189
find('branch'), err.error_args[0]))
4190
error_translators.register('nosuchrevision',
4191
lambda err, find, get_path: NoSuchRevision(
4192
find('repository'), err.error_args[0]))
4194
def _translate_nobranch_error(err, find, get_path):
4195
if len(err.error_args) >= 1:
4196
extra = err.error_args[0]
4199
return errors.NotBranchError(path=find('bzrdir').root_transport.base,
4202
error_translators.register('nobranch', _translate_nobranch_error)
4203
error_translators.register('norepository',
4204
lambda err, find, get_path: errors.NoRepositoryPresent(
4206
error_translators.register('UnlockableTransport',
4207
lambda err, find, get_path: errors.UnlockableTransport(
4208
find('bzrdir').root_transport))
4209
error_translators.register('TokenMismatch',
4210
lambda err, find, get_path: errors.TokenMismatch(
4211
find('token'), '(remote token)'))
4212
error_translators.register('Diverged',
4213
lambda err, find, get_path: errors.DivergedBranches(
4214
find('branch'), find('other_branch')))
4215
error_translators.register('NotStacked',
4216
lambda err, find, get_path: errors.NotStacked(branch=find('branch')))
4218
def _translate_PermissionDenied(err, find, get_path):
4220
if len(err.error_args) >= 2:
4221
extra = err.error_args[1]
4224
return errors.PermissionDenied(path, extra=extra)
4226
error_translators.register('PermissionDenied', _translate_PermissionDenied)
4227
error_translators.register('ReadError',
4228
lambda err, find, get_path: errors.ReadError(get_path()))
4229
error_translators.register('NoSuchFile',
4230
lambda err, find, get_path: errors.NoSuchFile(get_path()))
4231
error_translators.register('TokenLockingNotSupported',
4232
lambda err, find, get_path: errors.TokenLockingNotSupported(
4233
find('repository')))
4234
error_translators.register('UnsuspendableWriteGroup',
4235
lambda err, find, get_path: errors.UnsuspendableWriteGroup(
4236
repository=find('repository')))
4237
error_translators.register('UnresumableWriteGroup',
4238
lambda err, find, get_path: errors.UnresumableWriteGroup(
4239
repository=find('repository'), write_groups=err.error_args[0],
4240
reason=err.error_args[1]))
4241
no_context_error_translators.register('IncompatibleRepositories',
4242
lambda err: errors.IncompatibleRepositories(
4243
err.error_args[0], err.error_args[1], err.error_args[2]))
4244
no_context_error_translators.register('LockContention',
4245
lambda err: errors.LockContention('(remote lock)'))
4246
no_context_error_translators.register('LockFailed',
4247
lambda err: errors.LockFailed(err.error_args[0], err.error_args[1]))
4248
no_context_error_translators.register('TipChangeRejected',
4249
lambda err: errors.TipChangeRejected(err.error_args[0].decode('utf8')))
4250
no_context_error_translators.register('UnstackableBranchFormat',
4251
lambda err: errors.UnstackableBranchFormat(*err.error_args))
4252
no_context_error_translators.register('UnstackableRepositoryFormat',
4253
lambda err: errors.UnstackableRepositoryFormat(*err.error_args))
4254
no_context_error_translators.register('FileExists',
4255
lambda err: errors.FileExists(err.error_args[0]))
4256
no_context_error_translators.register('DirectoryNotEmpty',
4257
lambda err: errors.DirectoryNotEmpty(err.error_args[0]))
4259
def _translate_short_readv_error(err):
4260
args = err.error_args
4261
return errors.ShortReadvError(args[0], int(args[1]), int(args[2]),
4264
no_context_error_translators.register('ShortReadvError',
4265
_translate_short_readv_error)
4267
def _translate_unicode_error(err):
2889
4268
encoding = str(err.error_args[0]) # encoding must always be a string
2890
4269
val = err.error_args[1]
2891
4270
start = int(err.error_args[2])