~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/reconcile.py

  • Committer: INADA Naoki
  • Date: 2010-03-03 12:14:16 UTC
  • mfrom: (4634.171.4 fix-523746-2)
  • mto: This revision was merged to the branch mainline in revision 5892.
  • Revision ID: inada-n@klab.jp-20100303121416-uemvz4l5y1ilclv6
merge #523746 fix from lp:~songofacandy/bzr/fix-523746-2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2006-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
27
27
 
28
28
 
29
29
from bzrlib import (
 
30
    cleanup,
30
31
    errors,
31
32
    ui,
32
33
    repository,
33
 
    repofmt,
34
34
    )
35
 
from bzrlib.trace import mutter, note
 
35
from bzrlib.trace import mutter
36
36
from bzrlib.tsort import topo_sort
37
37
from bzrlib.versionedfile import AdapterFactory, FulltextContentFactory
38
38
 
90
90
            # Nothing to check here
91
91
            self.fixed_branch_history = None
92
92
            return
93
 
        self.pb.note('Reconciling branch %s',
94
 
                     self.branch.base)
 
93
        ui.ui_factory.note('Reconciling branch %s' % self.branch.base)
95
94
        branch_reconciler = self.branch.reconcile(thorough=True)
96
95
        self.fixed_branch_history = branch_reconciler.fixed_history
97
96
 
98
97
    def _reconcile_repository(self):
99
98
        self.repo = self.bzrdir.find_repository()
100
 
        self.pb.note('Reconciling repository %s',
101
 
                     self.repo.bzrdir.root_transport.base)
 
99
        ui.ui_factory.note('Reconciling repository %s' %
 
100
            self.repo.bzrdir.root_transport.base)
102
101
        self.pb.update("Reconciling repository", 0, 1)
103
102
        repo_reconciler = self.repo.reconcile(thorough=True)
104
103
        self.inconsistent_parents = repo_reconciler.inconsistent_parents
105
104
        self.garbage_inventories = repo_reconciler.garbage_inventories
106
105
        if repo_reconciler.aborted:
107
 
            self.pb.note(
 
106
            ui.ui_factory.note(
108
107
                'Reconcile aborted: revision index has inconsistent parents.')
109
 
            self.pb.note(
 
108
            ui.ui_factory.note(
110
109
                'Run "bzr check" for more details.')
111
110
        else:
112
 
            self.pb.note('Reconciliation complete.')
 
111
            ui.ui_factory.note('Reconciliation complete.')
113
112
 
114
113
 
115
114
class BranchReconciler(object):
121
120
        self.branch = a_branch
122
121
 
123
122
    def reconcile(self):
 
123
        operation = cleanup.OperationWithCleanups(self._reconcile)
 
124
        self.add_cleanup = operation.add_cleanup
 
125
        operation.run_simple()
 
126
 
 
127
    def _reconcile(self):
124
128
        self.branch.lock_write()
125
 
        try:
126
 
            self.pb = ui.ui_factory.nested_progress_bar()
127
 
            try:
128
 
                self._reconcile_steps()
129
 
            finally:
130
 
                self.pb.finished()
131
 
        finally:
132
 
            self.branch.unlock()
 
129
        self.add_cleanup(self.branch.unlock)
 
130
        self.pb = ui.ui_factory.nested_progress_bar()
 
131
        self.add_cleanup(self.pb.finished)
 
132
        self._reconcile_steps()
133
133
 
134
134
    def _reconcile_steps(self):
135
135
        self._reconcile_revision_history()
151
151
            # set_revision_history, as this will regenerate it again.
152
152
            # Not really worth a whole BranchReconciler class just for this,
153
153
            # though.
154
 
            self.pb.note('Fixing last revision info %s => %s',
155
 
                         last_revno, len(real_history))
 
154
            ui.ui_factory.note('Fixing last revision info %s => %s' % (
 
155
                 last_revno, len(real_history)))
156
156
            self.branch.set_last_revision_info(len(real_history),
157
157
                                               last_revision_id)
158
158
        else:
159
159
            self.fixed_history = False
160
 
            self.pb.note('revision_history ok.')
 
160
            ui.ui_factory.note('revision_history ok.')
161
161
 
162
162
 
163
163
class RepoReconciler(object):
193
193
        garbage_inventories: The number of inventory objects without revisions
194
194
                             that were garbage collected.
195
195
        """
 
196
        operation = cleanup.OperationWithCleanups(self._reconcile)
 
197
        self.add_cleanup = operation.add_cleanup
 
198
        operation.run_simple()
 
199
 
 
200
    def _reconcile(self):
196
201
        self.repo.lock_write()
197
 
        try:
198
 
            self.pb = ui.ui_factory.nested_progress_bar()
199
 
            try:
200
 
                self._reconcile_steps()
201
 
            finally:
202
 
                self.pb.finished()
203
 
        finally:
204
 
            self.repo.unlock()
 
202
        self.add_cleanup(self.repo.unlock)
 
203
        self.pb = ui.ui_factory.nested_progress_bar()
 
204
        self.add_cleanup(self.pb.finished)
 
205
        self._reconcile_steps()
205
206
 
206
207
    def _reconcile_steps(self):
207
208
        """Perform the steps to reconcile this repository."""
238
239
        # (no garbage inventories or we are not doing a thorough check)
239
240
        if (not self.inconsistent_parents and
240
241
            (not self.garbage_inventories or not self.thorough)):
241
 
            self.pb.note('Inventory ok.')
 
242
            ui.ui_factory.note('Inventory ok.')
242
243
            return
243
244
        self.pb.update('Backing up inventory', 0, 0)
244
245
        self.repo._backup_inventory()
245
 
        self.pb.note('Backup inventory created.')
 
246
        ui.ui_factory.note('Backup inventory created.')
246
247
        new_inventories = self.repo._temp_inventories()
247
248
 
248
249
        # we have topological order of revisions and non ghost parents ready.
261
262
        self.pb.update('Writing weave')
262
263
        self.repo._activate_new_inventory()
263
264
        self.inventory = None
264
 
        self.pb.note('Inventory regenerated.')
 
265
        ui.ui_factory.note('Inventory regenerated.')
265
266
 
266
267
    def _new_inv_parents(self, revision_key):
267
268
        """Lookup ghost-filtered parents for revision_key."""
368
369
        self._check_garbage_inventories()
369
370
        self.pb.update('Checking unused inventories', 1, 3)
370
371
        if not self.garbage_inventories:
371
 
            self.pb.note('Inventory ok.')
 
372
            ui.ui_factory.note('Inventory ok.')
372
373
            return
373
374
        self.pb.update('Backing up inventory', 0, 0)
374
375
        self.repo._backup_inventory()
375
 
        self.pb.note('Backup Inventory created')
 
376
        ui.ui_factory.note('Backup Inventory created')
376
377
        # asking for '' should never return a non-empty weave
377
378
        new_inventories = self.repo._temp_inventories()
378
379
        # we have topological order of revisions and non ghost parents ready.
392
393
        self.pb.update('Writing weave')
393
394
        self.repo._activate_new_inventory()
394
395
        self.inventory = None
395
 
        self.pb.note('Inventory regenerated.')
 
396
        ui.ui_factory.note('Inventory regenerated.')
396
397
 
397
398
    def _fix_text_parents(self):
398
399
        """Fix bad versionedfile parent entries.
503
504
        collection = self.repo._pack_collection
504
505
        collection.ensure_loaded()
505
506
        collection.lock_names()
506
 
        try:
507
 
            packs = collection.all_packs()
508
 
            all_revisions = self.repo.all_revision_ids()
509
 
            total_inventories = len(list(
510
 
                collection.inventory_index.combined_index.iter_all_entries()))
511
 
            if len(all_revisions):
512
 
                new_pack =  self.repo._reconcile_pack(collection, packs,
513
 
                    ".reconcile", all_revisions, self.pb)
514
 
                if new_pack is not None:
515
 
                    self._discard_and_save(packs)
516
 
            else:
517
 
                # only make a new pack when there is data to copy.
 
507
        self.add_cleanup(collection._unlock_names)
 
508
        packs = collection.all_packs()
 
509
        all_revisions = self.repo.all_revision_ids()
 
510
        total_inventories = len(list(
 
511
            collection.inventory_index.combined_index.iter_all_entries()))
 
512
        if len(all_revisions):
 
513
            new_pack =  self.repo._reconcile_pack(collection, packs,
 
514
                ".reconcile", all_revisions, self.pb)
 
515
            if new_pack is not None:
518
516
                self._discard_and_save(packs)
519
 
            self.garbage_inventories = total_inventories - len(list(
520
 
                collection.inventory_index.combined_index.iter_all_entries()))
521
 
        finally:
522
 
            collection._unlock_names()
 
517
        else:
 
518
            # only make a new pack when there is data to copy.
 
519
            self._discard_and_save(packs)
 
520
        self.garbage_inventories = total_inventories - len(list(
 
521
            collection.inventory_index.combined_index.iter_all_entries()))
523
522
 
524
523
    def _discard_and_save(self, packs):
525
524
        """Discard some packs from the repository.