/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: Martin Pool
  • Date: 2010-10-08 04:38:25 UTC
  • mfrom: (5462 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5478.
  • Revision ID: mbp@sourcefrog.net-20101008043825-b181r8bo5r3qwb6j
merge trunk

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
 
39
38
 
40
 
def reconcile(dir, other=None):
 
39
def reconcile(dir, canonicalize_chks=False):
41
40
    """Reconcile the data in dir.
42
41
 
43
42
    Currently this is limited to a inventory 'reweave'.
47
46
    Directly using Reconciler is recommended for library users that
48
47
    desire fine grained control or analysis of the found issues.
49
48
 
50
 
    :param other: another bzrdir to reconcile against.
 
49
    :param canonicalize_chks: Make sure CHKs are in canonical form.
51
50
    """
52
 
    reconciler = Reconciler(dir, other=other)
 
51
    reconciler = Reconciler(dir, canonicalize_chks=canonicalize_chks)
53
52
    reconciler.reconcile()
54
53
 
55
54
 
56
55
class Reconciler(object):
57
56
    """Reconcilers are used to reconcile existing data."""
58
57
 
59
 
    def __init__(self, dir, other=None):
 
58
    def __init__(self, dir, other=None, canonicalize_chks=False):
60
59
        """Create a Reconciler."""
61
60
        self.bzrdir = dir
 
61
        self.canonicalize_chks = canonicalize_chks
62
62
 
63
63
    def reconcile(self):
64
64
        """Perform reconciliation.
97
97
    def _reconcile_repository(self):
98
98
        self.repo = self.bzrdir.find_repository()
99
99
        ui.ui_factory.note('Reconciling repository %s' %
100
 
            self.repo.bzrdir.root_transport.base)
 
100
            self.repo.user_url)
101
101
        self.pb.update("Reconciling repository", 0, 1)
102
 
        repo_reconciler = self.repo.reconcile(thorough=True)
 
102
        if self.canonicalize_chks:
 
103
            try:
 
104
                self.repo.reconcile_canonicalize_chks
 
105
            except AttributeError:
 
106
                raise errors.BzrError(
 
107
                    "%s cannot canonicalize CHKs." % (self.repo,))
 
108
            repo_reconciler = self.repo.reconcile_canonicalize_chks()
 
109
        else:
 
110
            repo_reconciler = self.repo.reconcile(thorough=True)
103
111
        self.inconsistent_parents = repo_reconciler.inconsistent_parents
104
112
        self.garbage_inventories = repo_reconciler.garbage_inventories
105
113
        if repo_reconciler.aborted:
120
128
        self.branch = a_branch
121
129
 
122
130
    def reconcile(self):
 
131
        operation = cleanup.OperationWithCleanups(self._reconcile)
 
132
        self.add_cleanup = operation.add_cleanup
 
133
        operation.run_simple()
 
134
 
 
135
    def _reconcile(self):
123
136
        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()
 
137
        self.add_cleanup(self.branch.unlock)
 
138
        self.pb = ui.ui_factory.nested_progress_bar()
 
139
        self.add_cleanup(self.pb.finished)
 
140
        self._reconcile_steps()
132
141
 
133
142
    def _reconcile_steps(self):
134
143
        self._reconcile_revision_history()
192
201
        garbage_inventories: The number of inventory objects without revisions
193
202
                             that were garbage collected.
194
203
        """
 
204
        operation = cleanup.OperationWithCleanups(self._reconcile)
 
205
        self.add_cleanup = operation.add_cleanup
 
206
        operation.run_simple()
 
207
 
 
208
    def _reconcile(self):
195
209
        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()
 
210
        self.add_cleanup(self.repo.unlock)
 
211
        self.pb = ui.ui_factory.nested_progress_bar()
 
212
        self.add_cleanup(self.pb.finished)
 
213
        self._reconcile_steps()
204
214
 
205
215
    def _reconcile_steps(self):
206
216
        """Perform the steps to reconcile this repository."""
493
503
    #  - lock the names list
494
504
    #  - perform a customised pack() that regenerates data as needed
495
505
    #  - unlock the names list
496
 
    # https://bugs.edge.launchpad.net/bzr/+bug/154173
 
506
    # https://bugs.launchpad.net/bzr/+bug/154173
 
507
 
 
508
    def __init__(self, repo, other=None, thorough=False,
 
509
            canonicalize_chks=False):
 
510
        super(PackReconciler, self).__init__(repo, other=other,
 
511
            thorough=thorough)
 
512
        self.canonicalize_chks = canonicalize_chks
497
513
 
498
514
    def _reconcile_steps(self):
499
515
        """Perform the steps to reconcile this repository."""
502
518
        collection = self.repo._pack_collection
503
519
        collection.ensure_loaded()
504
520
        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)
 
521
        self.add_cleanup(collection._unlock_names)
 
522
        packs = collection.all_packs()
 
523
        all_revisions = self.repo.all_revision_ids()
 
524
        total_inventories = len(list(
 
525
            collection.inventory_index.combined_index.iter_all_entries()))
 
526
        if len(all_revisions):
 
527
            if self.canonicalize_chks:
 
528
                reconcile_meth = self.repo._canonicalize_chks_pack
515
529
            else:
516
 
                # only make a new pack when there is data to copy.
 
530
                reconcile_meth = self.repo._reconcile_pack
 
531
            new_pack = reconcile_meth(collection, packs, ".reconcile",
 
532
                all_revisions, self.pb)
 
533
            if new_pack is not None:
517
534
                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()
 
535
        else:
 
536
            # only make a new pack when there is data to copy.
 
537
            self._discard_and_save(packs)
 
538
        self.garbage_inventories = total_inventories - len(list(
 
539
            collection.inventory_index.combined_index.iter_all_entries()))
522
540
 
523
541
    def _discard_and_save(self, packs):
524
542
        """Discard some packs from the repository.