103
109
# the default CommitBuilder does not manage trees whose root is versioned.
104
110
_versioned_root = False
106
def __init__(self, repository, parents, config, timestamp=None,
112
def __init__(self, repository, parents, config_stack, timestamp=None,
107
113
timezone=None, committer=None, revprops=None,
108
114
revision_id=None, lossy=False):
109
115
super(VersionedFileCommitBuilder, self).__init__(repository,
110
parents, config, timestamp, timezone, committer, revprops,
116
parents, config_stack, timestamp, timezone, committer, revprops,
111
117
revision_id, lossy)
113
119
basis_id = self.parents[0]
194
200
revision_id=self._new_revision_id,
195
201
properties=self._revprops)
196
202
rev.parent_ids = self.parents
197
self.repository.add_revision(self._new_revision_id, rev,
198
self.new_inventory, self._config)
203
if self._config_stack.get('create_signatures') == _mod_config.SIGN_ALWAYS:
204
testament = Testament(rev, self.revision_tree())
205
plaintext = testament.as_short_text()
206
self.repository.store_revision_signature(
207
gpg.GPGStrategy(self._config_stack), plaintext,
208
self._new_revision_id)
209
self.repository._add_revision(rev)
199
210
self._ensure_fallback_inventories()
200
211
self.repository.commit_write_group()
201
212
return self._new_revision_id
919
930
if not self._format.supports_external_lookups:
920
931
raise errors.UnstackableRepositoryFormat(self._format, self.base)
932
# This can raise an exception, so should be done before we lock the
933
# fallback repository.
934
self._check_fallback_repository(repository)
921
935
if self.is_locked():
922
936
# This repository will call fallback.unlock() when we transition to
923
937
# the unlocked state, so we make sure to increment the lock count
924
938
repository.lock_read()
925
self._check_fallback_repository(repository)
926
939
self._fallback_repositories.append(repository)
927
940
self.texts.add_fallback_versioned_files(repository.texts)
928
941
self.inventories.add_fallback_versioned_files(repository.inventories)
1025
1038
self.inventories._access.flush()
1028
def add_revision(self, revision_id, rev, inv=None, config=None):
1041
def add_revision(self, revision_id, rev, inv=None):
1029
1042
"""Add rev to the revision store as revision_id.
1031
1044
:param revision_id: the revision id to use.
1032
1045
:param rev: The revision object.
1033
1046
:param inv: The inventory for the revision. if None, it will be looked
1034
1047
up in the inventory storer
1035
:param config: If None no digital signature will be created.
1036
If supplied its signature_needed method will be used
1037
to determine if a signature should be made.
1039
1049
# TODO: jam 20070210 Shouldn't we check rev.revision_id and
1040
1050
# rev.parent_ids?
1041
1051
_mod_revision.check_not_reserved_id(revision_id)
1042
if config is not None and config.signature_needed():
1044
inv = self.get_inventory(revision_id)
1045
tree = InventoryRevisionTree(self, inv, revision_id)
1046
testament = Testament(rev, tree)
1047
plaintext = testament.as_short_text()
1048
self.store_revision_signature(
1049
gpg.GPGStrategy(config), plaintext, revision_id)
1050
1052
# check inventory present
1051
1053
if not self.inventories.get_parent_map([(revision_id,)]):
1052
1054
if inv is None:
1085
1087
keys = {'chk_bytes':set(), 'inventories':set(), 'texts':set()}
1086
1088
kinds = ['chk_bytes', 'texts']
1087
1089
count = len(checker.pending_keys)
1088
bar.update("inventories", 0, 2)
1090
bar.update(gettext("inventories"), 0, 2)
1089
1091
current_keys = checker.pending_keys
1090
1092
checker.pending_keys = {}
1091
1093
# Accumulate current checks.
1196
1198
"""Instantiate a VersionedFileRepository.
1198
1200
:param _format: The format of the repository on disk.
1199
:param a_bzrdir: The BzrDir of the repository.
1201
:param controldir: The ControlDir of the repository.
1200
1202
:param control_files: Control files to use for locking, etc.
1202
1204
# In the future we will have a single api for all stores for
1204
1206
# this construct will accept instances of those things.
1205
1207
super(VersionedFileRepository, self).__init__(_format, a_bzrdir,
1209
self._transport = control_files._transport
1210
self.base = self._transport.base
1208
1212
self._reconcile_does_inventory_gc = True
1209
1213
self._reconcile_fixes_text_parents = False
1214
1218
# rather copying them?
1215
1219
self._safe_to_return_from_cache = False
1221
def fetch(self, source, revision_id=None, find_ghosts=False,
1223
"""Fetch the content required to construct revision_id from source.
1225
If revision_id is None and fetch_spec is None, then all content is
1228
fetch() may not be used when the repository is in a write group -
1229
either finish the current write group before using fetch, or use
1230
fetch before starting the write group.
1232
:param find_ghosts: Find and copy revisions in the source that are
1233
ghosts in the target (and not reachable directly by walking out to
1234
the first-present revision in target from revision_id).
1235
:param revision_id: If specified, all the content needed for this
1236
revision ID will be copied to the target. Fetch will determine for
1237
itself which content needs to be copied.
1238
:param fetch_spec: If specified, a SearchResult or
1239
PendingAncestryResult that describes which revisions to copy. This
1240
allows copying multiple heads at once. Mutually exclusive with
1243
if fetch_spec is not None and revision_id is not None:
1244
raise AssertionError(
1245
"fetch_spec and revision_id are mutually exclusive.")
1246
if self.is_in_write_group():
1247
raise errors.InternalBzrError(
1248
"May not fetch while in a write group.")
1249
# fast path same-url fetch operations
1250
# TODO: lift out to somewhere common with RemoteRepository
1251
# <https://bugs.launchpad.net/bzr/+bug/401646>
1252
if (self.has_same_location(source)
1253
and fetch_spec is None
1254
and self._has_same_fallbacks(source)):
1255
# check that last_revision is in 'from' and then return a
1257
if (revision_id is not None and
1258
not _mod_revision.is_null(revision_id)):
1259
self.get_revision(revision_id)
1261
inter = InterRepository.get(source, self)
1262
if (fetch_spec is not None and
1263
not getattr(inter, "supports_fetch_spec", False)):
1264
raise errors.UnsupportedOperation(
1265
"fetch_spec not supported for %r" % inter)
1266
return inter.fetch(revision_id=revision_id,
1267
find_ghosts=find_ghosts, fetch_spec=fetch_spec)
1217
1269
@needs_read_lock
1218
1270
def gather_stats(self, revid=None, committers=None):
1219
1271
"""See Repository.gather_stats()."""
1228
1280
# result['size'] = t
1231
def get_commit_builder(self, branch, parents, config, timestamp=None,
1283
def get_commit_builder(self, branch, parents, config_stack, timestamp=None,
1232
1284
timezone=None, committer=None, revprops=None,
1233
1285
revision_id=None, lossy=False):
1234
1286
"""Obtain a CommitBuilder for this repository.
1236
1288
:param branch: Branch to commit to.
1237
1289
:param parents: Revision ids of the parents of the new revision.
1238
:param config: Configuration to use.
1290
:param config_stack: Configuration stack to use.
1239
1291
:param timestamp: Optional timestamp recorded for commit.
1240
1292
:param timezone: Optional timezone for timestamp.
1241
1293
:param committer: Optional committer to set for commit.
1248
1300
raise errors.BzrError("Cannot commit directly to a stacked branch"
1249
1301
" in pre-2a formats. See "
1250
1302
"https://bugs.launchpad.net/bzr/+bug/375013 for details.")
1251
result = self._commit_builder_class(self, parents, config,
1303
result = self._commit_builder_class(self, parents, config_stack,
1252
1304
timestamp, timezone, committer, revprops, revision_id,
1254
1306
self.start_write_group()
1510
1562
text_keys[(file_id, revision_id)] = callable_data
1511
1563
for record in self.texts.get_record_stream(text_keys, 'unordered', True):
1512
1564
if record.storage_kind == 'absent':
1513
raise errors.RevisionNotPresent(record.key, self)
1565
raise errors.RevisionNotPresent(record.key[1], record.key[0])
1514
1566
yield text_keys[record.key], record.get_bytes_as('chunked')
1516
1568
def _generate_text_key_index(self, text_key_references=None,
1566
1618
batch_size = 10 # should be ~150MB on a 55K path tree
1567
1619
batch_count = len(revision_order) / batch_size + 1
1568
1620
processed_texts = 0
1569
pb.update("Calculating text parents", processed_texts, text_count)
1621
pb.update(gettext("Calculating text parents"), processed_texts, text_count)
1570
1622
for offset in xrange(batch_count):
1571
1623
to_query = revision_order[offset * batch_size:(offset + 1) *
1575
1627
for revision_id in to_query:
1576
1628
parent_ids = ancestors[revision_id]
1577
1629
for text_key in revision_keys[revision_id]:
1578
pb.update("Calculating text parents", processed_texts)
1630
pb.update(gettext("Calculating text parents"), processed_texts)
1579
1631
processed_texts += 1
1580
1632
candidate_parents = []
1581
1633
for parent_id in parent_ids:
1651
1703
num_file_ids = len(file_ids)
1652
1704
for file_id, altered_versions in file_ids.iteritems():
1653
1705
if pb is not None:
1654
pb.update("Fetch texts", count, num_file_ids)
1706
pb.update(gettext("Fetch texts"), count, num_file_ids)
1656
1708
yield ("file", file_id, altered_versions)
1694
1746
if ((None in revision_ids)
1695
1747
or (_mod_revision.NULL_REVISION in revision_ids)):
1696
1748
raise ValueError('cannot get null revision inventory')
1697
return self._iter_inventories(revision_ids, ordering)
1749
for inv, revid in self._iter_inventories(revision_ids, ordering):
1751
raise errors.NoSuchRevision(self, revid)
1699
1754
def _iter_inventories(self, revision_ids, ordering):
1700
1755
"""single-document based inventory iteration."""
1701
1756
inv_xmls = self._iter_inventory_xmls(revision_ids, ordering)
1702
1757
for text, revision_id in inv_xmls:
1703
yield self._deserialise_inventory(revision_id, text)
1759
yield None, revision_id
1761
yield self._deserialise_inventory(revision_id, text), revision_id
1705
1763
def _iter_inventory_xmls(self, revision_ids, ordering):
1706
1764
if ordering is None:
1725
1783
yield ''.join(chunks), record.key[-1]
1727
raise errors.NoSuchRevision(self, record.key)
1785
yield None, record.key[-1]
1728
1786
if order_as_requested:
1729
1787
# Yield as many results as we can while preserving order.
1730
1788
while next_key in text_chunks:
1759
1817
def _get_inventory_xml(self, revision_id):
1760
1818
"""Get serialized inventory as a string."""
1761
1819
texts = self._iter_inventory_xmls([revision_id], 'unordered')
1763
text, revision_id = texts.next()
1764
except StopIteration:
1765
raise errors.HistoryMissing(self, 'inventory', revision_id)
1820
text, revision_id = texts.next()
1822
raise errors.NoSuchRevision(self, revision_id)
1768
1825
@needs_read_lock
1843
1900
"""Return the graph walker for text revisions."""
1844
1901
return graph.Graph(self.texts)
1903
def revision_ids_to_search_result(self, result_set):
1904
"""Convert a set of revision ids to a graph SearchResult."""
1905
result_parents = set()
1906
for parents in self.get_graph().get_parent_map(
1907
result_set).itervalues():
1908
result_parents.update(parents)
1909
included_keys = result_set.intersection(result_parents)
1910
start_keys = result_set.difference(included_keys)
1911
exclude_keys = result_parents.difference(result_set)
1912
result = vf_search.SearchResult(start_keys, exclude_keys,
1913
len(result_set), result_set)
1846
1916
def _get_versioned_file_checker(self, text_key_references=None,
1847
1917
ancestors=None):
1848
1918
"""Return an object suitable for checking versioned files.
2462
2532
self.text_index.iterkeys()])
2463
2533
# text keys is now grouped by file_id
2464
2534
n_versions = len(self.text_index)
2465
progress_bar.update('loading text store', 0, n_versions)
2535
progress_bar.update(gettext('loading text store'), 0, n_versions)
2466
2536
parent_map = self.repository.texts.get_parent_map(self.text_index)
2467
2537
# On unlistable transports this could well be empty/error...
2468
2538
text_keys = self.repository.texts.keys()
2469
2539
unused_keys = frozenset(text_keys) - set(self.text_index)
2470
2540
for num, key in enumerate(self.text_index.iterkeys()):
2471
progress_bar.update('checking text graph', num, n_versions)
2541
progress_bar.update(gettext('checking text graph'), num, n_versions)
2472
2542
correct_parents = self.calculate_file_version_parents(key)
2474
2544
knit_parents = parent_map[key]
2565
2637
searcher.stop_searching_any(stop_revs)
2566
2638
if searcher_exhausted:
2568
return searcher.get_result()
2640
(started_keys, excludes, included_keys) = searcher.get_state()
2641
return vf_search.SearchResult(started_keys, excludes,
2642
len(included_keys), included_keys)
2570
2644
@needs_read_lock
2571
2645
def search_missing_revision_ids(self,
2918
2992
for offset in range(0, len(revision_ids), batch_size):
2919
2993
self.target.start_write_group()
2921
pb.update('Transferring revisions', offset,
2995
pb.update(gettext('Transferring revisions'), offset,
2922
2996
len(revision_ids))
2923
2997
batch = revision_ids[offset:offset+batch_size]
2924
2998
basis_id = self._fetch_batch(batch, basis_id, cache)
3047
3121
_install_revision(repository, revision, revision_tree, signature,
3048
3122
inventory_cache)
3049
3123
if pb is not None:
3050
pb.update('Transferring revisions', n + 1, num_revisions)
3124
pb.update(gettext('Transferring revisions'), n + 1, num_revisions)
3052
3126
repository.abort_write_group()