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