~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/reconcile.py

  • Committer: Jelmer Vernooij
  • Date: 2011-12-16 19:18:39 UTC
  • mto: This revision was merged to the branch mainline in revision 6391.
  • Revision ID: jelmer@samba.org-20111216191839-eg681lxqibi1qxu1
Fix remaining tests.

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,
32
33
    ui,
33
34
    )
34
35
from bzrlib.trace import mutter
35
36
from bzrlib.tsort import topo_sort
36
37
from bzrlib.versionedfile import AdapterFactory, FulltextContentFactory
 
38
from bzrlib.i18n import gettext
37
39
 
38
40
 
39
41
def reconcile(dir, canonicalize_chks=False):
64
66
        """Perform reconciliation.
65
67
 
66
68
        After reconciliation the following attributes document found issues:
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.
 
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.
74
77
        """
75
78
        self.pb = ui.ui_factory.nested_progress_bar()
76
79
        try:
90
93
            # Nothing to check here
91
94
            self.fixed_branch_history = None
92
95
            return
93
 
        ui.ui_factory.note('Reconciling branch %s' % self.branch.base)
 
96
        ui.ui_factory.note(gettext('Reconciling branch %s') % self.branch.base)
94
97
        branch_reconciler = self.branch.reconcile(thorough=True)
95
98
        self.fixed_branch_history = branch_reconciler.fixed_history
96
99
 
97
100
    def _reconcile_repository(self):
98
101
        self.repo = self.bzrdir.find_repository()
99
 
        ui.ui_factory.note('Reconciling repository %s' %
 
102
        ui.ui_factory.note(gettext('Reconciling repository %s') %
100
103
            self.repo.user_url)
101
 
        self.pb.update("Reconciling repository", 0, 1)
 
104
        self.pb.update(gettext("Reconciling repository"), 0, 1)
102
105
        if self.canonicalize_chks:
103
106
            try:
104
107
                self.repo.reconcile_canonicalize_chks
105
108
            except AttributeError:
106
109
                raise errors.BzrError(
107
 
                    "%s cannot canonicalize CHKs." % (self.repo,))
 
110
                    gettext("%s cannot canonicalize CHKs.") % (self.repo,))
108
111
            repo_reconciler = self.repo.reconcile_canonicalize_chks()
109
112
        else:
110
113
            repo_reconciler = self.repo.reconcile(thorough=True)
111
114
        self.inconsistent_parents = repo_reconciler.inconsistent_parents
112
115
        self.garbage_inventories = repo_reconciler.garbage_inventories
113
116
        if repo_reconciler.aborted:
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.')
 
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.'))
118
121
        else:
119
 
            ui.ui_factory.note('Reconciliation complete.')
 
122
            ui.ui_factory.note(gettext('Reconciliation complete.'))
120
123
 
121
124
 
122
125
class BranchReconciler(object):
143
146
        self._reconcile_revision_history()
144
147
 
145
148
    def _reconcile_revision_history(self):
146
 
        repo = self.branch.repository
147
149
        last_revno, last_revision_id = self.branch.last_revision_info()
148
150
        real_history = []
 
151
        graph = self.branch.repository.get_graph()
149
152
        try:
150
 
            for revid in repo.iter_reverse_revision_history(
151
 
                    last_revision_id):
 
153
            for revid in graph.iter_lefthand_ancestry(
 
154
                    last_revision_id, (_mod_revision.NULL_REVISION,)):
152
155
                real_history.append(revid)
153
156
        except errors.RevisionNotPresent:
154
157
            pass # Hit a ghost left hand parent
159
162
            # set_revision_history, as this will regenerate it again.
160
163
            # Not really worth a whole BranchReconciler class just for this,
161
164
            # though.
162
 
            ui.ui_factory.note('Fixing last revision info %s => %s' % (
163
 
                 last_revno, len(real_history)))
 
165
            ui.ui_factory.note(gettext('Fixing last revision info {0} '\
 
166
                                       ' => {1}').format(
 
167
                                       last_revno, len(real_history)))
164
168
            self.branch.set_last_revision_info(len(real_history),
165
169
                                               last_revision_id)
166
170
        else:
167
171
            self.fixed_history = False
168
 
            ui.ui_factory.note('revision_history ok.')
 
172
            ui.ui_factory.note(gettext('revision_history ok.'))
169
173
 
170
174
 
171
175
class RepoReconciler(object):
196
200
        """Perform reconciliation.
197
201
 
198
202
        After reconciliation the following attributes document found issues:
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.
 
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.
203
208
        """
204
209
        operation = cleanup.OperationWithCleanups(self._reconcile)
205
210
        self.add_cleanup = operation.add_cleanup
224
229
        only data-loss causing issues (!self.thorough) or all issues
225
230
        (self.thorough) are treated as requiring the reweave.
