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