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