~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/reconcile.py

  • Committer: Martin von Gagern
  • Date: 2011-09-19 08:49:15 UTC
  • mto: This revision was merged to the branch mainline in revision 6148.
  • Revision ID: martin.vgagern@gmx.net-20110919084915-vbumflqq3xqm1vez
Avoid using deprecated api in the unit tests for bzrlib.missing.

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
36
37
from bzrlib.versionedfile import AdapterFactory, FulltextContentFactory
37
38
 
38
39
 
39
 
def reconcile(dir, other=None):
 
40
def reconcile(dir, canonicalize_chks=False):
40
41
    """Reconcile the data in dir.
41
42
 
42
43
    Currently this is limited to a inventory 'reweave'.
46
47
    Directly using Reconciler is recommended for library users that
47
48
    desire fine grained control or analysis of the found issues.
48
49
 
49
 
    :param other: another bzrdir to reconcile against.
 
50
    :param canonicalize_chks: Make sure CHKs are in canonical form.
50
51
    """
51
 
    reconciler = Reconciler(dir, other=other)
 
52
    reconciler = Reconciler(dir, canonicalize_chks=canonicalize_chks)
52
53
    reconciler.reconcile()
53
54
 
54
55
 
55
56
class Reconciler(object):
56
57
    """Reconcilers are used to reconcile existing data."""
57
58
 
58
 
    def __init__(self, dir, other=None):
 
59
    def __init__(self, dir, other=None, canonicalize_chks=False):
59
60
        """Create a Reconciler."""
60
61
        self.bzrdir = dir
 
62
        self.canonicalize_chks = canonicalize_chks
61
63
 
62
64
    def reconcile(self):
63
65
        """Perform reconciliation.
64
66
 
65
67
        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.
 
68
 
 
69
        * `inconsistent_parents`: The number of revisions in the repository
 
70
          whose ancestry was being reported incorrectly.
 
71
        * `garbage_inventories`: The number of inventory objects without
 
72
          revisions that were garbage collected.
 
73
        * `fixed_branch_history`: None if there was no branch, False if the
 
74
          branch history was correct, True if the branch history needed to be
 
75
          re-normalized.
73
76
        """
74
77
        self.pb = ui.ui_factory.nested_progress_bar()
75
78
        try:
98
101
        ui.ui_factory.note('Reconciling repository %s' %
99
102
            self.repo.user_url)
100
103
        self.pb.update("Reconciling repository", 0, 1)
101
 
        repo_reconciler = self.repo.reconcile(thorough=True)
 
104
        if self.canonicalize_chks:
 
105
            try:
 
106
                self.repo.reconcile_canonicalize_chks
 
107
            except AttributeError:
 
108
                raise errors.BzrError(
 
109
                    "%s cannot canonicalize CHKs." % (self.repo,))
 
110
            repo_reconciler = self.repo.reconcile_canonicalize_chks()
 
111
        else:
 
112
            repo_reconciler = self.repo.reconcile(thorough=True)
102
113
        self.inconsistent_parents = repo_reconciler.inconsistent_parents
103
114
        self.garbage_inventories = repo_reconciler.garbage_inventories
104
115
        if repo_reconciler.aborted:
134
145
        self._reconcile_revision_history()
135
146
 
136
147
    def _reconcile_revision_history(self):
137
 
        repo = self.branch.repository
138
148
        last_revno, last_revision_id = self.branch.last_revision_info()
139
149
        real_history = []
 
150
        graph = self.branch.repository.get_graph()
140
151
        try:
141
 
            for revid in repo.iter_reverse_revision_history(
142
 
                    last_revision_id):
 
152
            for revid in graph.iter_lefthand_ancestry(
 
153
                    last_revision_id, (_mod_revision.NULL_REVISION,)):
143
154
                real_history.append(revid)
144
155
        except errors.RevisionNotPresent:
145
156
            pass # Hit a ghost left hand parent
187
198
        """Perform reconciliation.
188
199
 
189
200
        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.
 
201
 
 
202
        * `inconsistent_parents`: The number of revisions in the repository
 
203
          whose ancestry was being reported incorrectly.
 
204
        * `garbage_inventories`: The number of inventory objects without
 
205
          revisions that were garbage collected.
194
206
        """
195
207
        operation = cleanup.OperationWithCleanups(self._reconcile)
196
208
        self.add_cleanup = operation.add_cleanup
215
227
        only data-loss causing issues (!self.thorough) or all issues
216
228
        (self.thorough) are treated as requiring the reweave.
217
229
        """
218
 
        # local because needing to know about WeaveFile is a wart we want to hide
219
 
        from bzrlib.weave import WeaveFile, Weave
220
230
        transaction = self.repo.get_transaction()
221
231
        self.pb.update('Reading inventory data')
222
232
        self.inventory = self.repo.inventories
494
504
    #  - lock the names list
495
505
    #  - perform a customised pack() that regenerates data as needed
496
506
    #  - unlock the names list
497
 
    # https://bugs.edge.launchpad.net/bzr/+bug/154173
 
507
    # https://bugs.launchpad.net/bzr/+bug/154173
 
508
 
 
509
    def __init__(self, repo, other=None, thorough=False,
 
510
            canonicalize_chks=False):
 
511
        super(PackReconciler, self).__init__(repo, other=other,
 
512
            thorough=thorough)
 
513
        self.canonicalize_chks = canonicalize_chks
498
514
 
499
515
    def _reconcile_steps(self):
500
516
        """Perform the steps to reconcile this repository."""
509
525
        total_inventories = len(list(
510
526
            collection.inventory_index.combined_index.iter_all_entries()))
511
527
        if len(all_revisions):
512
 
            new_pack =  self.repo._reconcile_pack(collection, packs,
513
 
                ".reconcile", all_revisions, self.pb)
 
528
            if self.canonicalize_chks:
 
529
                reconcile_meth = self.repo._canonicalize_chks_pack
 
530
            else:
 
531
                reconcile_meth = self.repo._reconcile_pack
 
532
            new_pack = reconcile_meth(collection, packs, ".reconcile",
 
533
                all_revisions, self.pb)
514
534
            if new_pack is not None:
515
535
                self._discard_and_save(packs)
516
536
        else: