/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/reconcile.py

  • Committer: Jonathan Riddell
  • Date: 2011-09-16 10:08:09 UTC
  • mto: This revision was merged to the branch mainline in revision 6145.
  • Revision ID: jriddell@canonical.com-20110916100809-uii7a1h5tp8qguhy
add gettext to progress bar strings

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
37
 
 
38
 
 
39
 
def reconcile(dir, other=None):
 
38
from bzrlib.i18n import gettext
 
39
 
 
40
 
 
41
def reconcile(dir, canonicalize_chks=False):
40
42
    """Reconcile the data in dir.
41
43
 
42
44
    Currently this is limited to a inventory 'reweave'.
46
48
    Directly using Reconciler is recommended for library users that
47
49
    desire fine grained control or analysis of the found issues.
48
50
 
49
 
    :param other: another bzrdir to reconcile against.
 
51
    :param canonicalize_chks: Make sure CHKs are in canonical form.
50
52
    """
51
 
    reconciler = Reconciler(dir, other=other)
 
53
    reconciler = Reconciler(dir, canonicalize_chks=canonicalize_chks)
52
54
    reconciler.reconcile()
53
55
 
54
56
 
55
57
class Reconciler(object):
56
58
    """Reconcilers are used to reconcile existing data."""
57
59
 
58
 
    def __init__(self, dir, other=None):
 
60
    def __init__(self, dir, other=None, canonicalize_chks=False):
59
61
        """Create a Reconciler."""
60
62
        self.bzrdir = dir
 
63
        self.canonicalize_chks = canonicalize_chks
61
64
 
62
65
    def reconcile(self):
63
66
        """Perform reconciliation.
64
67
 
65
68
        After reconciliation the following attributes document found issues:
66
 
        inconsistent_parents: The number of revisions in the repository whose
67
 
                              ancestry was being reported incorrectly.
68
 
        garbage_inventories: The number of inventory objects without revisions
69
 
                             that were garbage collected.
70
 
        fixed_branch_history: None if there was no branch, False if the branch
71
 
                              history was correct, True if the branch history
72
 
                              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.
73
77
        """
74
78
        self.pb = ui.ui_factory.nested_progress_bar()
75
79
        try:
89
93
            # Nothing to check here
90
94
            self.fixed_branch_history = None
91
95
            return
92
 
        ui.ui_factory.note('Reconciling branch %s' % self.branch.base)
 
96
        ui.ui_factory.note(gettext('Reconciling branch %s') % self.branch.base)
93
97
        branch_reconciler = self.branch.reconcile(thorough=True)
94
98
        self.fixed_branch_history = branch_reconciler.fixed_history
95
99
 
96
100
    def _reconcile_repository(self):
97
101
        self.repo = self.bzrdir.find_repository()
98
 
        ui.ui_factory.note('Reconciling repository %s' %
 
102
        ui.ui_factory.note(gettext('Reconciling repository %s') %
99
103
            self.repo.user_url)
100
 
        self.pb.update("Reconciling repository", 0, 1)
101
 
        repo_reconciler = self.repo.reconcile(thorough=True)
 
104
        self.pb.update(gettext("Reconciling repository"), 0, 1)
 
105
        if self.canonicalize_chks:
 
106
            try:
 
107
                self.repo.reconcile_canonicalize_chks
 
108
            except AttributeError:
 
109
                raise errors.BzrError(
 
110
                    gettext("%s cannot canonicalize CHKs.") % (self.repo,))
 
111
            repo_reconciler = self.repo.reconcile_canonicalize_chks()
 
112
        else:
 
113
            repo_reconciler = self.repo.reconcile(thorough=True)
102
114
        self.inconsistent_parents = repo_reconciler.inconsistent_parents
103
115
        self.garbage_inventories = repo_reconciler.garbage_inventories
104
116
        if repo_reconciler.aborted:
105
 
            ui.ui_factory.note(
106
 
                'Reconcile aborted: revision index has inconsistent parents.')
107
 
            ui.ui_factory.note(
108
 
                '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.'))
109
121
        else:
110
 
            ui.ui_factory.note('Reconciliation complete.')
 
122
            ui.ui_factory.note(gettext('Reconciliation complete.'))
111
123
 
112
124
 
113
125
class BranchReconciler(object):
134
146
        self._reconcile_revision_history()
135
147
 
