559
417
ie.revision = parent_entry.revision
560
418
return self._get_delta(ie, basis_inv, path), False, None
561
419
ie.reference_revision = content_summary[3]
562
if ie.reference_revision is None:
563
raise AssertionError("invalid content_summary for nested tree: %r"
564
% (content_summary,))
565
self._add_text_to_weave(ie.file_id, '', heads, None)
421
self._add_text_to_weave(ie.file_id, lines, heads, None)
567
423
raise NotImplementedError('unknown kind')
568
424
ie.revision = self._new_revision_id
569
self._any_changes = True
570
425
return self._get_delta(ie, basis_inv, path), True, fingerprint
572
def record_iter_changes(self, tree, basis_revision_id, iter_changes,
573
_entry_factory=entry_factory):
574
"""Record a new tree via iter_changes.
576
:param tree: The tree to obtain text contents from for changed objects.
577
:param basis_revision_id: The revision id of the tree the iter_changes
578
has been generated against. Currently assumed to be the same
579
as self.parents[0] - if it is not, errors may occur.
580
:param iter_changes: An iter_changes iterator with the changes to apply
581
to basis_revision_id. The iterator must not include any items with
582
a current kind of None - missing items must be either filtered out
583
or errored-on beefore record_iter_changes sees the item.
584
:param _entry_factory: Private method to bind entry_factory locally for
586
:return: A generator of (file_id, relpath, fs_hash) tuples for use with
589
# Create an inventory delta based on deltas between all the parents and
590
# deltas between all the parent inventories. We use inventory delta's
591
# between the inventory objects because iter_changes masks
592
# last-changed-field only changes.
594
# file_id -> change map, change is fileid, paths, changed, versioneds,
595
# parents, names, kinds, executables
597
# {file_id -> revision_id -> inventory entry, for entries in parent
598
# trees that are not parents[0]
602
revtrees = list(self.repository.revision_trees(self.parents))
603
except errors.NoSuchRevision:
604
# one or more ghosts, slow path.
606
for revision_id in self.parents:
608
revtrees.append(self.repository.revision_tree(revision_id))
609
except errors.NoSuchRevision:
611
basis_revision_id = _mod_revision.NULL_REVISION
613
revtrees.append(self.repository.revision_tree(
614
_mod_revision.NULL_REVISION))
615
# The basis inventory from a repository
617
basis_inv = revtrees[0].inventory
619
basis_inv = self.repository.revision_tree(
620
_mod_revision.NULL_REVISION).inventory
621
if len(self.parents) > 0:
622
if basis_revision_id != self.parents[0] and not ghost_basis:
624
"arbitrary basis parents not yet supported with merges")
625
for revtree in revtrees[1:]:
626
for change in revtree.inventory._make_delta(basis_inv):
627
if change[1] is None:
628
# Not present in this parent.
630
if change[2] not in merged_ids:
631
if change[0] is not None:
632
basis_entry = basis_inv[change[2]]
633
merged_ids[change[2]] = [
635
basis_entry.revision,
638
parent_entries[change[2]] = {
640
basis_entry.revision:basis_entry,
642
change[3].revision:change[3],
645
merged_ids[change[2]] = [change[3].revision]
646
parent_entries[change[2]] = {change[3].revision:change[3]}
648
merged_ids[change[2]].append(change[3].revision)
649
parent_entries[change[2]][change[3].revision] = change[3]
652
# Setup the changes from the tree:
653
# changes maps file_id -> (change, [parent revision_ids])
655
for change in iter_changes:
656
# This probably looks up in basis_inv way to much.
657
if change[1][0] is not None:
658
head_candidate = [basis_inv[change[0]].revision]
661
changes[change[0]] = change, merged_ids.get(change[0],
663
unchanged_merged = set(merged_ids) - set(changes)
664
# Extend the changes dict with synthetic changes to record merges of
666
for file_id in unchanged_merged:
667
# Record a merged version of these items that did not change vs the
668
# basis. This can be either identical parallel changes, or a revert
669
# of a specific file after a merge. The recorded content will be
670
# that of the current tree (which is the same as the basis), but
671
# the per-file graph will reflect a merge.
672
# NB:XXX: We are reconstructing path information we had, this
673
# should be preserved instead.
674
# inv delta change: (file_id, (path_in_source, path_in_target),
675
# changed_content, versioned, parent, name, kind,
678
basis_entry = basis_inv[file_id]
679
except errors.NoSuchId:
680
# a change from basis->some_parents but file_id isn't in basis
681
# so was new in the merge, which means it must have changed
682
# from basis -> current, and as it hasn't the add was reverted
683
# by the user. So we discard this change.
687
(basis_inv.id2path(file_id), tree.id2path(file_id)),
689
(basis_entry.parent_id, basis_entry.parent_id),
690
(basis_entry.name, basis_entry.name),
691
(basis_entry.kind, basis_entry.kind),
692
(basis_entry.executable, basis_entry.executable))
693
changes[file_id] = (change, merged_ids[file_id])
694
# changes contains tuples with the change and a set of inventory
695
# candidates for the file.
697
# old_path, new_path, file_id, new_inventory_entry
698
seen_root = False # Is the root in the basis delta?
699
inv_delta = self._basis_delta
700
modified_rev = self._new_revision_id
701
for change, head_candidates in changes.values():
702
if change[3][1]: # versioned in target.
703
# Several things may be happening here:
704
# We may have a fork in the per-file graph
705
# - record a change with the content from tree
706
# We may have a change against < all trees
707
# - carry over the tree that hasn't changed
708
# We may have a change against all trees
709
# - record the change with the content from tree
712
entry = _entry_factory[kind](file_id, change[5][1],
714
head_set = self._heads(change[0], set(head_candidates))
717
for head_candidate in head_candidates:
718
if head_candidate in head_set:
719
heads.append(head_candidate)
720
head_set.remove(head_candidate)
723
# Could be a carry-over situation:
724
parent_entry_revs = parent_entries.get(file_id, None)
725
if parent_entry_revs:
726
parent_entry = parent_entry_revs.get(heads[0], None)
729
if parent_entry is None:
730
# The parent iter_changes was called against is the one
731
# that is the per-file head, so any change is relevant
732
# iter_changes is valid.
733
carry_over_possible = False
735
# could be a carry over situation
736
# A change against the basis may just indicate a merge,
737
# we need to check the content against the source of the
738
# merge to determine if it was changed after the merge
740
if (parent_entry.kind != entry.kind or
741
parent_entry.parent_id != entry.parent_id or
742
parent_entry.name != entry.name):
743
# Metadata common to all entries has changed
744
# against per-file parent
745
carry_over_possible = False
747
carry_over_possible = True
748
# per-type checks for changes against the parent_entry
751
# Cannot be a carry-over situation
752
carry_over_possible = False
753
# Populate the entry in the delta
755
# XXX: There is still a small race here: If someone reverts the content of a file
756
# after iter_changes examines and decides it has changed,
757
# we will unconditionally record a new version even if some
758
# other process reverts it while commit is running (with
759
# the revert happening after iter_changes did it's
762
entry.executable = True
764
entry.executable = False
765
if (carry_over_possible and
766
parent_entry.executable == entry.executable):
767
# Check the file length, content hash after reading
769
nostore_sha = parent_entry.text_sha1
772
file_obj, stat_value = tree.get_file_with_stat(file_id, change[1][1])
774
text = file_obj.read()
778
entry.text_sha1, entry.text_size = self._add_text_to_weave(
779
file_id, text, heads, nostore_sha)
780
yield file_id, change[1][1], (entry.text_sha1, stat_value)
781
except errors.ExistingContent:
782
# No content change against a carry_over parent
783
# Perhaps this should also yield a fs hash update?
785
entry.text_size = parent_entry.text_size
786
entry.text_sha1 = parent_entry.text_sha1
787
elif kind == 'symlink':
789
entry.symlink_target = tree.get_symlink_target(file_id)
790
if (carry_over_possible and
791
parent_entry.symlink_target == entry.symlink_target):
794
self._add_text_to_weave(change[0], '', heads, None)
795
elif kind == 'directory':
796
if carry_over_possible:
799
# Nothing to set on the entry.
800
# XXX: split into the Root and nonRoot versions.
801
if change[1][1] != '' or self.repository.supports_rich_root():
802
self._add_text_to_weave(change[0], '', heads, None)
803
elif kind == 'tree-reference':
804
if not self.repository._format.supports_tree_reference:
805
# This isn't quite sane as an error, but we shouldn't
806
# ever see this code path in practice: tree's don't
807
# permit references when the repo doesn't support tree
809
raise errors.UnsupportedOperation(tree.add_reference,
811
reference_revision = tree.get_reference_revision(change[0])
812
entry.reference_revision = reference_revision
813
if (carry_over_possible and
814
parent_entry.reference_revision == reference_revision):
817
self._add_text_to_weave(change[0], '', heads, None)
819
raise AssertionError('unknown kind %r' % kind)
821
entry.revision = modified_rev
823
entry.revision = parent_entry.revision
826
new_path = change[1][1]
827
inv_delta.append((change[1][0], new_path, change[0], entry))
830
self.new_inventory = None
832
# This should perhaps be guarded by a check that the basis we
833
# commit against is the basis for the commit and if not do a delta
835
self._any_changes = True
837
# housekeeping root entry changes do not affect no-change commits.
838
self._require_root_change(tree)
839
self.basis_delta_revision = basis_revision_id
841
def _add_text_to_weave(self, file_id, new_text, parents, nostore_sha):
842
parent_keys = tuple([(file_id, parent) for parent in parents])
843
return self.repository.texts._add_text(
844
(file_id, self._new_revision_id), parent_keys, new_text,
845
nostore_sha=nostore_sha, random_id=self.random_revid)[0:2]
427
def _add_text_to_weave(self, file_id, new_lines, parents, nostore_sha):
428
# Note: as we read the content directly from the tree, we know its not
429
# been turned into unicode or badly split - but a broken tree
430
# implementation could give us bad output from readlines() so this is
431
# not a guarantee of safety. What would be better is always checking
432
# the content during test suite execution. RBC 20070912
433
parent_keys = tuple((file_id, parent) for parent in parents)
434
return self.repository.texts.add_lines(
435
(file_id, self._new_revision_id), parent_keys, new_lines,
436
nostore_sha=nostore_sha, random_id=self.random_revid,
437
check_content=False)[0:2]
848
440
class RootCommitBuilder(CommitBuilder):
849
441
"""This commitbuilder actually records the root id"""
851
443
# the root entry gets versioned properly by this builder.
852
444
_versioned_root = True
1196
670
# The old API returned a list, should this actually be a set?
1197
671
return parent_map.keys()
1199
def _check_inventories(self, checker):
1200
"""Check the inventories found from the revision scan.
1202
This is responsible for verifying the sha1 of inventories and
1203
creating a pending_keys set that covers data referenced by inventories.
1205
bar = ui.ui_factory.nested_progress_bar()
1207
self._do_check_inventories(checker, bar)
1211
def _do_check_inventories(self, checker, bar):
1212
"""Helper for _check_inventories."""
1214
keys = {'chk_bytes':set(), 'inventories':set(), 'texts':set()}
1215
kinds = ['chk_bytes', 'texts']
1216
count = len(checker.pending_keys)
1217
bar.update("inventories", 0, 2)
1218
current_keys = checker.pending_keys
1219
checker.pending_keys = {}
1220
# Accumulate current checks.
1221
for key in current_keys:
1222
if key[0] != 'inventories' and key[0] not in kinds:
1223
checker._report_items.append('unknown key type %r' % (key,))
1224
keys[key[0]].add(key[1:])
1225
if keys['inventories']:
1226
# NB: output order *should* be roughly sorted - topo or
1227
# inverse topo depending on repository - either way decent
1228
# to just delta against. However, pre-CHK formats didn't
1229
# try to optimise inventory layout on disk. As such the
1230
# pre-CHK code path does not use inventory deltas.
1232
for record in self.inventories.check(keys=keys['inventories']):
1233
if record.storage_kind == 'absent':
1234
checker._report_items.append(
1235
'Missing inventory {%s}' % (record.key,))
1237
last_object = self._check_record('inventories', record,
1238
checker, last_object,
1239
current_keys[('inventories',) + record.key])
1240
del keys['inventories']
1243
bar.update("texts", 1)
1244
while (checker.pending_keys or keys['chk_bytes']
1246
# Something to check.
1247
current_keys = checker.pending_keys
1248
checker.pending_keys = {}
1249
# Accumulate current checks.
1250
for key in current_keys:
1251
if key[0] not in kinds:
1252
checker._report_items.append('unknown key type %r' % (key,))
1253
keys[key[0]].add(key[1:])
1254
# Check the outermost kind only - inventories || chk_bytes || texts
1258
for record in getattr(self, kind).check(keys=keys[kind]):
1259
if record.storage_kind == 'absent':
1260
checker._report_items.append(
1261
'Missing %s {%s}' % (kind, record.key,))
1263
last_object = self._check_record(kind, record,
1264
checker, last_object, current_keys[(kind,) + record.key])
1268
def _check_record(self, kind, record, checker, last_object, item_data):
1269
"""Check a single text from this repository."""
1270
if kind == 'inventories':
1271
rev_id = record.key[0]
1272
inv = self._deserialise_inventory(rev_id,
1273
record.get_bytes_as('fulltext'))
1274
if last_object is not None:
1275
delta = inv._make_delta(last_object)
1276
for old_path, path, file_id, ie in delta:
1279
ie.check(checker, rev_id, inv)
1281
for path, ie in inv.iter_entries():
1282
ie.check(checker, rev_id, inv)
1283
if self._format.fast_deltas:
1285
elif kind == 'chk_bytes':
1286
# No code written to check chk_bytes for this repo format.
1287
checker._report_items.append(
1288
'unsupported key type chk_bytes for %s' % (record.key,))
1289
elif kind == 'texts':
1290
self._check_text(record, checker, item_data)
1292
checker._report_items.append(
1293
'unknown key type %s for %s' % (kind, record.key))
1295
def _check_text(self, record, checker, item_data):
1296
"""Check a single text."""
1297
# Check it is extractable.
1298
# TODO: check length.
1299
if record.storage_kind == 'chunked':
1300
chunks = record.get_bytes_as(record.storage_kind)
1301
sha1 = osutils.sha_strings(chunks)
1302
length = sum(map(len, chunks))
1304
content = record.get_bytes_as('fulltext')
1305
sha1 = osutils.sha_string(content)
1306
length = len(content)
1307
if item_data and sha1 != item_data[1]:
1308
checker._report_items.append(
1309
'sha1 mismatch: %s has sha1 %s expected %s referenced by %s' %
1310
(record.key, sha1, item_data[1], item_data[2]))
1313
674
def create(a_bzrdir):
1314
675
"""Construct the current default format repository in a_bzrdir."""
1589
947
"""Commit the contents accrued within the current write group.
1591
949
:seealso: start_write_group.
1593
:return: it may return an opaque hint that can be passed to 'pack'.
1595
951
if self._write_group is not self.get_transaction():
1596
952
# has an unlock or relock occured ?
1597
953
raise errors.BzrError('mismatched lock context %r and '
1598
954
'write group %r.' %
1599
955
(self.get_transaction(), self._write_group))
1600
result = self._commit_write_group()
956
self._commit_write_group()
1601
957
self._write_group = None
1604
959
def _commit_write_group(self):
1605
960
"""Template method for per-repository write group cleanup.
1607
This is called before the write group is considered to be
962
This is called before the write group is considered to be
1608
963
finished and should ensure that all data handed to the repository
1609
for writing during the write group is safely committed (to the
964
for writing during the write group is safely committed (to the
1610
965
extent possible considering file system caching etc).
1613
def suspend_write_group(self):
1614
raise errors.UnsuspendableWriteGroup(self)
1616
def get_missing_parent_inventories(self, check_for_missing_texts=True):
1617
"""Return the keys of missing inventory parents for revisions added in
1620
A revision is not complete if the inventory delta for that revision
1621
cannot be calculated. Therefore if the parent inventories of a
1622
revision are not present, the revision is incomplete, and e.g. cannot
1623
be streamed by a smart server. This method finds missing inventory
1624
parents for revisions added in this write group.
1626
if not self._format.supports_external_lookups:
1627
# This is only an issue for stacked repositories
1629
if not self.is_in_write_group():
1630
raise AssertionError('not in a write group')
1632
# XXX: We assume that every added revision already has its
1633
# corresponding inventory, so we only check for parent inventories that
1634
# might be missing, rather than all inventories.
1635
parents = set(self.revisions._index.get_missing_parents())
1636
parents.discard(_mod_revision.NULL_REVISION)
1637
unstacked_inventories = self.inventories._index
1638
present_inventories = unstacked_inventories.get_parent_map(
1639
key[-1:] for key in parents)
1640
parents.difference_update(present_inventories)
1641
if len(parents) == 0:
1642
# No missing parent inventories.
1644
if not check_for_missing_texts:
1645
return set(('inventories', rev_id) for (rev_id,) in parents)
1646
# Ok, now we have a list of missing inventories. But these only matter
1647
# if the inventories that reference them are missing some texts they
1648
# appear to introduce.
1649
# XXX: Texts referenced by all added inventories need to be present,
1650
# but at the moment we're only checking for texts referenced by
1651
# inventories at the graph's edge.
1652
key_deps = self.revisions._index._key_dependencies
1653
key_deps.satisfy_refs_for_keys(present_inventories)
1654
referrers = frozenset(r[0] for r in key_deps.get_referrers())
1655
file_ids = self.fileids_altered_by_revision_ids(referrers)
1656
missing_texts = set()
1657
for file_id, version_ids in file_ids.iteritems():
1658
missing_texts.update(
1659
(file_id, version_id) for version_id in version_ids)
1660
present_texts = self.texts.get_parent_map(missing_texts)
1661
missing_texts.difference_update(present_texts)
1662
if not missing_texts:
1663
# No texts are missing, so all revisions and their deltas are
1666
# Alternatively the text versions could be returned as the missing
1667
# keys, but this is likely to be less data.
1668
missing_keys = set(('inventories', rev_id) for (rev_id,) in parents)
1671
def refresh_data(self):
1672
"""Re-read any data needed to synchronise with disk.
1674
This method is intended to be called after another repository instance
1675
(such as one used by a smart server) has inserted data into the
1676
repository. On all repositories this will work outside of write groups.
1677
Some repository formats (pack and newer for bzrlib native formats)
1678
support refresh_data inside write groups. If called inside a write
1679
group on a repository that does not support refreshing in a write group
1680
IsInWriteGroupError will be raised.
1682
self._refresh_data()
1684
def resume_write_group(self, tokens):
1685
if not self.is_write_locked():
1686
raise errors.NotWriteLocked(self)
1687
if self._write_group:
1688
raise errors.BzrError('already in a write group')
1689
self._resume_write_group(tokens)
1690
# so we can detect unlock/relock - the write group is now entered.
1691
self._write_group = self.get_transaction()
1693
def _resume_write_group(self, tokens):
1694
raise errors.UnsuspendableWriteGroup(self)
1696
def fetch(self, source, revision_id=None, pb=None, find_ghosts=False,
968
def fetch(self, source, revision_id=None, pb=None, find_ghosts=False):
1698
969
"""Fetch the content required to construct revision_id from source.
1700
If revision_id is None and fetch_spec is None, then all content is
1703
fetch() may not be used when the repository is in a write group -
1704
either finish the current write group before using fetch, or use
1705
fetch before starting the write group.
971
If revision_id is None all content is copied.
1707
972
:param find_ghosts: Find and copy revisions in the source that are
1708
973
ghosts in the target (and not reachable directly by walking out to
1709
974
the first-present revision in target from revision_id).
1710
:param revision_id: If specified, all the content needed for this
1711
revision ID will be copied to the target. Fetch will determine for
1712
itself which content needs to be copied.
1713
:param fetch_spec: If specified, a SearchResult or
1714
PendingAncestryResult that describes which revisions to copy. This
1715
allows copying multiple heads at once. Mutually exclusive with
1718
if fetch_spec is not None and revision_id is not None:
1719
raise AssertionError(
1720
"fetch_spec and revision_id are mutually exclusive.")
1721
if self.is_in_write_group():
1722
raise errors.InternalBzrError(
1723
"May not fetch while in a write group.")
1724
976
# fast path same-url fetch operations
1725
# TODO: lift out to somewhere common with RemoteRepository
1726
# <https://bugs.launchpad.net/bzr/+bug/401646>
1727
if (self.has_same_location(source)
1728
and fetch_spec is None
1729
and self._has_same_fallbacks(source)):
977
if self.has_same_location(source):
1730
978
# check that last_revision is in 'from' and then return a
1732
980
if (revision_id is not None and
1895
1128
@needs_read_lock
1896
1129
def get_revisions(self, revision_ids):
1897
"""Get many revisions at once.
1899
Repositories that need to check data on every revision read should
1900
subclass this method.
1130
"""Get many revisions at once."""
1902
1131
return self._get_revisions(revision_ids)
1904
1133
@needs_read_lock
1905
1134
def _get_revisions(self, revision_ids):
1906
1135
"""Core work logic to get many revisions without sanity checks."""
1136
for rev_id in revision_ids:
1137
if not rev_id or not isinstance(rev_id, basestring):
1138
raise errors.InvalidRevisionId(revision_id=rev_id, branch=self)
1139
keys = [(key,) for key in revision_ids]
1140
stream = self.revisions.get_record_stream(keys, 'unordered', True)
1908
for revid, rev in self._iter_revisions(revision_ids):
1910
raise errors.NoSuchRevision(self, revid)
1142
for record in stream:
1143
if record.storage_kind == 'absent':
1144
raise errors.NoSuchRevision(self, record.key[0])
1145
text = record.get_bytes_as('fulltext')
1146
rev = self._serializer.read_revision_from_string(text)
1147
revs[record.key[0]] = rev
1912
1148
return [revs[revid] for revid in revision_ids]
1914
def _iter_revisions(self, revision_ids):
1915
"""Iterate over revision objects.
1917
:param revision_ids: An iterable of revisions to examine. None may be
1918
passed to request all revisions known to the repository. Note that
1919
not all repositories can find unreferenced revisions; for those
1920
repositories only referenced ones will be returned.
1921
:return: An iterator of (revid, revision) tuples. Absent revisions (
1922
those asked for but not available) are returned as (revid, None).
1924
if revision_ids is None:
1925
revision_ids = self.all_revision_ids()
1927
for rev_id in revision_ids:
1928
if not rev_id or not isinstance(rev_id, basestring):
1929
raise errors.InvalidRevisionId(revision_id=rev_id, branch=self)
1930
keys = [(key,) for key in revision_ids]
1931
stream = self.revisions.get_record_stream(keys, 'unordered', True)
1932
for record in stream:
1933
revid = record.key[0]
1934
if record.storage_kind == 'absent':
1937
text = record.get_bytes_as('fulltext')
1938
rev = self._serializer.read_revision_from_string(text)
1941
def get_deltas_for_revisions(self, revisions, specific_fileids=None):
1151
def get_revision_xml(self, revision_id):
1152
# TODO: jam 20070210 This shouldn't be necessary since get_revision
1153
# would have already do it.
1154
# TODO: jam 20070210 Just use _serializer.write_revision_to_string()
1155
rev = self.get_revision(revision_id)
1156
rev_tmp = cStringIO.StringIO()
1157
# the current serializer..
1158
self._serializer.write_revision(rev, rev_tmp)
1160
return rev_tmp.getvalue()
1162
def get_deltas_for_revisions(self, revisions):
1942
1163
"""Produce a generator of revision deltas.
1944
1165
Note that the input is a sequence of REVISIONS, not revision_ids.
1945
1166
Trees will be held in memory until the generator exits.
1946
1167
Each delta is relative to the revision's lefthand predecessor.
1948
:param specific_fileids: if not None, the result is filtered
1949
so that only those file-ids, their parents and their
1950
children are included.
1952
# Get the revision-ids of interest
1953
1169
required_trees = set()
1954
1170
for revision in revisions:
1955
1171
required_trees.add(revision.revision_id)
1956
1172
required_trees.update(revision.parent_ids[:1])
1958
# Get the matching filtered trees. Note that it's more
1959
# efficient to pass filtered trees to changes_from() rather
1960
# than doing the filtering afterwards. changes_from() could
1961
# arguably do the filtering itself but it's path-based, not
1962
# file-id based, so filtering before or afterwards is
1964
if specific_fileids is None:
1965
trees = dict((t.get_revision_id(), t) for
1966
t in self.revision_trees(required_trees))
1968
trees = dict((t.get_revision_id(), t) for
1969
t in self._filtered_revision_trees(required_trees,
1972
# Calculate the deltas
1173
trees = dict((t.get_revision_id(), t) for
1174
t in self.revision_trees(required_trees))
1973
1175
for revision in revisions:
1974
1176
if not revision.parent_ids:
1975
1177
old_tree = self.revision_tree(_mod_revision.NULL_REVISION)
2382
1533
"""Get Inventory object by revision id."""
2383
1534
return self.iter_inventories([revision_id]).next()
2385
def iter_inventories(self, revision_ids, ordering=None):
1536
def iter_inventories(self, revision_ids):
2386
1537
"""Get many inventories by revision_ids.
2388
1539
This will buffer some or all of the texts used in constructing the
2389
1540
inventories in memory, but will only parse a single inventory at a
2392
:param revision_ids: The expected revision ids of the inventories.
2393
:param ordering: optional ordering, e.g. 'topological'. If not
2394
specified, the order of revision_ids will be preserved (by
2395
buffering if necessary).
2396
1543
:return: An iterator of inventories.
2398
1545
if ((None in revision_ids)
2399
1546
or (_mod_revision.NULL_REVISION in revision_ids)):
2400
1547
raise ValueError('cannot get null revision inventory')
2401
return self._iter_inventories(revision_ids, ordering)
1548
return self._iter_inventories(revision_ids)
2403
def _iter_inventories(self, revision_ids, ordering):
1550
def _iter_inventories(self, revision_ids):
2404
1551
"""single-document based inventory iteration."""
2405
inv_xmls = self._iter_inventory_xmls(revision_ids, ordering)
2406
for text, revision_id in inv_xmls:
2407
yield self._deserialise_inventory(revision_id, text)
1552
for text, revision_id in self._iter_inventory_xmls(revision_ids):
1553
yield self.deserialise_inventory(revision_id, text)
2409
def _iter_inventory_xmls(self, revision_ids, ordering):
2410
if ordering is None:
2411
order_as_requested = True
2412
ordering = 'unordered'
2414
order_as_requested = False
1555
def _iter_inventory_xmls(self, revision_ids):
2415
1556
keys = [(revision_id,) for revision_id in revision_ids]
2418
if order_as_requested:
2419
key_iter = iter(keys)
2420
next_key = key_iter.next()
2421
stream = self.inventories.get_record_stream(keys, ordering, True)
1557
stream = self.inventories.get_record_stream(keys, 'unordered', True)
2423
1559
for record in stream:
2424
1560
if record.storage_kind != 'absent':
2425
chunks = record.get_bytes_as('chunked')
2426
if order_as_requested:
2427
text_chunks[record.key] = chunks
2429
yield ''.join(chunks), record.key[-1]
1561
texts[record.key] = record.get_bytes_as('fulltext')
2431
1563
raise errors.NoSuchRevision(self, record.key)
2432
if order_as_requested:
2433
# Yield as many results as we can while preserving order.
2434
while next_key in text_chunks:
2435
chunks = text_chunks.pop(next_key)
2436
yield ''.join(chunks), next_key[-1]
2438
next_key = key_iter.next()
2439
except StopIteration:
2440
# We still want to fully consume the get_record_stream,
2441
# just in case it is not actually finished at this point
1565
yield texts[key], key[-1]
2445
def _deserialise_inventory(self, revision_id, xml):
2446
"""Transform the xml into an inventory object.
1567
def deserialise_inventory(self, revision_id, xml):
1568
"""Transform the xml into an inventory object.
2448
1570
:param revision_id: The expected revision id of the inventory.
2449
1571
:param xml: A serialised inventory.
2451
result = self._serializer.read_inventory_from_string(xml, revision_id,
2452
entry_cache=self._inventory_entry_cache,
2453
return_from_cache=self._safe_to_return_from_cache)
1573
result = self._serializer.read_inventory_from_string(xml, revision_id)
2454
1574
if result.revision_id != revision_id:
2455
1575
raise AssertionError('revision id mismatch %s != %s' % (
2456
1576
result.revision_id, revision_id))
1579
def serialise_inventory(self, inv):
1580
return self._serializer.write_inventory_to_string(inv)
1582
def _serialise_inventory_to_lines(self, inv):
1583
return self._serializer.write_inventory_to_lines(inv)
2459
1585
def get_serializer_format(self):
2460
1586
return self._serializer.format_num
2462
1588
@needs_read_lock
2463
def _get_inventory_xml(self, revision_id):
2464
"""Get serialized inventory as a string."""
2465
texts = self._iter_inventory_xmls([revision_id], 'unordered')
1589
def get_inventory_xml(self, revision_id):
1590
"""Get inventory XML as a file object."""
1591
texts = self._iter_inventory_xmls([revision_id])
2467
1593
text, revision_id = texts.next()
2468
1594
except StopIteration:
2469
1595
raise errors.HistoryMissing(self, 'inventory', revision_id)
2472
def get_rev_id_for_revno(self, revno, known_pair):
2473
"""Return the revision id of a revno, given a later (revno, revid)
2474
pair in the same history.
2476
:return: if found (True, revid). If the available history ran out
2477
before reaching the revno, then this returns
2478
(False, (closest_revno, closest_revid)).
1599
def get_inventory_sha1(self, revision_id):
1600
"""Return the sha1 hash of the inventory entry
2480
known_revno, known_revid = known_pair
2481
partial_history = [known_revid]
2482
distance_from_known = known_revno - revno
2483
if distance_from_known < 0:
2485
'requested revno (%d) is later than given known revno (%d)'
2486
% (revno, known_revno))
2489
self, partial_history, stop_index=distance_from_known)
2490
except errors.RevisionNotPresent, err:
2491
if err.revision_id == known_revid:
2492
# The start revision (known_revid) wasn't found.
2494
# This is a stacked repository with no fallbacks, or a there's a
2495
# left-hand ghost. Either way, even though the revision named in
2496
# the error isn't in this repo, we know it's the next step in this
2497
# left-hand history.
2498
partial_history.append(err.revision_id)
2499
if len(partial_history) <= distance_from_known:
2500
# Didn't find enough history to get a revid for the revno.
2501
earliest_revno = known_revno - len(partial_history) + 1
2502
return (False, (earliest_revno, partial_history[-1]))
2503
if len(partial_history) - 1 > distance_from_known:
2504
raise AssertionError('_iter_for_revno returned too much history')
2505
return (True, partial_history[-1])
1602
return self.get_revision(revision_id).inventory_sha1
2507
1604
def iter_reverse_revision_history(self, revision_id):
2508
1605
"""Iterate backwards through revision ids in the lefthand history
3741
2760
return self.source.revision_ids_to_search_result(result_set)
3744
class InterDifferingSerializer(InterRepository):
2763
class InterPackRepo(InterSameDataRepository):
2764
"""Optimised code paths between Pack based repositories."""
2767
def _get_repo_format_to_test(self):
2768
from bzrlib.repofmt import pack_repo
2769
return pack_repo.RepositoryFormatKnitPack1()
2772
def is_compatible(source, target):
2773
"""Be compatible with known Pack formats.
2775
We don't test for the stores being of specific types because that
2776
could lead to confusing results, and there is no need to be
2779
from bzrlib.repofmt.pack_repo import RepositoryFormatPack
2781
are_packs = (isinstance(source._format, RepositoryFormatPack) and
2782
isinstance(target._format, RepositoryFormatPack))
2783
except AttributeError:
2785
return are_packs and InterRepository._same_model(source, target)
2788
def fetch(self, revision_id=None, pb=None, find_ghosts=False):
2789
"""See InterRepository.fetch()."""
2790
if (len(self.source._fallback_repositories) > 0 or
2791
len(self.target._fallback_repositories) > 0):
2792
# The pack layer is not aware of fallback repositories, so when
2793
# fetching from a stacked repository or into a stacked repository
2794
# we use the generic fetch logic which uses the VersionedFiles
2795
# attributes on repository.
2796
from bzrlib.fetch import RepoFetcher
2797
fetcher = RepoFetcher(self.target, self.source, revision_id,
2799
return fetcher.count_copied, fetcher.failed_revisions
2800
from bzrlib.repofmt.pack_repo import Packer
2801
mutter("Using fetch logic to copy between %s(%s) and %s(%s)",
2802
self.source, self.source._format, self.target, self.target._format)
2803
self.count_copied = 0
2804
if revision_id is None:
2806
# everything to do - use pack logic
2807
# to fetch from all packs to one without
2808
# inventory parsing etc, IFF nothing to be copied is in the target.
2810
source_revision_ids = frozenset(self.source.all_revision_ids())
2811
revision_ids = source_revision_ids - \
2812
frozenset(self.target_get_parent_map(source_revision_ids))
2813
revision_keys = [(revid,) for revid in revision_ids]
2814
index = self.target._pack_collection.revision_index.combined_index
2815
present_revision_ids = set(item[1][0] for item in
2816
index.iter_entries(revision_keys))
2817
revision_ids = set(revision_ids) - present_revision_ids
2818
# implementing the TODO will involve:
2819
# - detecting when all of a pack is selected
2820
# - avoiding as much as possible pre-selection, so the
2821
# more-core routines such as create_pack_from_packs can filter in
2822
# a just-in-time fashion. (though having a HEADS list on a
2823
# repository might make this a lot easier, because we could
2824
# sensibly detect 'new revisions' without doing a full index scan.
2825
elif _mod_revision.is_null(revision_id):
2830
revision_ids = self.search_missing_revision_ids(revision_id,
2831
find_ghosts=find_ghosts).get_keys()
2832
except errors.NoSuchRevision:
2833
raise errors.InstallFailed([revision_id])
2834
if len(revision_ids) == 0:
2836
packs = self.source._pack_collection.all_packs()
2837
pack = Packer(self.target._pack_collection, packs, '.fetch',
2838
revision_ids).pack()
2839
if pack is not None:
2840
self.target._pack_collection._save_pack_names()
2841
# Trigger an autopack. This may duplicate effort as we've just done
2842
# a pack creation, but for now it is simpler to think about as
2843
# 'upload data, then repack if needed'.
2844
self.target._pack_collection.autopack()
2845
return (pack.get_revision_count(), [])
2850
def search_missing_revision_ids(self, revision_id=None, find_ghosts=True):
2851
"""See InterRepository.missing_revision_ids().
2853
:param find_ghosts: Find ghosts throughout the ancestry of
2856
if not find_ghosts and revision_id is not None:
2857
return self._walk_to_common_revisions([revision_id])
2858
elif revision_id is not None:
2859
# Find ghosts: search for revisions pointing from one repository to
2860
# the other, and vice versa, anywhere in the history of revision_id.
2861
graph = self.target_get_graph(other_repository=self.source)
2862
searcher = graph._make_breadth_first_searcher([revision_id])
2866
next_revs, ghosts = searcher.next_with_ghosts()
2867
except StopIteration:
2869
if revision_id in ghosts:
2870
raise errors.NoSuchRevision(self.source, revision_id)
2871
found_ids.update(next_revs)
2872
found_ids.update(ghosts)
2873
found_ids = frozenset(found_ids)
2874
# Double query here: should be able to avoid this by changing the
2875
# graph api further.
2876
result_set = found_ids - frozenset(
2877
self.target_get_parent_map(found_ids))
2879
source_ids = self.source.all_revision_ids()
2880
# source_ids is the worst possible case we may need to pull.
2881
# now we want to filter source_ids against what we actually
2882
# have in target, but don't try to check for existence where we know
2883
# we do not have a revision as that would be pointless.
2884
target_ids = set(self.target.all_revision_ids())
2885
result_set = set(source_ids).difference(target_ids)
2886
return self.source.revision_ids_to_search_result(result_set)
2889
class InterModel1and2(InterRepository):
2892
def _get_repo_format_to_test(self):
2896
def is_compatible(source, target):
2897
if not source.supports_rich_root() and target.supports_rich_root():
2903
def fetch(self, revision_id=None, pb=None, find_ghosts=False):
2904
"""See InterRepository.fetch()."""
2905
from bzrlib.fetch import Model1toKnit2Fetcher
2906
f = Model1toKnit2Fetcher(to_repository=self.target,
2907
from_repository=self.source,
2908
last_revision=revision_id,
2909
pb=pb, find_ghosts=find_ghosts)
2910
return f.count_copied, f.failed_revisions
2913
def copy_content(self, revision_id=None):
2914
"""Make a complete copy of the content in self into destination.
2916
This is a destructive operation! Do not use it on existing
2919
:param revision_id: Only copy the content needed to construct
2920
revision_id and its parents.
2923
self.target.set_make_working_trees(self.source.make_working_trees())
2924
except NotImplementedError:
2926
# but don't bother fetching if we have the needed data now.
2927
if (revision_id not in (None, _mod_revision.NULL_REVISION) and
2928
self.target.has_revision(revision_id)):
2930
self.target.fetch(self.source, revision_id=revision_id)
2933
class InterKnit1and2(InterKnitRepo):
2936
def _get_repo_format_to_test(self):
2940
def is_compatible(source, target):
2941
"""Be compatible with Knit1 source and Knit3 target"""
2943
from bzrlib.repofmt.knitrepo import (
2944
RepositoryFormatKnit1,
2945
RepositoryFormatKnit3,
2947
from bzrlib.repofmt.pack_repo import (
2948
RepositoryFormatKnitPack1,
2949
RepositoryFormatKnitPack3,
2950
RepositoryFormatKnitPack4,
2951
RepositoryFormatKnitPack5,
2952
RepositoryFormatKnitPack5RichRoot,
2953
RepositoryFormatPackDevelopment2,
2954
RepositoryFormatPackDevelopment2Subtree,
2957
RepositoryFormatKnit1, # no rr, no subtree
2958
RepositoryFormatKnitPack1, # no rr, no subtree
2959
RepositoryFormatPackDevelopment2, # no rr, no subtree
2960
RepositoryFormatKnitPack5, # no rr, no subtree
2963
RepositoryFormatKnit3, # rr, subtree
2964
RepositoryFormatKnitPack3, # rr, subtree
2965
RepositoryFormatKnitPack4, # rr, no subtree
2966
RepositoryFormatKnitPack5RichRoot,# rr, no subtree
2967
RepositoryFormatPackDevelopment2Subtree, # rr, subtree
2969
for format in norichroot:
2970
if format.rich_root_data:
2971
raise AssertionError('Format %s is a rich-root format'
2972
' but is included in the non-rich-root list'
2974
for format in richroot:
2975
if not format.rich_root_data:
2976
raise AssertionError('Format %s is not a rich-root format'
2977
' but is included in the rich-root list'
2979
# TODO: One alternative is to just check format.rich_root_data,
2980
# instead of keeping membership lists. However, the formats
2981
# *also* have to use the same 'Knit' style of storage
2982
# (line-deltas, fulltexts, etc.)
2983
return (isinstance(source._format, norichroot) and
2984
isinstance(target._format, richroot))
2985
except AttributeError:
2989
def fetch(self, revision_id=None, pb=None, find_ghosts=False):
2990
"""See InterRepository.fetch()."""
2991
from bzrlib.fetch import Knit1to2Fetcher
2992
mutter("Using fetch logic to copy between %s(%s) and %s(%s)",
2993
self.source, self.source._format, self.target,
2994
self.target._format)
2995
f = Knit1to2Fetcher(to_repository=self.target,
2996
from_repository=self.source,
2997
last_revision=revision_id,
2998
pb=pb, find_ghosts=find_ghosts)
2999
return f.count_copied, f.failed_revisions
3002
class InterDifferingSerializer(InterKnitRepo):
3747
3005
def _get_repo_format_to_test(self):
3751
3009
def is_compatible(source, target):
3752
3010
"""Be compatible with Knit2 source and Knit3 target"""
3753
# This is redundant with format.check_conversion_target(), however that
3754
# raises an exception, and we just want to say "False" as in we won't
3755
# support converting between these formats.
3756
if 'IDS_never' in debug.debug_flags:
3758
if source.supports_rich_root() and not target.supports_rich_root():
3760
if (source._format.supports_tree_reference
3761
and not target._format.supports_tree_reference):
3763
if target._fallback_repositories and target._format.supports_chks:
3764
# IDS doesn't know how to copy CHKs for the parent inventories it
3765
# adds to stacked repos.
3767
if 'IDS_always' in debug.debug_flags:
3769
# Only use this code path for local source and target. IDS does far
3770
# too much IO (both bandwidth and roundtrips) over a network.
3771
if not source.bzrdir.transport.base.startswith('file:///'):
3773
if not target.bzrdir.transport.base.startswith('file:///'):
3011
if source.supports_rich_root() != target.supports_rich_root():
3013
# Ideally, we'd support fetching if the source had no tree references
3014
# even if it supported them...
3015
if (getattr(source, '_format.supports_tree_reference', False) and
3016
not getattr(target, '_format.supports_tree_reference', False)):
3777
def _get_trees(self, revision_ids, cache):
3779
for rev_id in revision_ids:
3781
possible_trees.append((rev_id, cache[rev_id]))
3783
# Not cached, but inventory might be present anyway.
3785
tree = self.source.revision_tree(rev_id)
3786
except errors.NoSuchRevision:
3787
# Nope, parent is ghost.
3790
cache[rev_id] = tree
3791
possible_trees.append((rev_id, tree))
3792
return possible_trees
3794
def _get_delta_for_revision(self, tree, parent_ids, possible_trees):
3795
"""Get the best delta and base for this revision.
3797
:return: (basis_id, delta)
3800
# Generate deltas against each tree, to find the shortest.
3801
texts_possibly_new_in_tree = set()
3802
for basis_id, basis_tree in possible_trees:
3803
delta = tree.inventory._make_delta(basis_tree.inventory)
3804
for old_path, new_path, file_id, new_entry in delta:
3805
if new_path is None:
3806
# This file_id isn't present in the new rev, so we don't
3810
# Rich roots are handled elsewhere...
3812
kind = new_entry.kind
3813
if kind != 'directory' and kind != 'file':
3814
# No text record associated with this inventory entry.
3816
# This is a directory or file that has changed somehow.
3817
texts_possibly_new_in_tree.add((file_id, new_entry.revision))
3818
deltas.append((len(delta), basis_id, delta))
3820
return deltas[0][1:]
3822
def _fetch_parent_invs_for_stacking(self, parent_map, cache):
3823
"""Find all parent revisions that are absent, but for which the
3824
inventory is present, and copy those inventories.
3826
This is necessary to preserve correctness when the source is stacked
3827
without fallbacks configured. (Note that in cases like upgrade the
3828
source may be not have _fallback_repositories even though it is
3832
for parents in parent_map.values():
3833
parent_revs.update(parents)
3834
present_parents = self.source.get_parent_map(parent_revs)
3835
absent_parents = set(parent_revs).difference(present_parents)
3836
parent_invs_keys_for_stacking = self.source.inventories.get_parent_map(
3837
(rev_id,) for rev_id in absent_parents)
3838
parent_inv_ids = [key[-1] for key in parent_invs_keys_for_stacking]
3839
for parent_tree in self.source.revision_trees(parent_inv_ids):
3840
current_revision_id = parent_tree.get_revision_id()
3841
parents_parents_keys = parent_invs_keys_for_stacking[
3842
(current_revision_id,)]
3843
parents_parents = [key[-1] for key in parents_parents_keys]
3844
basis_id = _mod_revision.NULL_REVISION
3845
basis_tree = self.source.revision_tree(basis_id)
3846
delta = parent_tree.inventory._make_delta(basis_tree.inventory)
3847
self.target.add_inventory_by_delta(
3848
basis_id, delta, current_revision_id, parents_parents)
3849
cache[current_revision_id] = parent_tree
3851
def _fetch_batch(self, revision_ids, basis_id, cache, a_graph=None):
3852
"""Fetch across a few revisions.
3854
:param revision_ids: The revisions to copy
3855
:param basis_id: The revision_id of a tree that must be in cache, used
3856
as a basis for delta when no other base is available
3857
:param cache: A cache of RevisionTrees that we can use.
3858
:param a_graph: A Graph object to determine the heads() of the
3859
rich-root data stream.
3860
:return: The revision_id of the last converted tree. The RevisionTree
3861
for it will be in cache
3863
# Walk though all revisions; get inventory deltas, copy referenced
3864
# texts that delta references, insert the delta, revision and
3866
root_keys_to_create = set()
3869
pending_revisions = []
3870
parent_map = self.source.get_parent_map(revision_ids)
3871
self._fetch_parent_invs_for_stacking(parent_map, cache)
3872
self.source._safe_to_return_from_cache = True
3873
for tree in self.source.revision_trees(revision_ids):
3874
# Find a inventory delta for this revision.
3875
# Find text entries that need to be copied, too.
3876
current_revision_id = tree.get_revision_id()
3877
parent_ids = parent_map.get(current_revision_id, ())
3878
parent_trees = self._get_trees(parent_ids, cache)
3879
possible_trees = list(parent_trees)
3880
if len(possible_trees) == 0:
3881
# There either aren't any parents, or the parents are ghosts,
3882
# so just use the last converted tree.
3883
possible_trees.append((basis_id, cache[basis_id]))
3884
basis_id, delta = self._get_delta_for_revision(tree, parent_ids,
3886
revision = self.source.get_revision(current_revision_id)
3887
pending_deltas.append((basis_id, delta,
3888
current_revision_id, revision.parent_ids))
3889
if self._converting_to_rich_root:
3890
self._revision_id_to_root_id[current_revision_id] = \
3892
# Determine which texts are in present in this revision but not in
3893
# any of the available parents.
3894
texts_possibly_new_in_tree = set()
3895
for old_path, new_path, file_id, entry in delta:
3896
if new_path is None:
3897
# This file_id isn't present in the new rev
3901
if not self.target.supports_rich_root():
3902
# The target doesn't support rich root, so we don't
3905
if self._converting_to_rich_root:
3906
# This can't be copied normally, we have to insert
3908
root_keys_to_create.add((file_id, entry.revision))
3911
texts_possibly_new_in_tree.add((file_id, entry.revision))
3912
for basis_id, basis_tree in possible_trees:
3913
basis_inv = basis_tree.inventory
3914
for file_key in list(texts_possibly_new_in_tree):
3915
file_id, file_revision = file_key
3917
entry = basis_inv[file_id]
3918
except errors.NoSuchId:
3920
if entry.revision == file_revision:
3921
texts_possibly_new_in_tree.remove(file_key)
3922
text_keys.update(texts_possibly_new_in_tree)
3923
pending_revisions.append(revision)
3924
cache[current_revision_id] = tree
3925
basis_id = current_revision_id
3926
self.source._safe_to_return_from_cache = False
3928
from_texts = self.source.texts
3929
to_texts = self.target.texts
3930
if root_keys_to_create:
3931
root_stream = _mod_fetch._new_root_data_stream(
3932
root_keys_to_create, self._revision_id_to_root_id, parent_map,
3933
self.source, graph=a_graph)
3934
to_texts.insert_record_stream(root_stream)
3935
to_texts.insert_record_stream(from_texts.get_record_stream(
3936
text_keys, self.target._format._fetch_order,
3937
not self.target._format._fetch_uses_deltas))
3938
# insert inventory deltas
3939
for delta in pending_deltas:
3940
self.target.add_inventory_by_delta(*delta)
3941
if self.target._fallback_repositories:
3942
# Make sure this stacked repository has all the parent inventories
3943
# for the new revisions that we are about to insert. We do this
3944
# before adding the revisions so that no revision is added until
3945
# all the inventories it may depend on are added.
3946
# Note that this is overzealous, as we may have fetched these in an
3949
revision_ids = set()
3950
for revision in pending_revisions:
3951
revision_ids.add(revision.revision_id)
3952
parent_ids.update(revision.parent_ids)
3953
parent_ids.difference_update(revision_ids)
3954
parent_ids.discard(_mod_revision.NULL_REVISION)
3955
parent_map = self.source.get_parent_map(parent_ids)
3956
# we iterate over parent_map and not parent_ids because we don't
3957
# want to try copying any revision which is a ghost
3958
for parent_tree in self.source.revision_trees(parent_map):
3959
current_revision_id = parent_tree.get_revision_id()
3960
parents_parents = parent_map[current_revision_id]
3961
possible_trees = self._get_trees(parents_parents, cache)
3962
if len(possible_trees) == 0:
3963
# There either aren't any parents, or the parents are
3964
# ghosts, so just use the last converted tree.
3965
possible_trees.append((basis_id, cache[basis_id]))
3966
basis_id, delta = self._get_delta_for_revision(parent_tree,
3967
parents_parents, possible_trees)
3968
self.target.add_inventory_by_delta(
3969
basis_id, delta, current_revision_id, parents_parents)
3970
# insert signatures and revisions
3971
for revision in pending_revisions:
3973
signature = self.source.get_signature_text(
3974
revision.revision_id)
3975
self.target.add_signature_text(revision.revision_id,
3977
except errors.NoSuchRevision:
3979
self.target.add_revision(revision.revision_id, revision)
3982
def _fetch_all_revisions(self, revision_ids, pb):
3983
"""Fetch everything for the list of revisions.
3985
:param revision_ids: The list of revisions to fetch. Must be in
3987
:param pb: A ProgressTask
3990
basis_id, basis_tree = self._get_basis(revision_ids[0])
3992
cache = lru_cache.LRUCache(100)
3993
cache[basis_id] = basis_tree
3994
del basis_tree # We don't want to hang on to it here
3996
if self._converting_to_rich_root and len(revision_ids) > 100:
3997
a_graph = _mod_fetch._get_rich_root_heads_graph(self.source,
4002
for offset in range(0, len(revision_ids), batch_size):
4003
self.target.start_write_group()
4005
pb.update('Transferring revisions', offset,
4007
batch = revision_ids[offset:offset+batch_size]
4008
basis_id = self._fetch_batch(batch, basis_id, cache,
4011
self.source._safe_to_return_from_cache = False
4012
self.target.abort_write_group()
4015
hint = self.target.commit_write_group()
4018
if hints and self.target._format.pack_compresses:
4019
self.target.pack(hint=hints)
4020
pb.update('Transferring revisions', len(revision_ids),
4023
3020
@needs_write_lock
4024
def fetch(self, revision_id=None, pb=None, find_ghosts=False,
3021
def fetch(self, revision_id=None, pb=None, find_ghosts=False):
4026
3022
"""See InterRepository.fetch()."""
4027
if fetch_spec is not None:
4028
raise AssertionError("Not implemented yet...")
4029
ui.ui_factory.warn_experimental_format_fetch(self)
4030
if (not self.source.supports_rich_root()
4031
and self.target.supports_rich_root()):
4032
self._converting_to_rich_root = True
4033
self._revision_id_to_root_id = {}
4035
self._converting_to_rich_root = False
4036
# See <https://launchpad.net/bugs/456077> asking for a warning here
4037
if self.source._format.network_name() != self.target._format.network_name():
4038
ui.ui_factory.show_user_warning('cross_format_fetch',
4039
from_format=self.source._format,
4040
to_format=self.target._format)
4041
3023
revision_ids = self.target.search_missing_revision_ids(self.source,
4042
3024
revision_id, find_ghosts=find_ghosts).get_keys()
4043
if not revision_ids:
4045
3025
revision_ids = tsort.topo_sort(
4046
3026
self.source.get_graph().get_parent_map(revision_ids))
4047
if not revision_ids:
4049
# Walk though all revisions; get inventory deltas, copy referenced
4050
# texts that delta references, insert the delta, revision and
3027
def revisions_iterator():
3028
for current_revision_id in revision_ids:
3029
revision = self.source.get_revision(current_revision_id)
3030
tree = self.source.revision_tree(current_revision_id)
3032
signature = self.source.get_signature_text(
3033
current_revision_id)
3034
except errors.NoSuchRevision:
3036
yield revision, tree, signature
4053
3038
my_pb = ui.ui_factory.nested_progress_bar()
4056
symbol_versioning.warn(
4057
symbol_versioning.deprecated_in((1, 14, 0))
4058
% "pb parameter to fetch()")
4061
self._fetch_all_revisions(revision_ids, pb)
3043
install_revisions(self.target, revisions_iterator(),
3044
len(revision_ids), pb)
4063
3046
if my_pb is not None:
4064
3047
my_pb.finished()
4065
3048
return len(revision_ids), 0
4067
def _get_basis(self, first_revision_id):
4068
"""Get a revision and tree which exists in the target.
4070
This assumes that first_revision_id is selected for transmission
4071
because all other ancestors are already present. If we can't find an
4072
ancestor we fall back to NULL_REVISION since we know that is safe.
4074
:return: (basis_id, basis_tree)
4076
first_rev = self.source.get_revision(first_revision_id)
4078
basis_id = first_rev.parent_ids[0]
4079
# only valid as a basis if the target has it
4080
self.target.get_revision(basis_id)
4081
# Try to get a basis tree - if its a ghost it will hit the
4082
# NoSuchRevision case.
4083
basis_tree = self.source.revision_tree(basis_id)
4084
except (IndexError, errors.NoSuchRevision):
4085
basis_id = _mod_revision.NULL_REVISION
4086
basis_tree = self.source.revision_tree(basis_id)
4087
return basis_id, basis_tree
3051
class InterOtherToRemote(InterRepository):
3053
_walk_to_common_revisions_batch_size = 50
3055
def __init__(self, source, target):
3056
InterRepository.__init__(self, source, target)
3057
self._real_inter = None
3060
def is_compatible(source, target):
3061
if isinstance(target, remote.RemoteRepository):
3065
def _ensure_real_inter(self):
3066
if self._real_inter is None:
3067
self.target._ensure_real()
3068
real_target = self.target._real_repository
3069
self._real_inter = InterRepository.get(self.source, real_target)
3070
# Make _real_inter use the RemoteRepository for get_parent_map
3071
self._real_inter.target_get_graph = self.target.get_graph
3072
self._real_inter.target_get_parent_map = self.target.get_parent_map
3074
def copy_content(self, revision_id=None):
3075
self._ensure_real_inter()
3076
self._real_inter.copy_content(revision_id=revision_id)
3078
def fetch(self, revision_id=None, pb=None, find_ghosts=False):
3079
self._ensure_real_inter()
3080
return self._real_inter.fetch(revision_id=revision_id, pb=pb,
3081
find_ghosts=find_ghosts)
3084
def _get_repo_format_to_test(self):
3088
class InterRemoteToOther(InterRepository):
3090
def __init__(self, source, target):
3091
InterRepository.__init__(self, source, target)
3092
self._real_inter = None
3095
def is_compatible(source, target):
3096
if not isinstance(source, remote.RemoteRepository):
3098
# Is source's model compatible with target's model?
3099
source._ensure_real()
3100
real_source = source._real_repository
3101
if isinstance(real_source, remote.RemoteRepository):
3102
raise NotImplementedError(
3103
"We don't support remote repos backed by remote repos yet.")
3104
return InterRepository._same_model(real_source, target)
3106
def _ensure_real_inter(self):
3107
if self._real_inter is None:
3108
self.source._ensure_real()
3109
real_source = self.source._real_repository
3110
self._real_inter = InterRepository.get(real_source, self.target)
3112
def fetch(self, revision_id=None, pb=None, find_ghosts=False):
3113
self._ensure_real_inter()
3114
return self._real_inter.fetch(revision_id=revision_id, pb=pb,
3115
find_ghosts=find_ghosts)
3117
def copy_content(self, revision_id=None):
3118
self._ensure_real_inter()
3119
self._real_inter.copy_content(revision_id=revision_id)
3122
def _get_repo_format_to_test(self):
4090
3127
InterRepository.register_optimiser(InterDifferingSerializer)
4091
3128
InterRepository.register_optimiser(InterSameDataRepository)
4092
3129
InterRepository.register_optimiser(InterWeaveRepo)
4093
3130
InterRepository.register_optimiser(InterKnitRepo)
3131
InterRepository.register_optimiser(InterModel1and2)
3132
InterRepository.register_optimiser(InterKnit1and2)
3133
InterRepository.register_optimiser(InterPackRepo)
3134
InterRepository.register_optimiser(InterOtherToRemote)
3135
InterRepository.register_optimiser(InterRemoteToOther)
4096
3138
class CopyConverter(object):
4097
3139
"""A repository conversion tool which just performs a copy of the content.
4099
3141
This is slow but quite reliable.
4252
3289
revision_graph[key] = tuple(parent for parent in parents if parent
4253
3290
in revision_graph)
4254
3291
return revision_graph
4257
class StreamSink(object):
4258
"""An object that can insert a stream into a repository.
4260
This interface handles the complexity of reserialising inventories and
4261
revisions from different formats, and allows unidirectional insertion into
4262
stacked repositories without looking for the missing basis parents
4266
def __init__(self, target_repo):
4267
self.target_repo = target_repo
4269
def insert_stream(self, stream, src_format, resume_tokens):
4270
"""Insert a stream's content into the target repository.
4272
:param src_format: a bzr repository format.
4274
:return: a list of resume tokens and an iterable of keys additional
4275
items required before the insertion can be completed.
4277
self.target_repo.lock_write()
4280
self.target_repo.resume_write_group(resume_tokens)
4283
self.target_repo.start_write_group()
4286
# locked_insert_stream performs a commit|suspend.
4287
return self._locked_insert_stream(stream, src_format,
4290
self.target_repo.abort_write_group(suppress_errors=True)
4293
self.target_repo.unlock()
4295
def _locked_insert_stream(self, stream, src_format, is_resume):
4296
to_serializer = self.target_repo._format._serializer
4297
src_serializer = src_format._serializer
4299
if to_serializer == src_serializer:
4300
# If serializers match and the target is a pack repository, set the
4301
# write cache size on the new pack. This avoids poor performance
4302
# on transports where append is unbuffered (such as
4303
# RemoteTransport). This is safe to do because nothing should read
4304
# back from the target repository while a stream with matching
4305
# serialization is being inserted.
4306
# The exception is that a delta record from the source that should
4307
# be a fulltext may need to be expanded by the target (see
4308
# test_fetch_revisions_with_deltas_into_pack); but we take care to
4309
# explicitly flush any buffered writes first in that rare case.
4311
new_pack = self.target_repo._pack_collection._new_pack
4312
except AttributeError:
4313
# Not a pack repository
4316
new_pack.set_write_cache_size(1024*1024)
4317
for substream_type, substream in stream:
4318
if 'stream' in debug.debug_flags:
4319
mutter('inserting substream: %s', substream_type)
4320
if substream_type == 'texts':
4321
self.target_repo.texts.insert_record_stream(substream)
4322
elif substream_type == 'inventories':
4323
if src_serializer == to_serializer:
4324
self.target_repo.inventories.insert_record_stream(
4327
self._extract_and_insert_inventories(
4328
substream, src_serializer)
4329
elif substream_type == 'inventory-deltas':
4330
self._extract_and_insert_inventory_deltas(
4331
substream, src_serializer)
4332
elif substream_type == 'chk_bytes':
4333
# XXX: This doesn't support conversions, as it assumes the
4334
# conversion was done in the fetch code.
4335
self.target_repo.chk_bytes.insert_record_stream(substream)
4336
elif substream_type == 'revisions':
4337
# This may fallback to extract-and-insert more often than
4338
# required if the serializers are different only in terms of
4340
if src_serializer == to_serializer:
4341
self.target_repo.revisions.insert_record_stream(substream)
4343
self._extract_and_insert_revisions(substream,
4345
elif substream_type == 'signatures':
4346
self.target_repo.signatures.insert_record_stream(substream)
4348
raise AssertionError('kaboom! %s' % (substream_type,))
4349
# Done inserting data, and the missing_keys calculations will try to
4350
# read back from the inserted data, so flush the writes to the new pack
4351
# (if this is pack format).
4352
if new_pack is not None:
4353
new_pack._write_data('', flush=True)
4354
# Find all the new revisions (including ones from resume_tokens)
4355
missing_keys = self.target_repo.get_missing_parent_inventories(
4356
check_for_missing_texts=is_resume)
4358
for prefix, versioned_file in (
4359
('texts', self.target_repo.texts),
4360
('inventories', self.target_repo.inventories),
4361
('revisions', self.target_repo.revisions),
4362
('signatures', self.target_repo.signatures),
4363
('chk_bytes', self.target_repo.chk_bytes),
4365
if versioned_file is None:
4367
# TODO: key is often going to be a StaticTuple object
4368
# I don't believe we can define a method by which
4369
# (prefix,) + StaticTuple will work, though we could
4370
# define a StaticTuple.sq_concat that would allow you to
4371
# pass in either a tuple or a StaticTuple as the second
4372
# object, so instead we could have:
4373
# StaticTuple(prefix) + key here...
4374
missing_keys.update((prefix,) + key for key in
4375
versioned_file.get_missing_compression_parent_keys())
4376
except NotImplementedError:
4377
# cannot even attempt suspending, and missing would have failed
4378
# during stream insertion.
4379
missing_keys = set()
4382
# suspend the write group and tell the caller what we is
4383
# missing. We know we can suspend or else we would not have
4384
# entered this code path. (All repositories that can handle
4385
# missing keys can handle suspending a write group).
4386
write_group_tokens = self.target_repo.suspend_write_group()
4387
return write_group_tokens, missing_keys
4388
hint = self.target_repo.commit_write_group()
4389
if (to_serializer != src_serializer and
4390
self.target_repo._format.pack_compresses):
4391
self.target_repo.pack(hint=hint)
4394
def _extract_and_insert_inventory_deltas(self, substream, serializer):
4395
target_rich_root = self.target_repo._format.rich_root_data
4396
target_tree_refs = self.target_repo._format.supports_tree_reference
4397
for record in substream:
4398
# Insert the delta directly
4399
inventory_delta_bytes = record.get_bytes_as('fulltext')
4400
deserialiser = inventory_delta.InventoryDeltaDeserializer()
4402
parse_result = deserialiser.parse_text_bytes(
4403
inventory_delta_bytes)
4404
except inventory_delta.IncompatibleInventoryDelta, err:
4405
trace.mutter("Incompatible delta: %s", err.msg)
4406
raise errors.IncompatibleRevision(self.target_repo._format)
4407
basis_id, new_id, rich_root, tree_refs, inv_delta = parse_result
4408
revision_id = new_id
4409
parents = [key[0] for key in record.parents]
4410
self.target_repo.add_inventory_by_delta(
4411
basis_id, inv_delta, revision_id, parents)
4413
def _extract_and_insert_inventories(self, substream, serializer,
4415
"""Generate a new inventory versionedfile in target, converting data.
4417
The inventory is retrieved from the source, (deserializing it), and
4418
stored in the target (reserializing it in a different format).
4420
target_rich_root = self.target_repo._format.rich_root_data
4421
target_tree_refs = self.target_repo._format.supports_tree_reference
4422
for record in substream:
4423
# It's not a delta, so it must be a fulltext in the source
4424
# serializer's format.
4425
bytes = record.get_bytes_as('fulltext')
4426
revision_id = record.key[0]
4427
inv = serializer.read_inventory_from_string(bytes, revision_id)
4428
parents = [key[0] for key in record.parents]
4429
self.target_repo.add_inventory(revision_id, inv, parents)
4430
# No need to keep holding this full inv in memory when the rest of
4431
# the substream is likely to be all deltas.
4434
def _extract_and_insert_revisions(self, substream, serializer):
4435
for record in substream:
4436
bytes = record.get_bytes_as('fulltext')
4437
revision_id = record.key[0]
4438
rev = serializer.read_revision_from_string(bytes)
4439
if rev.revision_id != revision_id:
4440
raise AssertionError('wtf: %s != %s' % (rev, revision_id))
4441
self.target_repo.add_revision(revision_id, rev)
4444
if self.target_repo._format._fetch_reconcile:
4445
self.target_repo.reconcile()
4448
class StreamSource(object):
4449
"""A source of a stream for fetching between repositories."""
4451
def __init__(self, from_repository, to_format):
4452
"""Create a StreamSource streaming from from_repository."""
4453
self.from_repository = from_repository
4454
self.to_format = to_format
4455
self._record_counter = RecordCounter()
4457
def delta_on_metadata(self):
4458
"""Return True if delta's are permitted on metadata streams.
4460
That is on revisions and signatures.
4462
src_serializer = self.from_repository._format._serializer
4463
target_serializer = self.to_format._serializer
4464
return (self.to_format._fetch_uses_deltas and
4465
src_serializer == target_serializer)
4467
def _fetch_revision_texts(self, revs):
4468
# fetch signatures first and then the revision texts
4469
# may need to be a InterRevisionStore call here.
4470
from_sf = self.from_repository.signatures
4471
# A missing signature is just skipped.
4472
keys = [(rev_id,) for rev_id in revs]
4473
signatures = versionedfile.filter_absent(from_sf.get_record_stream(
4475
self.to_format._fetch_order,
4476
not self.to_format._fetch_uses_deltas))
4477
# If a revision has a delta, this is actually expanded inside the
4478
# insert_record_stream code now, which is an alternate fix for
4480
from_rf = self.from_repository.revisions
4481
revisions = from_rf.get_record_stream(
4483
self.to_format._fetch_order,
4484
not self.delta_on_metadata())
4485
return [('signatures', signatures), ('revisions', revisions)]
4487
def _generate_root_texts(self, revs):
4488
"""This will be called by get_stream between fetching weave texts and
4489
fetching the inventory weave.
4491
if self._rich_root_upgrade():
4492
return _mod_fetch.Inter1and2Helper(
4493
self.from_repository).generate_root_texts(revs)
4497
def get_stream(self, search):
4499
revs = search.get_keys()
4500
graph = self.from_repository.get_graph()
4501
revs = tsort.topo_sort(graph.get_parent_map(revs))
4502
data_to_fetch = self.from_repository.item_keys_introduced_by(revs)
4504
for knit_kind, file_id, revisions in data_to_fetch:
4505
if knit_kind != phase:
4507
# Make a new progress bar for this phase
4508
if knit_kind == "file":
4509
# Accumulate file texts
4510
text_keys.extend([(file_id, revision) for revision in
4512
elif knit_kind == "inventory":
4513
# Now copy the file texts.
4514
from_texts = self.from_repository.texts
4515
yield ('texts', from_texts.get_record_stream(
4516
text_keys, self.to_format._fetch_order,
4517
not self.to_format._fetch_uses_deltas))
4518
# Cause an error if a text occurs after we have done the
4521
# Before we process the inventory we generate the root
4522
# texts (if necessary) so that the inventories references
4524
for _ in self._generate_root_texts(revs):
4526
# we fetch only the referenced inventories because we do not
4527
# know for unselected inventories whether all their required
4528
# texts are present in the other repository - it could be
4530
for info in self._get_inventory_stream(revs):
4532
elif knit_kind == "signatures":
4533
# Nothing to do here; this will be taken care of when
4534
# _fetch_revision_texts happens.
4536
elif knit_kind == "revisions":
4537
for record in self._fetch_revision_texts(revs):
4540
raise AssertionError("Unknown knit kind %r" % knit_kind)
4542
def get_stream_for_missing_keys(self, missing_keys):
4543
# missing keys can only occur when we are byte copying and not
4544
# translating (because translation means we don't send
4545
# unreconstructable deltas ever).
4547
keys['texts'] = set()
4548
keys['revisions'] = set()
4549
keys['inventories'] = set()
4550
keys['chk_bytes'] = set()
4551
keys['signatures'] = set()
4552
for key in missing_keys:
4553
keys[key[0]].add(key[1:])
4554
if len(keys['revisions']):
4555
# If we allowed copying revisions at this point, we could end up
4556
# copying a revision without copying its required texts: a
4557
# violation of the requirements for repository integrity.
4558
raise AssertionError(
4559
'cannot copy revisions to fill in missing deltas %s' % (
4560
keys['revisions'],))
4561
for substream_kind, keys in keys.iteritems():
4562
vf = getattr(self.from_repository, substream_kind)
4563
if vf is None and keys:
4564
raise AssertionError(
4565
"cannot fill in keys for a versioned file we don't"
4566
" have: %s needs %s" % (substream_kind, keys))
4568
# No need to stream something we don't have
4570
if substream_kind == 'inventories':
4571
# Some missing keys are genuinely ghosts, filter those out.
4572
present = self.from_repository.inventories.get_parent_map(keys)
4573
revs = [key[0] for key in present]
4574
# Get the inventory stream more-or-less as we do for the
4575
# original stream; there's no reason to assume that records
4576
# direct from the source will be suitable for the sink. (Think
4577
# e.g. 2a -> 1.9-rich-root).
4578
for info in self._get_inventory_stream(revs, missing=True):
4582
# Ask for full texts always so that we don't need more round trips
4583
# after this stream.
4584
# Some of the missing keys are genuinely ghosts, so filter absent
4585
# records. The Sink is responsible for doing another check to
4586
# ensure that ghosts don't introduce missing data for future
4588
stream = versionedfile.filter_absent(vf.get_record_stream(keys,
4589
self.to_format._fetch_order, True))
4590
yield substream_kind, stream
4592
def inventory_fetch_order(self):
4593
if self._rich_root_upgrade():
4594
return 'topological'
4596
return self.to_format._fetch_order
4598
def _rich_root_upgrade(self):
4599
return (not self.from_repository._format.rich_root_data and
4600
self.to_format.rich_root_data)
4602
def _get_inventory_stream(self, revision_ids, missing=False):
4603
from_format = self.from_repository._format
4604
if (from_format.supports_chks and self.to_format.supports_chks and
4605
from_format.network_name() == self.to_format.network_name()):
4606
raise AssertionError(
4607
"this case should be handled by GroupCHKStreamSource")
4608
elif 'forceinvdeltas' in debug.debug_flags:
4609
return self._get_convertable_inventory_stream(revision_ids,
4610
delta_versus_null=missing)
4611
elif from_format.network_name() == self.to_format.network_name():
4613
return self._get_simple_inventory_stream(revision_ids,
4615
elif (not from_format.supports_chks and not self.to_format.supports_chks
4616
and from_format._serializer == self.to_format._serializer):
4617
# Essentially the same format.
4618
return self._get_simple_inventory_stream(revision_ids,
4621
# Any time we switch serializations, we want to use an
4622
# inventory-delta based approach.
4623
return self._get_convertable_inventory_stream(revision_ids,
4624
delta_versus_null=missing)
4626
def _get_simple_inventory_stream(self, revision_ids, missing=False):
4627
# NB: This currently reopens the inventory weave in source;
4628
# using a single stream interface instead would avoid this.
4629
from_weave = self.from_repository.inventories
4631
delta_closure = True
4633
delta_closure = not self.delta_on_metadata()
4634
yield ('inventories', from_weave.get_record_stream(
4635
[(rev_id,) for rev_id in revision_ids],
4636
self.inventory_fetch_order(), delta_closure))
4638
def _get_convertable_inventory_stream(self, revision_ids,
4639
delta_versus_null=False):
4640
# The two formats are sufficiently different that there is no fast
4641
# path, so we need to send just inventorydeltas, which any
4642
# sufficiently modern client can insert into any repository.
4643
# The StreamSink code expects to be able to
4644
# convert on the target, so we need to put bytes-on-the-wire that can
4645
# be converted. That means inventory deltas (if the remote is <1.19,
4646
# RemoteStreamSink will fallback to VFS to insert the deltas).
4647
yield ('inventory-deltas',
4648
self._stream_invs_as_deltas(revision_ids,
4649
delta_versus_null=delta_versus_null))
4651
def _stream_invs_as_deltas(self, revision_ids, delta_versus_null=False):
4652
"""Return a stream of inventory-deltas for the given rev ids.
4654
:param revision_ids: The list of inventories to transmit
4655
:param delta_versus_null: Don't try to find a minimal delta for this
4656
entry, instead compute the delta versus the NULL_REVISION. This
4657
effectively streams a complete inventory. Used for stuff like
4658
filling in missing parents, etc.
4660
from_repo = self.from_repository
4661
revision_keys = [(rev_id,) for rev_id in revision_ids]
4662
parent_map = from_repo.inventories.get_parent_map(revision_keys)
4663
# XXX: possibly repos could implement a more efficient iter_inv_deltas
4665
inventories = self.from_repository.iter_inventories(
4666
revision_ids, 'topological')
4667
format = from_repo._format
4668
invs_sent_so_far = set([_mod_revision.NULL_REVISION])
4669
inventory_cache = lru_cache.LRUCache(50)
4670
null_inventory = from_repo.revision_tree(
4671
_mod_revision.NULL_REVISION).inventory
4672
# XXX: ideally the rich-root/tree-refs flags would be per-revision, not
4673
# per-repo (e.g. streaming a non-rich-root revision out of a rich-root
4674
# repo back into a non-rich-root repo ought to be allowed)
4675
serializer = inventory_delta.InventoryDeltaSerializer(
4676
versioned_root=format.rich_root_data,
4677
tree_references=format.supports_tree_reference)
4678
for inv in inventories:
4679
key = (inv.revision_id,)
4680
parent_keys = parent_map.get(key, ())
4682
if not delta_versus_null and parent_keys:
4683
# The caller did not ask for complete inventories and we have
4684
# some parents that we can delta against. Make a delta against
4685
# each parent so that we can find the smallest.
4686
parent_ids = [parent_key[0] for parent_key in parent_keys]
4687
for parent_id in parent_ids:
4688
if parent_id not in invs_sent_so_far:
4689
# We don't know that the remote side has this basis, so
4692
if parent_id == _mod_revision.NULL_REVISION:
4693
parent_inv = null_inventory
4695
parent_inv = inventory_cache.get(parent_id, None)
4696
if parent_inv is None:
4697
parent_inv = from_repo.get_inventory(parent_id)
4698
candidate_delta = inv._make_delta(parent_inv)
4699
if (delta is None or
4700
len(delta) > len(candidate_delta)):
4701
delta = candidate_delta
4702
basis_id = parent_id
4704
# Either none of the parents ended up being suitable, or we
4705
# were asked to delta against NULL
4706
basis_id = _mod_revision.NULL_REVISION
4707
delta = inv._make_delta(null_inventory)
4708
invs_sent_so_far.add(inv.revision_id)
4709
inventory_cache[inv.revision_id] = inv
4710
delta_serialized = ''.join(
4711
serializer.delta_to_lines(basis_id, key[-1], delta))
4712
yield versionedfile.FulltextContentFactory(
4713
key, parent_keys, None, delta_serialized)
4716
def _iter_for_revno(repo, partial_history_cache, stop_index=None,
4717
stop_revision=None):
4718
"""Extend the partial history to include a given index
4720
If a stop_index is supplied, stop when that index has been reached.
4721
If a stop_revision is supplied, stop when that revision is
4722
encountered. Otherwise, stop when the beginning of history is
4725
:param stop_index: The index which should be present. When it is
4726
present, history extension will stop.
4727
:param stop_revision: The revision id which should be present. When
4728
it is encountered, history extension will stop.
4730
start_revision = partial_history_cache[-1]
4731
iterator = repo.iter_reverse_revision_history(start_revision)
4733
#skip the last revision in the list
4736
if (stop_index is not None and
4737
len(partial_history_cache) > stop_index):
4739
if partial_history_cache[-1] == stop_revision:
4741
revision_id = iterator.next()
4742
partial_history_cache.append(revision_id)
4743
except StopIteration: