/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: John Arbash Meinel
  • Date: 2010-01-06 17:46:15 UTC
  • mto: (4634.119.1 2.0)
  • mto: This revision was merged to the branch mainline in revision 4951.
  • Revision ID: john@arbash-meinel.com-20100106174615-cq1nckxhbuyemgjx
Fix bug #503886, errors setting up logging go to stderr.

The basic issue is that we were using logging to describe failures
to set up logging. However, those fail with bad error messages
rather than giving us the output we want. This was especially bad
when the failure was occuring on the server. Since 'ssh' will pass
back the stderr stream without bzr handling it at all.

Show diffs side-by-side

added added

removed removed

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