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.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.
84
print ("Checking reachable history -"
85
" for a complete check use a local branch.")
88
self.planned_revisions = set(self.branch.storage.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',
110
129
last_rev_id - the previous one on the mainline, if any.
113
# mutter(' revision {%s}' % rev_id)
132
# mutter(' revision {%s}', rev_id)
114
133
branch = self.branch
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)
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