35
35
from bzrlib.trace import mutter
36
36
from bzrlib.tsort import topo_sort
37
37
from bzrlib.versionedfile import AdapterFactory, FulltextContentFactory
38
from bzrlib.i18n import gettext
41
40
def reconcile(dir, canonicalize_chks=False):
93
92
# Nothing to check here
94
93
self.fixed_branch_history = None
96
ui.ui_factory.note(gettext('Reconciling branch %s') % self.branch.base)
95
ui.ui_factory.note('Reconciling branch %s' % self.branch.base)
97
96
branch_reconciler = self.branch.reconcile(thorough=True)
98
97
self.fixed_branch_history = branch_reconciler.fixed_history
100
99
def _reconcile_repository(self):
101
100
self.repo = self.bzrdir.find_repository()
102
ui.ui_factory.note(gettext('Reconciling repository %s') %
101
ui.ui_factory.note('Reconciling repository %s' %
103
102
self.repo.user_url)
104
self.pb.update(gettext("Reconciling repository"), 0, 1)
103
self.pb.update("Reconciling repository", 0, 1)
105
104
if self.canonicalize_chks:
107
106
self.repo.reconcile_canonicalize_chks
108
107
except AttributeError:
109
108
raise errors.BzrError(
110
gettext("%s cannot canonicalize CHKs.") % (self.repo,))
109
"%s cannot canonicalize CHKs." % (self.repo,))
111
110
repo_reconciler = self.repo.reconcile_canonicalize_chks()
113
112
repo_reconciler = self.repo.reconcile(thorough=True)
114
113
self.inconsistent_parents = repo_reconciler.inconsistent_parents
115
114
self.garbage_inventories = repo_reconciler.garbage_inventories
116
115
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.'))
117
'Reconcile aborted: revision index has inconsistent parents.')
119
'Run "bzr check" for more details.')
122
ui.ui_factory.note(gettext('Reconciliation complete.'))
121
ui.ui_factory.note('Reconciliation complete.')
125
124
class BranchReconciler(object):
162
161
# set_revision_history, as this will regenerate it again.
163
162
# 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)))
164
ui.ui_factory.note('Fixing last revision info %s => %s' % (
165
last_revno, len(real_history)))
168
166
self.branch.set_last_revision_info(len(real_history),
169
167
last_revision_id)
171
169
self.fixed_history = False
172
ui.ui_factory.note(gettext('revision_history ok.'))
170
ui.ui_factory.note('revision_history ok.')
175
173
class RepoReconciler(object):
230
228
(self.thorough) are treated as requiring the reweave.
232
230
transaction = self.repo.get_transaction()
233
self.pb.update(gettext('Reading inventory data'))
231
self.pb.update('Reading inventory data')
234
232
self.inventory = self.repo.inventories
235
233
self.revisions = self.repo.revisions
236
234
# the total set of revisions to process
250
248
# (no garbage inventories or we are not doing a thorough check)
251
249
if (not self.inconsistent_parents and
252
250
(not self.garbage_inventories or not self.thorough)):
253
ui.ui_factory.note(gettext('Inventory ok.'))
251
ui.ui_factory.note('Inventory ok.')
255
self.pb.update(gettext('Backing up inventory'), 0, 0)
253
self.pb.update('Backing up inventory', 0, 0)
256
254
self.repo._backup_inventory()
257
ui.ui_factory.note(gettext('Backup inventory created.'))
255
ui.ui_factory.note('Backup inventory created.')
258
256
new_inventories = self.repo._temp_inventories()
260
258
# we have topological order of revisions and non ghost parents ready.
270
268
if not (set(new_inventories.keys()) ==
271
269
set([(revid,) for revid in self.pending])):
272
270
raise AssertionError()
273
self.pb.update(gettext('Writing weave'))
271
self.pb.update('Writing weave')
274
272
self.repo._activate_new_inventory()
275
273
self.inventory = None
276
ui.ui_factory.note(gettext('Inventory regenerated.'))
274
ui.ui_factory.note('Inventory regenerated.')
278
276
def _new_inv_parents(self, revision_key):
279
277
"""Lookup ghost-filtered parents for revision_key."""
367
365
def _load_indexes(self):
368
366
"""Load indexes for the reconciliation."""
369
367
self.transaction = self.repo.get_transaction()
370
self.pb.update(gettext('Reading indexes'), 0, 2)
368
self.pb.update('Reading indexes', 0, 2)
371
369
self.inventory = self.repo.inventories
372
self.pb.update(gettext('Reading indexes'), 1, 2)
370
self.pb.update('Reading indexes', 1, 2)
373
371
self.repo._check_for_inconsistent_revision_parents()
374
372
self.revisions = self.repo.revisions
375
self.pb.update(gettext('Reading indexes'), 2, 2)
373
self.pb.update('Reading indexes', 2, 2)
377
375
def _gc_inventory(self):
378
376
"""Remove inventories that are not referenced from the revision store."""
379
self.pb.update(gettext('Checking unused inventories'), 0, 1)
377
self.pb.update('Checking unused inventories', 0, 1)
380
378
self._check_garbage_inventories()
381
self.pb.update(gettext('Checking unused inventories'), 1, 3)
379
self.pb.update('Checking unused inventories', 1, 3)
382
380
if not self.garbage_inventories:
383
ui.ui_factory.note(gettext('Inventory ok.'))
381
ui.ui_factory.note('Inventory ok.')
385
self.pb.update(gettext('Backing up inventory'), 0, 0)
383
self.pb.update('Backing up inventory', 0, 0)
386
384
self.repo._backup_inventory()
387
ui.ui_factory.note(gettext('Backup Inventory created'))
385
ui.ui_factory.note('Backup Inventory created')
388
386
# asking for '' should never return a non-empty weave
389
387
new_inventories = self.repo._temp_inventories()
390
388
# we have topological order of revisions and non ghost parents ready.
401
399
# the revisionds list
402
400
if not(set(new_inventories.keys()) == set(revision_keys)):
403
401
raise AssertionError()
404
self.pb.update(gettext('Writing weave'))
402
self.pb.update('Writing weave')
405
403
self.repo._activate_new_inventory()
406
404
self.inventory = None
407
ui.ui_factory.note(gettext('Inventory regenerated.'))
405
ui.ui_factory.note('Inventory regenerated.')
409
407
def _fix_text_parents(self):
410
408
"""Fix bad versionedfile parent entries.
442
440
versions_list.append(text_key[1])
443
441
# Do the reconcile of individual weaves.
444
442
for num, file_id in enumerate(per_id_bad_parents):
445
self.pb.update(gettext('Fixing text parents'), num,
443
self.pb.update('Fixing text parents', num,
446
444
len(per_id_bad_parents))
447
445
versions_with_bad_parents = per_id_bad_parents[file_id]
448
446
id_unused_versions = set(key[-1] for key in unused_versions