~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/check.py

[merge] bzr.dev

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):
42
41
 
43
42
    def __init__(self, branch):
44
43
        self.branch = branch
45
 
        self.inventory_weave = branch._get_inventory_weave()
46
44
        self.checked_text_cnt = 0
47
45
        self.checked_rev_cnt = 0
48
46
        self.ghosts = []
57
55
        self.branch.lock_read()
58
56
        self.progress = bzrlib.ui.ui_factory.progress_bar()
59
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()
60
62
            self.history = self.branch.revision_history()
61
63
            if not len(self.history):
62
64
                # nothing to see here
63
65
                return
64
 
            if not self.branch.revision_store.listable():
65
 
                raise BzrCheckError("Branch must be local")
66
 
            self.planned_revisions = set(self.branch.revision_store)
67
 
            inventoried = set(self.inventory_weave.names())
68
 
            awol = self.planned_revisions - inventoried
69
 
            if len(awol) > 0:
70
 
                raise BzrCheckError('Stored revisions missing from inventory'
71
 
                    '{%s}' % ','.join([f for f in awol]))
72
 
    
73
 
            for revno, rev_id in enumerate(self.planned_revisions):
74
 
                self.progress.update('checking revision', revno+1,
 
66
            self.plan_revisions()
 
67
            revno = 0
 
68
            while revno < len(self.planned_revisions):
 
69
                rev_id = self.planned_revisions[revno]
 
70
                self.progress.update('checking revision', revno,
75
71
                                     len(self.planned_revisions))
 
72
                revno += 1
76
73
                self.check_one_rev(rev_id)
77
74
        finally:
78
75
            self.progress.clear()
79
76
            self.branch.unlock()
80
77
 
 
78
    def plan_revisions(self):
 
79
        if not self.branch.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.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
 
81
96
    def report_results(self, verbose):
82
97
        note('checked branch %s format %d',
83
98
             self.branch.base, 
147
162
                    missing_links = self.missing_parent_links.get(parent, [])
148
163
                    missing_links.append(rev_id)
149
164
                    self.missing_parent_links[parent] = missing_links
150
 
                    # 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.
151
167
                    if self.branch.has_revision(parent):
152
168
                        missing_ancestry = self.branch.get_ancestry(parent)
153
169
                        for missing in missing_ancestry: