496
490
self._next_open_branch_result = None
497
491
return _mod_bzrdir.BzrDir.break_lock(self)
499
def _vfs_checkout_metadir(self):
501
return self._real_bzrdir.checkout_metadir()
503
def checkout_metadir(self):
504
"""Retrieve the controldir format to use for checkouts of this one.
506
medium = self._client._medium
507
if medium._is_remote_before((2, 5)):
508
return self._vfs_checkout_metadir()
509
path = self._path_for_remote_call(self._client)
511
response = self._client.call('BzrDir.checkout_metadir',
513
except errors.UnknownSmartMethod:
514
medium._remember_remote_is_before((2, 5))
515
return self._vfs_checkout_metadir()
516
if len(response) != 3:
517
raise errors.UnexpectedSmartServerResponse(response)
518
control_name, repo_name, branch_name = response
520
format = controldir.network_format_registry.get(control_name)
522
raise errors.UnknownFormatError(kind='control',
526
repo_format = _mod_repository.network_format_registry.get(
529
raise errors.UnknownFormatError(kind='repository',
531
format.repository_format = repo_format
534
format.set_branch_format(
535
branch.network_format_registry.get(branch_name))
537
raise errors.UnknownFormatError(kind='branch',
541
493
def _vfs_cloning_metadir(self, require_stacking=False):
542
494
self._ensure_real()
543
495
return self._real_bzrdir.cloning_metadir(
687
631
b = self.open_branch(name=name)
690
def get_branches(self, possible_transports=None, ignore_fallbacks=False):
691
path = self._path_for_remote_call(self._client)
693
response, handler = self._call_expecting_body(
694
'BzrDir.get_branches', path)
695
except errors.UnknownSmartMethod:
697
return self._real_bzrdir.get_branches()
698
if response[0] != "success":
699
raise errors.UnexpectedSmartServerResponse(response)
700
body = bencode.bdecode(handler.read_body_bytes())
702
for (name, value) in body.iteritems():
703
ret[name] = self._open_branch(name, value[0], value[1],
704
possible_transports=possible_transports,
705
ignore_fallbacks=ignore_fallbacks)
708
def set_branch_reference(self, target_branch, name=None):
709
"""See BzrDir.set_branch_reference()."""
711
name = self._get_selected_branch()
713
raise errors.NoColocatedBranchSupport(self)
715
return self._real_bzrdir.set_branch_reference(target_branch, name=name)
717
634
def get_branch_reference(self, name=None):
718
635
"""See BzrDir.get_branch_reference()."""
720
name = self._get_selected_branch()
637
# XXX JRV20100304: Support opening colocated branches
722
638
raise errors.NoColocatedBranchSupport(self)
723
639
response = self._get_branch_reference()
724
640
if response[0] == 'ref':
760
676
"""See BzrDir._get_tree_branch()."""
761
677
return None, self.open_branch(name=name)
763
def _open_branch(self, name, kind, location_or_format,
764
ignore_fallbacks=False, possible_transports=None):
679
def open_branch(self, name=None, unsupported=False,
680
ignore_fallbacks=False, possible_transports=None):
682
raise NotImplementedError('unsupported flag support not implemented yet.')
683
if self._next_open_branch_result is not None:
684
# See create_branch for details.
685
result = self._next_open_branch_result
686
self._next_open_branch_result = None
688
response = self._get_branch_reference()
689
if response[0] == 'ref':
766
690
# a branch reference, use the existing BranchReference logic.
767
691
format = BranchReferenceFormat()
768
692
return format.open(self, name=name, _found=True,
769
location=location_or_format, ignore_fallbacks=ignore_fallbacks,
693
location=response[1], ignore_fallbacks=ignore_fallbacks,
770
694
possible_transports=possible_transports)
771
branch_format_name = location_or_format
695
branch_format_name = response[1]
772
696
if not branch_format_name:
773
697
branch_format_name = None
774
698
format = RemoteBranchFormat(network_name=branch_format_name)
776
700
setup_stacking=not ignore_fallbacks, name=name,
777
701
possible_transports=possible_transports)
779
def open_branch(self, name=None, unsupported=False,
780
ignore_fallbacks=False, possible_transports=None):
782
name = self._get_selected_branch()
784
raise errors.NoColocatedBranchSupport(self)
786
raise NotImplementedError('unsupported flag support not implemented yet.')
787
if self._next_open_branch_result is not None:
788
# See create_branch for details.
789
result = self._next_open_branch_result
790
self._next_open_branch_result = None
792
response = self._get_branch_reference()
793
return self._open_branch(name, response[0], response[1],
794
possible_transports=possible_transports,
795
ignore_fallbacks=ignore_fallbacks)
797
703
def _open_repo_v1(self, path):
798
704
verb = 'BzrDir.find_repository'
799
705
response = self._call(verb, path)
1816
1720
def get_commit_builder(self, branch, parents, config, timestamp=None,
1817
1721
timezone=None, committer=None, revprops=None,
1818
1722
revision_id=None, lossy=False):
1819
"""Obtain a CommitBuilder for this repository.
1821
:param branch: Branch to commit to.
1822
:param parents: Revision ids of the parents of the new revision.
1823
:param config: Configuration to use.
1824
:param timestamp: Optional timestamp recorded for commit.
1825
:param timezone: Optional timezone for timestamp.
1826
:param committer: Optional committer to set for commit.
1827
:param revprops: Optional dictionary of revision properties.
1828
:param revision_id: Optional revision id.
1829
:param lossy: Whether to discard data that can not be natively
1830
represented, when pushing to a foreign VCS
1832
if self._fallback_repositories and not self._format.supports_chks:
1833
raise errors.BzrError("Cannot commit directly to a stacked branch"
1834
" in pre-2a formats. See "
1835
"https://bugs.launchpad.net/bzr/+bug/375013 for details.")
1836
if self._format.rich_root_data:
1837
commit_builder_kls = vf_repository.VersionedFileRootCommitBuilder
1839
commit_builder_kls = vf_repository.VersionedFileCommitBuilder
1840
result = commit_builder_kls(self, parents, config,
1841
timestamp, timezone, committer, revprops, revision_id,
1843
self.start_write_group()
1723
# FIXME: It ought to be possible to call this without immediately
1724
# triggering _ensure_real. For now it's the easiest thing to do.
1726
real_repo = self._real_repository
1727
builder = real_repo.get_commit_builder(branch, parents,
1728
config, timestamp=timestamp, timezone=timezone,
1729
committer=committer, revprops=revprops,
1730
revision_id=revision_id, lossy=lossy)
1846
1733
def add_fallback_repository(self, repository):
1847
1734
"""Add a repository to use for looking up data not held locally.
1892
1779
delta, new_revision_id, parents, basis_inv=basis_inv,
1893
1780
propagate_caches=propagate_caches)
1895
def add_revision(self, revision_id, rev, inv=None):
1896
_mod_revision.check_not_reserved_id(revision_id)
1897
key = (revision_id,)
1898
# check inventory present
1899
if not self.inventories.get_parent_map([key]):
1901
raise errors.WeaveRevisionNotPresent(revision_id,
1904
# yes, this is not suitable for adding with ghosts.
1905
rev.inventory_sha1 = self.add_inventory(revision_id, inv,
1908
rev.inventory_sha1 = self.inventories.get_sha1s([key])[key]
1909
self._add_revision(rev)
1911
def _add_revision(self, rev):
1912
if self._real_repository is not None:
1913
return self._real_repository._add_revision(rev)
1914
text = self._serializer.write_revision_to_string(rev)
1915
key = (rev.revision_id,)
1916
parents = tuple((parent,) for parent in rev.parent_ids)
1917
self._write_group_tokens, missing_keys = self._get_sink().insert_stream(
1918
[('revisions', [FulltextContentFactory(key, parents, None, text)])],
1919
self._format, self._write_group_tokens)
1782
def add_revision(self, rev_id, rev, inv=None, config=None):
1784
return self._real_repository.add_revision(
1785
rev_id, rev, inv=inv, config=config)
1921
1787
@needs_read_lock
1922
1788
def get_inventory(self, revision_id):
1923
1789
return list(self.iter_inventories([revision_id]))[0]
1925
def _iter_inventories_rpc(self, revision_ids, ordering):
1926
if ordering is None:
1927
ordering = 'unordered'
1928
path = self.bzrdir._path_for_remote_call(self._client)
1929
body = "\n".join(revision_ids)
1930
response_tuple, response_handler = (
1931
self._call_with_body_bytes_expecting_body(
1932
"VersionedFileRepository.get_inventories",
1933
(path, ordering), body))
1934
if response_tuple[0] != "ok":
1935
raise errors.UnexpectedSmartServerResponse(response_tuple)
1936
deserializer = inventory_delta.InventoryDeltaDeserializer()
1937
byte_stream = response_handler.read_streamed_body()
1938
decoded = smart_repo._byte_stream_to_stream(byte_stream)
1940
# no results whatsoever
1942
src_format, stream = decoded
1943
if src_format.network_name() != self._format.network_name():
1944
raise AssertionError(
1945
"Mismatched RemoteRepository and stream src %r, %r" % (
1946
src_format.network_name(), self._format.network_name()))
1947
# ignore the src format, it's not really relevant
1948
prev_inv = Inventory(root_id=None,
1949
revision_id=_mod_revision.NULL_REVISION)
1950
# there should be just one substream, with inventory deltas
1951
substream_kind, substream = stream.next()
1952
if substream_kind != "inventory-deltas":
1953
raise AssertionError(
1954
"Unexpected stream %r received" % substream_kind)
1955
for record in substream:
1956
(parent_id, new_id, versioned_root, tree_references, invdelta) = (
1957
deserializer.parse_text_bytes(record.get_bytes_as("fulltext")))
1958
if parent_id != prev_inv.revision_id:
1959
raise AssertionError("invalid base %r != %r" % (parent_id,
1960
prev_inv.revision_id))
1961
inv = prev_inv.create_by_apply_delta(invdelta, new_id)
1962
yield inv, inv.revision_id
1965
def _iter_inventories_vfs(self, revision_ids, ordering=None):
1967
return self._real_repository._iter_inventories(revision_ids, ordering)
1969
1791
def iter_inventories(self, revision_ids, ordering=None):
1970
"""Get many inventories by revision_ids.
1972
This will buffer some or all of the texts used in constructing the
1973
inventories in memory, but will only parse a single inventory at a
1976
:param revision_ids: The expected revision ids of the inventories.
1977
:param ordering: optional ordering, e.g. 'topological'. If not
1978
specified, the order of revision_ids will be preserved (by
1979
buffering if necessary).
1980
:return: An iterator of inventories.
1982
if ((None in revision_ids)
1983
or (_mod_revision.NULL_REVISION in revision_ids)):
1984
raise ValueError('cannot get null revision inventory')
1985
for inv, revid in self._iter_inventories(revision_ids, ordering):
1987
raise errors.NoSuchRevision(self, revid)
1990
def _iter_inventories(self, revision_ids, ordering=None):
1991
if len(revision_ids) == 0:
1993
missing = set(revision_ids)
1994
if ordering is None:
1995
order_as_requested = True
1997
order = list(revision_ids)
1999
next_revid = order.pop()
2001
order_as_requested = False
2002
if ordering != 'unordered' and self._fallback_repositories:
2003
raise ValueError('unsupported ordering %r' % ordering)
2004
iter_inv_fns = [self._iter_inventories_rpc] + [
2005
fallback._iter_inventories for fallback in
2006
self._fallback_repositories]
2008
for iter_inv in iter_inv_fns:
2009
request = [revid for revid in revision_ids if revid in missing]
2010
for inv, revid in iter_inv(request, ordering):
2013
missing.remove(inv.revision_id)
2014
if ordering != 'unordered':
2018
if order_as_requested:
2019
# Yield as many results as we can while preserving order.
2020
while next_revid in invs:
2021
inv = invs.pop(next_revid)
2022
yield inv, inv.revision_id
2024
next_revid = order.pop()
2026
# We still want to fully consume the stream, just
2027
# in case it is not actually finished at this point
2030
except errors.UnknownSmartMethod:
2031
for inv, revid in self._iter_inventories_vfs(revision_ids, ordering):
2035
if order_as_requested:
2036
if next_revid is not None:
2037
yield None, next_revid
2040
yield invs.get(revid), revid
2043
yield None, missing.pop()
1793
return self._real_repository.iter_inventories(revision_ids, ordering)
2045
1795
@needs_read_lock
2046
1796
def get_revision(self, revision_id):
2403
2150
@needs_read_lock
2404
2151
def _get_inventory_xml(self, revision_id):
2405
# This call is used by older working tree formats,
2406
# which stored a serialized basis inventory.
2407
2152
self._ensure_real()
2408
2153
return self._real_repository._get_inventory_xml(revision_id)
2411
2155
def reconcile(self, other=None, thorough=False):
2412
from bzrlib.reconcile import RepoReconciler
2413
path = self.bzrdir._path_for_remote_call(self._client)
2415
response, handler = self._call_expecting_body(
2416
'Repository.reconcile', path, self._lock_token)
2417
except (errors.UnknownSmartMethod, errors.TokenLockingNotSupported):
2419
return self._real_repository.reconcile(other=other, thorough=thorough)
2420
if response != ('ok', ):
2421
raise errors.UnexpectedSmartServerResponse(response)
2422
body = handler.read_body_bytes()
2423
result = RepoReconciler(self)
2424
for line in body.split('\n'):
2427
key, val_text = line.split(':')
2428
if key == "garbage_inventories":
2429
result.garbage_inventories = int(val_text)
2430
elif key == "inconsistent_parents":
2431
result.inconsistent_parents = int(val_text)
2433
mutter("unknown reconcile key %r" % key)
2157
return self._real_repository.reconcile(other=other, thorough=thorough)
2436
2159
def all_revision_ids(self):
2437
2160
path = self.bzrdir._path_for_remote_call(self._client)
2448
2171
revids.update(set(fallback.all_revision_ids()))
2449
2172
return list(revids)
2451
def _filtered_revision_trees(self, revision_ids, file_ids):
2452
"""Return Tree for a revision on this branch with only some files.
2454
:param revision_ids: a sequence of revision-ids;
2455
a revision-id may not be None or 'null:'
2456
:param file_ids: if not None, the result is filtered
2457
so that only those file-ids, their parents and their
2458
children are included.
2460
inventories = self.iter_inventories(revision_ids)
2461
for inv in inventories:
2462
# Should we introduce a FilteredRevisionTree class rather
2463
# than pre-filter the inventory here?
2464
filtered_inv = inv.filter(file_ids)
2465
yield InventoryRevisionTree(self, filtered_inv, filtered_inv.revision_id)
2467
2174
@needs_read_lock
2468
2175
def get_deltas_for_revisions(self, revisions, specific_fileids=None):
2469
medium = self._client._medium
2470
if medium._is_remote_before((1, 2)):
2472
for delta in self._real_repository.get_deltas_for_revisions(
2473
revisions, specific_fileids):
2476
# Get the revision-ids of interest
2477
required_trees = set()
2478
for revision in revisions:
2479
required_trees.add(revision.revision_id)
2480
required_trees.update(revision.parent_ids[:1])
2482
# Get the matching filtered trees. Note that it's more
2483
# efficient to pass filtered trees to changes_from() rather
2484
# than doing the filtering afterwards. changes_from() could
2485
# arguably do the filtering itself but it's path-based, not
2486
# file-id based, so filtering before or afterwards is
2488
if specific_fileids is None:
2489
trees = dict((t.get_revision_id(), t) for
2490
t in self.revision_trees(required_trees))
2492
trees = dict((t.get_revision_id(), t) for
2493
t in self._filtered_revision_trees(required_trees,
2496
# Calculate the deltas
2497
for revision in revisions:
2498
if not revision.parent_ids:
2499
old_tree = self.revision_tree(_mod_revision.NULL_REVISION)
2501
old_tree = trees[revision.parent_ids[0]]
2502
yield trees[revision.revision_id].changes_from(old_tree)
2177
return self._real_repository.get_deltas_for_revisions(revisions,
2178
specific_fileids=specific_fileids)
2504
2180
@needs_read_lock
2505
2181
def get_revision_delta(self, revision_id, specific_fileids=None):