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