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
40
39
class Check(object):
56
55
self.branch.lock_read()
56
self.progress = bzrlib.ui.ui_factory.progress_bar()
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
62
self.planned_revisions = self.branch.get_ancestry(self.history[-1])
63
self.planned_revisions.remove(None)
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))
72
73
self.check_one_rev(rev_id)
75
76
self.branch.unlock()
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.
84
print ("Checking reachable history -"
85
" for a complete check use a local branch.")
88
self.planned_revisions = set(self.branch.revision_store)
89
inventoried = set(self.inventory_weave.names())
90
awol = self.planned_revisions - inventoried
92
raise BzrCheckError('Stored revisions missing from inventory'
93
'{%s}' % ','.join([f for f in awol]))
94
self.planned_revisions = list(self.planned_revisions)
77
96
def report_results(self, verbose):
78
97
note('checked branch %s format %d',
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: