/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: Robert Collins
  • Date: 2010-05-06 11:08:10 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506110810-h3j07fh5gmw54s25
Cleaner matcher matching revised unlocking protocol.

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
 
    repository,
33
 
    repofmt,
34
33
    )
35
 
from bzrlib.trace import mutter, note
 
34
from bzrlib.trace import mutter
36
35
from bzrlib.tsort import topo_sort
37
36
from bzrlib.versionedfile import AdapterFactory, FulltextContentFactory
38
37
 
97
96
    def _reconcile_repository(self):
98
97
        self.repo = self.bzrdir.find_repository()
99
98
        ui.ui_factory.note('Reconciling repository %s' %
100
 
            self.repo.bzrdir.root_transport.base)
 
99
            self.repo.user_url)
101
100
        self.pb.update("Reconciling repository", 0, 1)
102
101
        repo_reconciler = self.repo.reconcile(thorough=True)
103
102
        self.inconsistent_parents = repo_reconciler.inconsistent_parents
120
119
        self.branch = a_branch
121
120
 
122
121
    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):
123
127
        self.branch.lock_write()
124
 
        try:
125
 
            self.pb = ui.ui_factory.nested_progress_bar()
126
 
            try:
127
 
                self._reconcile_steps()
128
 
            finally:
129
 
                self.pb.finished()
130
 
        finally:
131
 
            self.branch.unlock()
 
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()
132
132
 
133
133
    def _reconcile_steps(self):
134
134
        self._reconcile_revision_history()
192
192
        garbage_inventories: The number of inventory objects without revisions
193
193
                             that were garbage collected.
194
194
        """
 
195
        operation = cleanup.OperationWithCleanups(self._reconcile)
 
196
        self.add_cleanup = operation.add_cleanup
 
197
        operation.run_simple()
 
198
 
 
199
    def _reconcile(self):
195
200
        self.repo.lock_write()
196
 
        try:
197
 
            self.pb = ui.ui_factory.nested_progress_bar()
198
 
            try:
199
 
                self._reconcile_steps()
200
 
            finally:
201
 
                self.pb.finished()
202
 
        finally:
203
 
            self.repo.unlock()
 
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()
204
205
 
205
206
    def _reconcile_steps(self):
206
207
        """Perform the steps to reconcile this repository."""
502
503
        collection = self.repo._pack_collection
503
504
        collection.ensure_loaded()
504
505
        collection.lock_names()
505
 
        try:
506
 
            packs = collection.all_packs()
507
 
            all_revisions = self.repo.all_revision_ids()
508
 
            total_inventories = len(list(
509
 
                collection.inventory_index.combined_index.iter_all_entries()))
510
 
            if len(all_revisions):
511
 
                new_pack =  self.repo._reconcile_pack(collection, packs,
512
 
                    ".reconcile", all_revisions, self.pb)
513
 
                if new_pack is not None:
514
 
                    self._discard_and_save(packs)
515
 
            else:
516
 
                # only make a new pack when there is data to copy.
 
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:
517
515
                self._discard_and_save(packs)
518
 
            self.garbage_inventories = total_inventories - len(list(
519
 
                collection.inventory_index.combined_index.iter_all_entries()))
520
 
        finally:
521
 
            collection._unlock_names()
 
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()))
522
521
 
523
522
    def _discard_and_save(self, packs):
524
523
        """Discard some packs from the repository.