~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/check.py

Merge from integration

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
from bzrlib.trace import mutter
35
35
from bzrlib.errors import BzrCheckError, NoSuchRevision
36
36
from bzrlib.inventory import ROOT_ID
37
 
from bzrlib.branch import gen_root_id
38
37
 
39
38
 
40
39
class Check(object):
54
53
 
55
54
    def check(self):
56
55
        self.branch.lock_read()
 
56
        self.progress = bzrlib.ui.ui_factory.progress_bar()
57
57
        try:
 
58
            self.progress.update('retrieving inventory', 0, 0)
 
59
            # do not put in init, as it should be done with progess,
 
60
            # and inside the lock.
 
61
            self.inventory_weave = self.branch._get_inventory_weave()
58
62
            self.history = self.branch.revision_history()
59
63
            if not len(self.history):
60
64
                # nothing to see here
61
65
                return
62
 
            self.planned_revisions = self.branch.get_ancestry(self.history[-1])
63
 
            self.planned_revisions.remove(None)
 
66
            self.plan_revisions()
64
67
            revno = 0
65
 
    
66
 
            self.progress = bzrlib.ui.ui_factory.progress_bar()
67
68
            while revno < len(self.planned_revisions):
68
69
                rev_id = self.planned_revisions[revno]
69
70
                self.progress.update('checking revision', revno,
70
71
                                     len(self.planned_revisions))
71
72
                revno += 1
72
73
                self.check_one_rev(rev_id)
73
 
            self.progress.clear()
74
74
        finally:
 
75
            self.progress.clear()
75
76
            self.branch.unlock()
76
77
 
 
78
    def plan_revisions(self):
 
79
        if not self.branch.storage.revision_store.listable():
 
80
            self.planned_revisions = self.branch.get_ancestry(self.history[-1])
 
81
            self.planned_revisions.remove(None)
 
82
            # FIXME progress bars should support this more nicely.
 
83
            self.progress.clear()
 
84
            print ("Checking reachable history -"
 
85
                   " for a complete check use a local branch.")
 
86
            return
 
87
        
 
88
        self.planned_revisions = set(self.branch.storage.revision_store)
 
89
        inventoried = set(self.inventory_weave.names())
 
90
        awol = self.planned_revisions - inventoried
 
91
        if len(awol) > 0:
 
92
            raise BzrCheckError('Stored revisions missing from inventory'
 
93
                '{%s}' % ','.join([f for f in awol]))
 
94
        self.planned_revisions = list(self.planned_revisions)
 
95
 
77
96
    def report_results(self, verbose):
78
97
        note('checked branch %s format %d',
79
98
             self.branch.base, 
110
129
        last_rev_id - the previous one on the mainline, if any.
111
130
        """
112
131
 
113
 
        # mutter('    revision {%s}' % rev_id)
 
132
        # mutter('    revision {%s}', rev_id)
114
133
        branch = self.branch
115
134
        try:
116
135
            rev_history_position = self.history.index(rev_id)
143
162
                    missing_links = self.missing_parent_links.get(parent, [])
144
163
                    missing_links.append(rev_id)
145
164
                    self.missing_parent_links[parent] = missing_links
146
 
                    # list based so slow, TODO have a planned_revisions list and set.
 
165
                    # list based so somewhat slow,
 
166
                    # TODO have a planned_revisions list and set.
147
167
                    if self.branch.has_revision(parent):
148
168
                        missing_ancestry = self.branch.get_ancestry(parent)
149
169
                        for missing in missing_ancestry:
164
184
                    ' value in revision {%s}' % rev_id)
165
185
        else:
166
186
            missing_inventory_sha_cnt += 1
167
 
            mutter("no inventory_sha1 on revision {%s}" % rev_id)
 
187
            mutter("no inventory_sha1 on revision {%s}", rev_id)
168
188
        self._check_revision_tree(rev_id)
169
189
        self.checked_rev_cnt += 1
170
190