~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/check.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-08-17 07:52:09 UTC
  • mfrom: (1910.3.4 trivial)
  • Revision ID: pqm@pqm.ubuntu.com-20060817075209-e85a1f9e05ff8b87
(andrew) Trivial fixes to NotImplemented errors.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 by 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
32
32
# raising them.  If there's more than one exception it'd be good to see them
33
33
# all.
34
34
 
35
 
from bzrlib import errors
36
 
from bzrlib import repository as _mod_repository
37
 
from bzrlib import revision
38
35
from bzrlib.errors import BzrCheckError
39
36
import bzrlib.ui
40
 
from bzrlib.trace import log_error, note
 
37
from bzrlib.trace import note
41
38
 
42
39
class Check(object):
43
40
    """Check a repository"""
56
53
        # maps (file-id, version) -> sha1; used by InventoryFile._check
57
54
        self.checked_texts = {}
58
55
        self.checked_weaves = {}
59
 
        self.revision_versions = _mod_repository._RevisionTextVersionCache(
60
 
            self.repository)
61
 
        self.unreferenced_ancestors = set()
62
 
        self.inconsistent_parents = []
63
56
 
64
57
    def check(self):
65
58
        self.repository.lock_read()
66
59
        self.progress = bzrlib.ui.ui_factory.nested_progress_bar()
67
60
        try:
68
 
            self.progress.update('retrieving inventory', 0, 2)
 
61
            self.progress.update('retrieving inventory', 0, 0)
69
62
            # do not put in init, as it should be done with progess,
70
63
            # and inside the lock.
71
64
            self.inventory_weave = self.repository.get_inventory_weave()
72
 
            self.progress.update('checking revision graph', 1)
73
 
            self.check_revision_graph()
74
65
            self.plan_revisions()
75
66
            revno = 0
 
67
            self.check_weaves()
76
68
            while revno < len(self.planned_revisions):
77
69
                rev_id = self.planned_revisions[revno]
78
70
                self.progress.update('checking revision', revno,
79
71
                                     len(self.planned_revisions))
80
72
                revno += 1
81
73
                self.check_one_rev(rev_id)
82
 
            # check_weaves is done after the revision scan so that
83
 
            # revision_versions is pre-populated
84
 
            self.check_weaves()
85
74
        finally:
86
75
            self.progress.finished()
87
76
            self.repository.unlock()
88
77
 
89
 
    def check_revision_graph(self):
90
 
        if not self.repository.revision_graph_can_have_wrong_parents():
91
 
            # This check is not necessary.
92
 
            self.revs_with_bad_parents_in_index = None
93
 
            return
94
 
        bad_revisions = self.repository._find_inconsistent_revision_parents()
95
 
        self.revs_with_bad_parents_in_index = list(bad_revisions)
96
 
 
97
78
    def plan_revisions(self):
98
79
        repository = self.repository
99
 
        self.planned_revisions = repository.all_revision_ids()
 
80
        self.planned_revisions = set(repository.all_revision_ids())
100
81
        self.progress.clear()
101
82
        inventoried = set(self.inventory_weave.versions())
102
 
        awol = set(self.planned_revisions) - inventoried
 
83
        awol = self.planned_revisions - inventoried
103
84
        if len(awol) > 0:
104
85
            raise BzrCheckError('Stored revisions missing from inventory'
105
86
                '{%s}' % ','.join([f for f in awol]))
 
87
        self.planned_revisions = list(self.planned_revisions)
106
88
 
107
89
    def report_results(self, verbose):
108
90
        note('checked repository %s format %s',
109
91
             self.repository.bzrdir.root_transport,
110
92
             self.repository._format)
111
93
        note('%6d revisions', self.checked_rev_cnt)
112
 
        note('%6d file-ids', len(self.checked_weaves))
113
94
        note('%6d unique file texts', self.checked_text_cnt)
114
95
        note('%6d repeated file texts', self.repeated_text_cnt)
