29
29
from bzrlib import (
32
revision as _mod_revision,
34
35
from bzrlib.trace import mutter
35
36
from bzrlib.tsort import topo_sort
36
37
from bzrlib.versionedfile import AdapterFactory, FulltextContentFactory
38
from bzrlib.i18n import gettext
39
41
def reconcile(dir, canonicalize_chks=False):
64
66
"""Perform reconciliation.
66
68
After reconciliation the following attributes document found issues:
67
inconsistent_parents: The number of revisions in the repository whose
68
ancestry was being reported incorrectly.
69
garbage_inventories: The number of inventory objects without revisions
70
that were garbage collected.
71
fixed_branch_history: None if there was no branch, False if the branch
72
history was correct, True if the branch history
73
needed to be re-normalized.
70
* `inconsistent_parents`: The number of revisions in the repository
71
whose ancestry was being reported incorrectly.
72
* `garbage_inventories`: The number of inventory objects without
73
revisions that were garbage collected.
74
* `fixed_branch_history`: None if there was no branch, False if the
75
branch history was correct, True if the branch history needed to be
75
78
self.pb = ui.ui_factory.nested_progress_bar()
90
93
# Nothing to check here
91
94
self.fixed_branch_history = None
93
ui.ui_factory.note('Reconciling branch %s' % self.branch.base)
96
ui.ui_factory.note(gettext('Reconciling branch %s') % self.branch.base)
94
97
branch_reconciler = self.branch.reconcile(thorough=True)
95
98
self.fixed_branch_history = branch_reconciler.fixed_history
97
100
def _reconcile_repository(self):
98
101
self.repo = self.bzrdir.find_repository()
99
ui.ui_factory.note('Reconciling repository %s' %
102
ui.ui_factory.note(gettext('Reconciling repository %s') %
100
103
self.repo.user_url)
101
self.pb.update("Reconciling repository", 0, 1)
104
self.pb.update(gettext("Reconciling repository"), 0, 1)
102
105
if self.canonicalize_chks:
104
107
self.repo.reconcile_canonicalize_chks
105
108
except AttributeError:
106
109
raise errors.BzrError(
107
"%s cannot canonicalize CHKs." % (self.repo,))
110
gettext("%s cannot canonicalize CHKs.") % (self.repo,))
108
111
repo_reconciler = self.repo.reconcile_canonicalize_chks()
110
113
repo_reconciler = self.repo.reconcile(thorough=True)
111
114
self.inconsistent_parents = repo_reconciler.inconsistent_parents
112
115
self.garbage_inventories = repo_reconciler.garbage_inventories
113
116
if repo_reconciler.aborted:
115
'Reconcile aborted: revision index has inconsistent parents.')
117
'Run "bzr check" for more details.')
117
ui.ui_factory.note(gettext(
118
'Reconcile aborted: revision index has inconsistent parents.'))
119
ui.ui_factory.note(gettext(
120
'Run "bzr check" for more details.'))
119
ui.ui_factory.note('Reconciliation complete.')
122
ui.ui_factory.note(gettext('Reconciliation complete.'))
122
125
class BranchReconciler(object):
143
146
self._reconcile_revision_history()
145
148
def _reconcile_revision_history(self):
146
repo = self.branch.repository
147
149
last_revno, last_revision_id = self.branch.last_revision_info()
148
150
real_history = []
151
graph = self.branch.repository.get_graph()
150
for revid in repo.iter_reverse_revision_history(
153
for revid in graph.iter_lefthand_ancestry(
154
last_revision_id, (_mod_revision.NULL_REVISION,)):
152
155
real_history.append(revid)
153
156
except errors.RevisionNotPresent:
154
157
pass # Hit a ghost left hand parent
159
162
# set_revision_history, as this will regenerate it again.
160
163
# Not really worth a whole BranchReconciler class just for this,
162
ui.ui_factory.note('Fixing last revision info %s => %s' % (
163
last_revno, len(real_history)))
165
ui.ui_factory.note(gettext('Fixing last revision info {0} '\
167
last_revno, len(real_history)))
164
168
self.branch.set_last_revision_info(len(real_history),
165
169
last_revision_id)
167
171
self.fixed_history = False
168
ui.ui_factory.note('revision_history ok.')
172
ui.ui_factory.note(gettext('revision_history ok.'))
171
175
class RepoReconciler(object):
196
200
"""Perform reconciliation.
198
202
After reconciliation the following attributes document found issues:
199
inconsistent_parents: The number of revisions in the repository whose
200
ancestry was being reported incorrectly.
201
garbage_inventories: The number of inventory objects without revisions
202
that were garbage collected.
204
* `inconsistent_parents`: The number of revisions in the repository
205
whose ancestry was being reported incorrectly.
206
* `garbage_inventories`: The number of inventory objects without
207
revisions that were garbage collected.
204
209
operation = cleanup.OperationWithCleanups(self._reconcile)
205
210
self.add_cleanup = operation.add_cleanup
225
230
(self.thorough) are treated as requiring the reweave.
227
232
transaction = self.repo.get_transaction()
228
self.pb.update('Reading inventory data')
233
self.pb.update(gettext('Reading inventory data'))
229
234
self.inventory = self.repo.inventories
230
235
self.revisions = self.repo.revisions
231
236
# the total set of revisions to process
245
250
# (no garbage inventories or we are not doing a thorough check)
246
251
if (not self.inconsistent_parents and
247
252
(not self.garbage_inventories or not self.thorough)):
248
ui.ui_factory.note('Inventory ok.')
253
ui.ui_factory.note(gettext('Inventory ok.'))
250
self.pb.update('Backing up inventory', 0, 0)
255
self.pb.update(gettext('Backing up inventory'), 0, 0)
251
256
self.repo._backup_inventory()
252
ui.ui_factory.note('Backup inventory created.')
257
ui.ui_factory.note(gettext('Backup inventory created.'))
253
258
new_inventories = self.repo._temp_inventories()
255
260
# we have topological order of revisions and non ghost parents ready.
265
270
if not (set(new_inventories.keys()) ==
266
271
set([(revid,) for revid in self.pending])):
267
272
raise AssertionError()
268
self.pb.update('Writing weave')
273
self.pb.update(gettext('Writing weave'))
269
274
self.repo._activate_new_inventory()
270
275
self.inventory = None
271
ui.ui_factory.note('Inventory regenerated.')
276
ui.ui_factory.note(gettext('Inventory regenerated.'))
273
278
def _new_inv_parents(self, revision_key):
274
279
"""Lookup ghost-filtered parents for revision_key."""
362
367
def _load_indexes(self):
363
368
"""Load indexes for the reconciliation."""
364
369
self.transaction = self.repo.get_transaction()
365
self.pb.update('Reading indexes', 0, 2)
370
self.pb.update(gettext('Reading indexes'), 0, 2)
366
371
self.inventory = self.repo.inventories
367
self.pb.update('Reading indexes', 1, 2)
372
self.pb.update(gettext('Reading indexes'), 1, 2)
368
373
self.repo._check_for_inconsistent_revision_parents()
369
374
self.revisions = self.repo.revisions
370
self.pb.update('Reading indexes', 2, 2)
375
self.pb.update(gettext('Reading indexes'), 2, 2)
372
377
def _gc_inventory(self):
373
378
"""Remove inventories that are not referenced from the revision store."""
374
self.pb.update('Checking unused inventories', 0, 1)
379
self.pb.update(gettext('Checking unused inventories'), 0, 1)
375
380
self._check_garbage_inventories()
376
self.pb.update('Checking unused inventories', 1, 3)
381
self.pb.update(gettext('Checking unused inventories'), 1, 3)
377
382
if not self.garbage_inventories:
378
ui.ui_factory.note('Inventory ok.')
383
ui.ui_factory.note(gettext('Inventory ok.'))
380
self.pb.update('Backing up inventory', 0, 0)
385
self.pb.update(gettext('Backing up inventory'), 0, 0)
381
386
self.repo._backup_inventory()
382
ui.ui_factory.note('Backup Inventory created')
387
ui.ui_factory.note(gettext('Backup Inventory created'))
383
388
# asking for '' should never return a non-empty weave
384
389
new_inventories = self.repo._temp_inventories()
385
390
# we have topological order of revisions and non ghost parents ready.
396
401
# the revisionds list
397
402
if not(set(new_inventories.keys()) == set(revision_keys)):
398
403
raise AssertionError()
399
self.pb.update('Writing weave')
404
self.pb.update(gettext('Writing weave'))
400
405
self.repo._activate_new_inventory()
401
406
self.inventory = None
402
ui.ui_factory.note('Inventory regenerated.')
407
ui.ui_factory.note(gettext('Inventory regenerated.'))
404
409
def _fix_text_parents(self):
405
410
"""Fix bad versionedfile parent entries.
437
442
versions_list.append(text_key[1])
438
443
# Do the reconcile of individual weaves.
439
444
for num, file_id in enumerate(per_id_bad_parents):
440
self.pb.update('Fixing text parents', num,
445
self.pb.update(gettext('Fixing text parents'), num,
441
446
len(per_id_bad_parents))
442
447
versions_with_bad_parents = per_id_bad_parents[file_id]
443
448
id_unused_versions = set(key[-1] for key in unused_versions