226
231
        """
227
 
        # local because needing to know about WeaveFile is a wart we want to hide
228
 
        from bzrlib.weave import WeaveFile, Weave
229
232
        transaction = self.repo.get_transaction()
230
 
        self.pb.update('Reading inventory data')
 
233
        self.pb.update(gettext('Reading inventory data'))
231
234
        self.inventory = self.repo.inventories
232
235
        self.revisions = self.repo.revisions
233
236
        # the total set of revisions to process
247
250
        # (no garbage inventories or we are not doing a thorough check)
248
251
        if (not self.inconsistent_parents and
249
252
            (not self.garbage_inventories or not self.thorough)):
250
 
            ui.ui_factory.note('Inventory ok.')
 
253
            ui.ui_factory.note(gettext('Inventory ok.'))
251
254
            return
252
 
        self.pb.update('Backing up inventory', 0, 0)
 
255
        self.pb.update(gettext('Backing up inventory'), 0, 0)
253
256
        self.repo._backup_inventory()
254
 
        ui.ui_factory.note('Backup inventory created.')
 
257
        ui.ui_factory.note(gettext('Backup inventory created.'))
255
258
        new_inventories = self.repo._temp_inventories()
256
259
 
257
260
        # we have topological order of revisions and non ghost parents ready.
267
270
        if not (set(new_inventories.keys()) ==
268
271
            set([(revid,) for revid in self.pending])):
269
272
            raise AssertionError()
270
 
        self.pb.update('Writing weave')
 
273
        self.pb.update(gettext('Writing weave'))
271
274
        self.repo._activate_new_inventory()
272
275
        self.inventory = None
273
 
        ui.ui_factory.note('Inventory regenerated.')
 
276
        ui.ui_factory.note(gettext('Inventory regenerated.'))
274
277
 
275
278
    def _new_inv_parents(self, revision_key):
276
279
        """Lookup ghost-filtered parents for revision_key."""
364
367
    def _load_indexes(self):
365
368
        """Load indexes for the reconciliation."""
366
369
        self.transaction = self.repo.get_transaction()
367
 
        self.pb.update('Reading indexes', 0, 2)
 
370
        self.pb.update(gettext('Reading indexes'), 0, 2)
368
371
        self.inventory = self.repo.inventories
369
 
        self.pb.update('Reading indexes', 1, 2)
 
372
        self.pb.update(gettext('Reading indexes'), 1, 2)
370
373
        self.repo._check_for_inconsistent_revision_parents()
371
374
        self.revisions = self.repo.revisions
372
 
        self.pb.update('Reading indexes', 2, 2)
 
375
        self.pb.update(gettext('Reading indexes'), 2, 2)
373
376
 
374
377
    def _gc_inventory(self):
375
378
        """Remove inventories that are not referenced from the revision store."""
376
 
        self.pb.update('Checking unused inventories', 0, 1)
 
379
        self.pb.update(gettext('Checking unused inventories'), 0, 1)
377
380
        self._check_garbage_inventories()
378
 
        self.pb.update('Checking unused inventories', 1, 3)
 
381
        self.pb.update(gettext('Checking unused inventories'), 1, 3)
379
382
        if not self.garbage_inventories:
380
 
            ui.ui_factory.note('Inventory ok.')
 
383
            ui.ui_factory.note(gettext('Inventory ok.'))
381
384
            return
382
 
        self.pb.update('Backing up inventory', 0, 0)
 
385
        self.pb.update(gettext('Backing up inventory'), 0, 0)
383
386
        self.repo._backup_inventory()
384
 
        ui.ui_factory.note('Backup Inventory created')
 
387
        ui.ui_factory.note(gettext('Backup Inventory created'))
385
388
        # asking for '' should never return a non-empty weave
386
389
        new_inventories = self.repo._temp_inventories()
387
390
        # we have topological order of revisions and non ghost parents ready.
398
401
        # the revisionds list
399
402
        if not(set(new_inventories.keys()) == set(revision_keys)):
400
403
            raise AssertionError()
401
 
        self.pb.update('Writing weave')
 
404
        self.pb.update(gettext('Writing weave'))
402
405
        self.repo._activate_new_inventory()
403
406
        self.inventory = None
404
 
        ui.ui_factory.note('Inventory regenerated.')
 
407
        ui.ui_factory.note(gettext('Inventory regenerated.'))
405
408
 
406
409
    def _fix_text_parents(self):
407
410
        """Fix bad versionedfile parent entries.
439
442
            versions_list.append(text_key[1])
440
443
        # Do the reconcile of individual weaves.
441
444
        for num, file_id in enumerate(per_id_bad_parents):
442
 
            self.pb.update('Fixing text parents', num,
 
445
            self.pb.update(gettext('Fixing text parents'), num,
443
446
                           len(per_id_bad_parents))
444
447
            versions_with_bad_parents = per_id_bad_parents[file_id]
445
448
            id_unused_versions = set(key[-1] for key in unused_versions