115
 
        note('%6d unreferenced text ancestors',
116
 
             len(self.unreferenced_ancestors))
 
96
        note('%6d weaves', len(self.checked_weaves))
117
97
        if self.missing_inventory_sha_cnt:
118
98
            note('%6d revisions are missing inventory_sha1',
119
99
                 self.missing_inventory_sha_cnt)
133
113
                    note('      %s should be in the ancestry for:', link)
134
114
                    for linker in linkers:
135
115
                        note('       * %s', linker)
136
 
            if verbose:
137
 
                for file_id, revision_id in self.unreferenced_ancestors:
138
 
                    log_error('unreferenced ancestor: {%s} in %s', revision_id,
139
 
                        file_id)
140
 
        if len(self.inconsistent_parents):
141
 
            note('%6d inconsistent parents', len(self.inconsistent_parents))
142
 
            if verbose:
143
 
                for info in self.inconsistent_parents:
144
 
                    revision_id, file_id, found_parents, correct_parents = info
145
 
                    note('      * %s version %s has parents %r '
146
 
                         'but should have %r'
147
 
                         % (file_id, revision_id, found_parents,
148
 
                             correct_parents))
149
 
        if self.revs_with_bad_parents_in_index:
150
 
            note('%6d revisions have incorrect parents in the revision index',
151
 
                 len(self.revs_with_bad_parents_in_index))
152
 
            if verbose:
153
 
                for item in self.revs_with_bad_parents_in_index:
154
 
                    revision_id, index_parents, actual_parents = item
155
 
                    note(
156
 
                        '       %s has wrong parents in index: '
157
 
                        '%r should be %r',
158
 
                        revision_id, index_parents, actual_parents)
159
116
 
160
117
    def check_one_rev(self, rev_id):
161
118
        """Check one revision.
199
156
        weave_ids = []
200
157
        if self.repository.weave_store.listable():
201
158
            weave_ids = list(self.repository.weave_store)
202
 
            n_weaves = len(weave_ids) + 1
203
 
        self.progress.update('checking versionedfile', 0, n_weaves)
 
159
            n_weaves = len(weave_ids)
 
160
        self.progress.update('checking weave', 0, n_weaves)
204
161
        self.inventory_weave.check(progress_bar=self.progress)
205
 
        files_in_revisions = {}
206
 
        revisions_of_files = {}
207
162
        for i, weave_id in enumerate(weave_ids):
208
 
            self.progress.update('checking versionedfile', i, n_weaves)
 
163
            self.progress.update('checking weave', i, n_weaves)
209
164
            w = self.repository.weave_store.get_weave(weave_id,
210
165
                    self.repository.get_transaction())
211
166
            # No progress here, because it looks ugly.
212
167
            w.check()
213
 
 
214
 
            weave_checker = self.repository.get_versioned_file_checker(
215
 
                self.planned_revisions, self.revision_versions)
216
 
            result = weave_checker.check_file_version_parents(w, weave_id)
217
 
 
218
 
            for revision_id, (weave_parents,correct_parents) in result.items():
219
 
                self.inconsistent_parents.append(
220
 
                    (revision_id, weave_id, weave_parents, correct_parents))
221
 
                unreferenced_parents = set(weave_parents)-set(correct_parents)
222
 
                for unreferenced_parent in unreferenced_parents:
223
 
                    self.unreferenced_ancestors.add(
224
 
                        (weave_id, unreferenced_parent))
225
168
            self.checked_weaves[weave_id] = True
226
169
 
227
170
    def _check_revision_tree(self, rev_id):
228
171
        tree = self.repository.revision_tree(rev_id)
229
 
        self.revision_versions.add_revision_text_versions(tree)
230
172
        inv = tree.inventory
231
173
        seen_ids = {}
232
174
        for file_id in inv:
262
204
        branch.unlock()
263
205
    branch_result.report_results(verbose)
264
206
    repo_result.report_results(verbose)
265
 
 
266
 
 
267