~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/check.py

  • Committer: John Arbash Meinel
  • Date: 2006-08-23 22:18:16 UTC
  • mto: This revision was merged to the branch mainline in revision 1955.
  • Revision ID: john@arbash-meinel.com-20060823221816-832d30e909734e97
Rename test_aftp_transport to test_ftp_tranpsport

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.unreferenced_versions = set()
60
 
        self.inconsistent_parents = []
61
56
 
62
57
    def check(self):
63
58
        self.repository.lock_read()
64
59
        self.progress = bzrlib.ui.ui_factory.nested_progress_bar()
65
60
        try:
66
 
            self.progress.update('retrieving inventory', 0, 2)
 
61
            self.progress.update('retrieving inventory', 0, 0)
67
62
            # do not put in init, as it should be done with progess,
68
63
            # and inside the lock.
69
64
            self.inventory_weave = self.repository.get_inventory_weave()
70
 
            self.progress.update('checking revision graph', 1)
71
 
            self.check_revision_graph()
72
65
            self.plan_revisions()
73
66
            revno = 0
 
67
            self.check_weaves()
74
68
            while revno < len(self.planned_revisions):
75
69
                rev_id = self.planned_revisions[revno]
76
70
                self.progress.update('checking revision', revno,
77
71
                                     len(self.planned_revisions))
78
72
                revno += 1
79
73
                self.check_one_rev(rev_id)
80
 
            # check_weaves is done after the revision scan so that
81
 
            # revision index is known to be valid.
82
 
            self.check_weaves()
83
74
        finally:
84
75
            self.progress.finished()
85
76
            self.repository.unlock()
86
77
 
87
 
    def check_revision_graph(self):
88
 
        if not self.repository.revision_graph_can_have_wrong_parents():
89
 
            # This check is not necessary.
90
 
            self.revs_with_bad_parents_in_index = None
91
 
            return
92
 
        bad_revisions = self.repository._find_inconsistent_revision_parents()
93
 
        self.revs_with_bad_parents_in_index = list(bad_revisions)
94
 
 
95
78
    def plan_revisions(self):
96
79
        repository = self.repository
97
 
        self.planned_revisions = repository.all_revision_ids()
 
80
        self.planned_revisions = set(repository.all_revision_ids())
98
81
        self.progress.clear()
99
82
        inventoried = set(self.inventory_weave.versions())
100
 
        awol = set(self.planned_revisions) - inventoried
 
83
        awol = self.planned_revisions - inventoried
101
84
        if len(awol) > 0:
102
85
            raise BzrCheckError('Stored revisions missing from inventory'
103
86
                '{%s}' % ','.join([f for f in awol]))
 
87
        self.planned_revisions = list(self.planned_revisions)
104
88
 
105
89
    def report_results(self, verbose):
106
90
        note('checked repository %s format %s',
107
91
             self.repository.bzrdir.root_transport,
108
92
             self.repository._format)
109
93
        note('%6d revisions', self.checked_rev_cnt)
110
 
        note('%6d file-ids', len(self.checked_weaves))
111
94
        note('%6d unique file texts', self.checked_text_cnt)
112
95
        note('%6d repeated file texts', self.repeated_text_cnt)
113
 
        note('%6d unreferenced text versions',
114
 
             len(self.unreferenced_versions))
 
96
        note('%6d weaves', len(self.checked_weaves))
115
97
        if self.missing_inventory_sha_cnt:
116
98
            note('%6d revisions are missing inventory_sha1',
117
99
                 self.missing_inventory_sha_cnt)
131
113
                    note('      %s should be in the ancestry for:', link)
132
114
                    for linker in linkers:
133
115
                        note('       * %s', linker)
134
 
            if verbose:
135
 
                for file_id, revision_id in self.unreferenced_versions:
136
 
                    log_error('unreferenced version: {%s} in %s', revision_id,
137
 
                        file_id)
138
 
        if len(self.inconsistent_parents):
139
 
            note('%6d inconsistent parents', len(self.inconsistent_parents))
140
 
            if verbose:
141
 
                for info in self.inconsistent_parents:
142
 
                    revision_id, file_id, found_parents, correct_parents = info
143
 
                    note('      * %s version %s has parents %r '
144
 
                         'but should have %r'
145
 
                         % (file_id, revision_id, found_parents,
146
 
                             correct_parents))
147
 
        if self.revs_with_bad_parents_in_index:
148
 
            note('%6d revisions have incorrect parents in the revision index',
149
 
                 len(self.revs_with_bad_parents_in_index))
150
 
            if verbose:
151
 
                for item in self.revs_with_bad_parents_in_index:
152
 
                    revision_id, index_parents, actual_parents = item
153
 
                    note(
154
 
                        '       %s has wrong parents in index: '
155
 
                        '%r should be %r',
156
 
                        revision_id, index_parents, actual_parents)
157
116
 
158
117
    def check_one_rev(self, rev_id):
159
118
        """Check one revision.
197
156
        weave_ids = []
198
157
        if self.repository.weave_store.listable():
199
158
            weave_ids = list(self.repository.weave_store)
200
 
            n_weaves = len(weave_ids) + 1
201
 
        self.progress.update('checking versionedfile', 0, n_weaves)
 
159
            n_weaves = len(weave_ids)
 
160
        self.progress.update('checking weave', 0, n_weaves)
202
161
        self.inventory_weave.check(progress_bar=self.progress)
203
 
        files_in_revisions = {}
204
 
        revisions_of_files = {}
205
 
        weave_checker = self.repository._get_versioned_file_checker()
206
162
        for i, weave_id in enumerate(weave_ids):
207
 
            self.progress.update('checking versionedfile', i, n_weaves)
 
163
            self.progress.update('checking weave', i, n_weaves)
208
164
            w = self.repository.weave_store.get_weave(weave_id,
209
165
                    self.repository.get_transaction())
210
166
            # No progress here, because it looks ugly.
211
167
            w.check()
212
 
            result = weave_checker.check_file_version_parents(w, weave_id)
213
 
            bad_parents, unused_versions = result
214
 
            bad_parents = bad_parents.items()
215
 
            for revision_id, (weave_parents, correct_parents) in bad_parents:
216
 
                self.inconsistent_parents.append(
217
 
                    (revision_id, weave_id, weave_parents, correct_parents))
218
 
            for revision_id in unused_versions:
219
 
                self.unreferenced_versions.add((weave_id, revision_id))
220
168
            self.checked_weaves[weave_id] = True
221
169
 
222
170
    def _check_revision_tree(self, rev_id):
256
204
        branch.unlock()
257
205
    branch_result.report_results(verbose)
258
206
    repo_result.report_results(verbose)
259
 
 
260
 
 
261