136
148
    def _reconcile_revision_history(self):
137
 
        repo = self.branch.repository
138
149
        last_revno, last_revision_id = self.branch.last_revision_info()
139
150
        real_history = []
 
151
        graph = self.branch.repository.get_graph()
140
152
        try:
141
 
            for revid in repo.iter_reverse_revision_history(
142
 
                    last_revision_id):
 
153
            for revid in graph.iter_lefthand_ancestry(
 
154
                    last_revision_id, (_mod_revision.NULL_REVISION,)):
143
155
                real_history.append(revid)
144
156
        except errors.RevisionNotPresent:
145
157
            pass # Hit a ghost left hand parent
150
162
            # set_revision_history, as this will regenerate it again.
151
163
            # Not really worth a whole BranchReconciler class just for this,
152
164
            # though.
153
 
            ui.ui_factory.note('Fixing last revision info %s => %s' % (
 
165
            ui.ui_factory.note(gettext('Fixing last revision info %s => %s') % (
154
166
                 last_revno, len(real_history)))
155
167
            self.branch.set_last_revision_info(len(real_history),
156
168
                                               last_revision_id)
157
169
        else:
158
170
            self.fixed_history = False
159
 
            ui.ui_factory.note('revision_history ok.')
 
171
            ui.ui_factory.note(gettext('revision_history ok.'))
160
172
 
161
173
 
162
174
class RepoReconciler(object):
187
199
        """Perform reconciliation.
188
200
 
189
201
        After reconciliation the following attributes document found issues:
190
 
        inconsistent_parents: The number of revisions in the repository whose
191
 
                              ancestry was being reported incorrectly.
192
 
        garbage_inventories: The number of inventory objects without revisions
193
 
                             that were garbage collected.
 
202
 
 
203
        * `inconsistent_parents`: The number of revisions in the repository
 
204
          whose ancestry was being reported incorrectly.
 
205
        * `garbage_inventories`: The number of inventory objects without
 
206
          revisions that were garbage collected.
194
207
        """
195
208
        operation = cleanup.OperationWithCleanups(self._reconcile)
196
209
        self.add_cleanup = operation.add_cleanup
215
228
        only data-loss causing issues (!self.thorough) or all issues
216
229
        (self.thorough) are treated as requiring the reweave.
217
230
        """
218
 
        # local because needing to know about WeaveFile is a wart we want to hide
219
 
        from bzrlib.weave import WeaveFile, Weave
220
231
        transaction = self.repo.get_transaction()
221
 
        self.pb.update('Reading inventory data')
 
232
        self.pb.update(gettext('Reading inventory data'))
222
233
        self.inventory = self.repo.inventories
223
234
        self.revisions = self.repo.revisions
224
235
        # the total set of revisions to process
238
249
        # (no garbage inventories or we are not doing a thorough check)
239
250
        if (not self.inconsistent_parents and
240
251
            (not self.garbage_inventories or not self.thorough)):
241
 
            ui.ui_factory.note('Inventory ok.')
 
252
            ui.ui_factory.note(gettext('Inventory ok.'))
242
253
            return
243
 
        self.pb.update('Backing up inventory', 0, 0)
 
254
        self.pb.update(gettext('Backing up inventory'), 0, 0)
244
255
        self.repo._backup_inventory()
245
 
        ui.ui_factory.note('Backup inventory created.')
 
256
        ui.ui_factory.note(gettext('Backup inventory created.'))
246
257
        new_inventories = self.repo._temp_inventories()
247
258
 
248
259
        # we have topological order of revisions and non ghost parents ready.
258
269
        if not (set(new_inventories.keys()) ==
259
270
            set([(revid,) for revid in self.pending])):
260
271
            raise AssertionError()
261
 
        self.pb.update('Writing weave')
 
272
        self.pb.update(gettext('Writing weave'))
262
273
        self.repo._activate_new_inventory()
263
274
        self.inventory = None
264
 
        ui.ui_factory.note('Inventory regenerated.')
 
275
        ui.ui_factory.note(gettext('Inventory regenerated.'))
265
276
 
266
277
    def _new_inv_parents(self, revision_key):
267
278
        """Lookup ghost-filtered parents for revision_key."""
355
366
    def _load_indexes(self):
356
367
        """Load indexes for the reconciliation."""
357
368
        self.transaction = self.repo.get_transaction()
358
 
        self.pb.update('Reading indexes', 0, 2)
 
369
        self.pb.update(gettext('Reading indexes'), 0, 2)
359
370
        self.inventory = self.repo.inventories
360
 
        self.pb.update('Reading indexes', 1, 2)
 
371
        self.pb.update(gettext('Reading indexes'), 1, 2)
361
372
        self.repo._check_for_inconsistent_revision_parents()
362
373
        self.revisions = self.repo.revisions
363
 
        self.pb.update('Reading indexes', 2, 2)
 
374
        self.pb.update(gettext('Reading indexes'), 2, 2)
364
375
 
365
376
    def _gc_inventory(self):
366
377
        """Remove inventories that are not referenced from the revision store."""
367
 
        self.pb.update('Checking unused inventories', 0, 1)
 
378
        self.pb.update(gettext('Checking unused inventories'), 0, 1)
368
379
        self._check_garbage_inventories()
369
 
        self.pb.update('Checking unused inventories', 1, 3)
 
380
        self.pb.update(gettext('Checking unused inventories'), 1, 3)
370
381
        if not self.garbage_inventories:
371
 
            ui.ui_factory.note('Inventory ok.')
 
382
            ui.ui_factory.note(gettext('Inventory ok.'))
372
383
            return
373
 
        self.pb.update('Backing up inventory', 0, 0)
 
384
        self.pb.update(gettext('Backing up inventory'), 0, 0)
374
385
        self.repo._backup_inventory()
375
 
        ui.ui_factory.note('Backup Inventory created')
 
386
        ui.ui_factory.note(gettext('Backup Inventory created'))
376
387
        # asking for '' should never return a non-empty weave
377
388
        new_inventories = self.repo._temp_inventories()
378
389
        # we have topological order of revisions and non ghost parents ready.
389
400
        # the revisionds list
390
401
        if not(set(new_inventories.keys()) == set(revision_keys)):
391
402
            raise AssertionError()
392
 
        self.pb.update('Writing weave')
 
403
        self.pb.update(gettext('Writing weave'))
393
404
        self.repo._activate_new_inventory()
394
405
        self.inventory = None
395
 
        ui.ui_factory.note('Inventory regenerated.')
 
406
        ui.ui_factory.note(gettext('Inventory regenerated.'))
396
407
 
397
408
    def _fix_text_parents(self):
398
409
        """Fix bad versionedfile parent entries.
430
441
            versions_list.append(text_key[1])
431
442
        # Do the reconcile of individual weaves.
432
443
        for num, file_id in enumerate(per_id_bad_parents):
433
 
            self.pb.update('Fixing text parents', num,
 
444
            self.pb.update(gettext('Fixing text parents'), num,
434
445
                           len(per_id_bad_parents))
435
446
            versions_with_bad_parents = per_id_bad_parents[file_id]
436
447
            id_unused_versions = set(key[-1] for key in unused_versions
494
505
    #  - lock the names list
495
506
    #  - perform a customised pack() that regenerates data as needed
496
507
    #  - unlock the names list
497
 
    # https://bugs.edge.launchpad.net/bzr/+bug/154173
 
508
    # https://bugs.launchpad.net/bzr/+bug/154173
 
509
 
 
510
    def __init__(self, repo, other=None, thorough=False,
 
511
            canonicalize_chks=False):
 
512
        super(PackReconciler, self).__init__(repo, other=other,
 
513
            thorough=thorough)
 
514
        self.canonicalize_chks = canonicalize_chks
498
515
 
499
516
    def _reconcile_steps(self):
500
517
        """Perform the steps to reconcile this repository."""
509
526
        total_inventories = len(list(
510
527
            collection.inventory_index.combined_index.iter_all_entries()))
511
528
        if len(all_revisions):
512
 
            new_pack =  self.repo._reconcile_pack(collection, packs,
513
 
                ".reconcile", all_revisions, self.pb)
 
529
            if self.canonicalize_chks:
 
530
                reconcile_meth = self.repo._canonicalize_chks_pack
 
531
            else:
 
532
                reconcile_meth = self.repo._reconcile_pack
 
533
            new_pack = reconcile_meth(collection, packs, ".reconcile",
 
534
                all_revisions, self.pb)
514
535
            if new_pack is not None:
515
536
                self._discard_and_save(packs)
516
537
        else: