~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/reconcile.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-05-28 00:25:32 UTC
  • mfrom: (5264.1.2 command-help-bug-177500)
  • Revision ID: pqm@pqm.ubuntu.com-20100528002532-9bzj1fajyxckd1rg
(lifeless) Stop raising at runtime when a command has no help,
 instead have a test in the test suite that checks all known command objects.
 (Robert Collins)

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,
33
32
    ui,
34
33
    )
35
34
from bzrlib.trace import mutter
37
36
from bzrlib.versionedfile import AdapterFactory, FulltextContentFactory
38
37
 
39
38
 
40
 
def reconcile(dir, canonicalize_chks=False):
 
39
def reconcile(dir, other=None):
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 canonicalize_chks: Make sure CHKs are in canonical form.
 
49
    :param other: another bzrdir to reconcile against.
51
50
    """
52
 
    reconciler = Reconciler(dir, canonicalize_chks=canonicalize_chks)
 
51
    reconciler = Reconciler(dir, other=other)
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, canonicalize_chks=False):
 
58
    def __init__(self, dir, other=None):
60
59
        """Create a Reconciler."""
61
60
        self.bzrdir = dir
62
 
        self.canonicalize_chks = canonicalize_chks
63
61
 
64
62
    def reconcile(self):
65
63
        """Perform reconciliation.
66
64
 
67
65
        After reconciliation the following attributes document found issues:
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.
 
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.
76
73
        """
77
74
        self.pb = ui.ui_factory.nested_progress_bar()
78
75
        try:
101
98
        ui.ui_factory.note('Reconciling repository %s' %
102
99
            self.repo.user_url)
103
100
        self.pb.update("Reconciling repository", 0, 1)
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)
 
101
        repo_reconciler = self.repo.reconcile(thorough=True)
113
102
        self.inconsistent_parents = repo_reconciler.inconsistent_parents
114
103
        self.garbage_inventories = repo_reconciler.garbage_inventories
115
104
        if repo_reconciler.aborted:
145
134
        self._reconcile_revision_history()
146
135
 
147
136
    def _reconcile_revision_history(self):
 
137
        repo = self.branch.repository
148
138
        last_revno, last_revision_id = self.branch.last_revision_info()
149
139
        real_history = []
150
 
        graph = self.branch.repository.get_graph()
151
140
        try:
152
 
            for revid in graph.iter_lefthand_ancestry(
153
 
                    last_revision_id, (_mod_revision.NULL_REVISION,)):
 
141
            for revid in repo.iter_reverse_revision_history(
 
142
                    last_revision_id):
154
143
                real_history.append(revid)
155
144
        except errors.RevisionNotPresent:
156
145
            pass # Hit a ghost left hand parent
198
187
        """Perform reconciliation.
199
188
 
200
189
        After reconciliation the following attributes document found issues:
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.
 
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.
206
194
        """
207
195
        operation = cleanup.OperationWithCleanups(self._reconcile)
208
196
        self.add_cleanup = operation.add_cleanup
227
215
        only data-loss causing issues (!self.thorough) or all issues
228
216
        (self.thorough) are treated as requiring the reweave.
229
217
        """
 
218
        # local because needing to know about WeaveFile is a wart we want to hide
 
219
        from bzrlib.weave import WeaveFile, Weave
230
220
        transaction = self.repo.get_transaction()
231
221
        self.pb.update('Reading inventory data')
232
222
        self.inventory = self.repo.inventories
506
496
    #  - unlock the names list
507
497
    # https://bugs.launchpad.net/bzr/+bug/154173
508
498
 
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
514
 
 
515
499
    def _reconcile_steps(self):
516
500
        """Perform the steps to reconcile this repository."""
517
501
        if not self.thorough:
525
509
        total_inventories = len(list(
526
510
            collection.inventory_index.combined_index.iter_all_entries()))
527
511
        if len(all_revisions):
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)
 
512
            new_pack =  self.repo._reconcile_pack(collection, packs,
 
513
                ".reconcile", all_revisions, self.pb)
534
514
            if new_pack is not None:
535
515
                self._discard_and_save(packs)
536
516
        else: