~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/reconcile.py

(jameinel) (bug #780544) when updating the WT,
 allow it to be done with a fast delta,
 rather than setting the state from scratch. (John A Meinel)

Show diffs side-by-side

added added

removed removed

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