~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/reconcile.py

(gz) Fix test failure on alpha by correcting format string for
 gc_chk_sha1_record (Martin [gz])

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
from bzrlib import (
30
30
    cleanup,
31
31
    errors,
32
 
    revision as _mod_revision,
33
32
    ui,
34
33
    )
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
39
37
 
40
38
 
41
39
def reconcile(dir, canonicalize_chks=False):
66
64
        """Perform reconciliation.
67
65
 
68
66
        After reconciliation the following attributes document found issues:
69
 
 
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
76
 
          re-normalized.
 
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.
77
74
        """
78
75
        self.pb = ui.ui_factory.nested_progress_bar()
79
76
        try:
93
90
            # Nothing to check here
94
91
            self.fixed_branch_history = None
95
92
            return
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
99
96
 
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:
106
103
            try:
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()
112
109
        else:
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.'))
 
114
            ui.ui_factory.note(
 
115
                'Reconcile aborted: revision index has inconsistent parents.')
 
116
            ui.ui_factory.note(
 
117
                'Run "bzr check" for more details.')
121
118
        else:
122
 
            ui.ui_factory.note(gettext('Reconciliation complete.'))
 
119
            ui.ui_factory.note('Reconciliation complete.')
123
120
 
124
121
 
125
122
class BranchReconciler(object):
146
143
        self._reconcile_revision_history()
147
144
 
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()
152
149
        try:
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(
 
151
                    last_revision_id):
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,
164
161
            # though.
165
 
            ui.ui_factory.note(gettext('Fixing last revision info {0} '\
166
 
                                       ' => {1}').format(
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)
170
166
        else:
171
167
            self.fixed_history = False
172
 
            ui.ui_factory.note(gettext('revision_history ok.'))
 
168
            ui.ui_factory.note('revision_history ok.')
173
169
 
174
170
 
175
171
class RepoReconciler(object):
200
196
        """Perform reconciliation.
201
197
 
202
198
        After reconciliation the following attributes document found issues:
203
 
 
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.
208
203
        """
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.
231
226
        """
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.')
254
249
            return
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()
259
254
 
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.')
277
272
 
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)
376
371
 
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.')
384
379
            return
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.')
408
403
 
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