25
25
# TODO: Check revision, inventory and entry objects have all
28
# TODO: Get every revision in the revision-store even if they're not
29
# referenced by history and make sure they're all valid.
32
30
from bzrlib.trace import note, warning
34
32
from bzrlib.trace import mutter
35
33
from bzrlib.errors import BzrCheckError, NoSuchRevision
36
34
from bzrlib.inventory import ROOT_ID
35
from bzrlib.branch import gen_root_id
39
38
class Check(object):
56
54
self.branch.lock_read()
57
self.progress = bzrlib.ui.ui_factory.progress_bar()
59
56
self.history = self.branch.revision_history()
60
57
if not len(self.history):
61
58
# nothing to see here
63
if not self.branch.revision_store.listable():
64
raise BzrCheckError("Branch must be local")
65
self.planned_revisions = set(self.branch.revision_store)
66
inventoried = set(self.inventory_weave.names())
67
awol = self.planned_revisions - inventoried
69
raise BzrCheckError('Stored revisions missing from inventory'
70
'{%s}' % ','.join([f for f in awol]))
60
self.planned_revisions = self.branch.get_ancestry(self.history[-1])
61
self.planned_revisions.remove(None)
72
for revno, rev_id in enumerate(self.planned_revisions):
73
self.progress.update('checking revision', revno+1,
64
self.progress = bzrlib.ui.ui_factory.progress_bar()
65
while revno < len(self.planned_revisions):
66
rev_id = self.planned_revisions[revno]
67
self.progress.update('checking revision', revno,
74
68
len(self.planned_revisions))
75
70
self.check_one_rev(rev_id)
78
73
self.branch.unlock()
80
75
def report_results(self, verbose):
113
108
last_rev_id - the previous one on the mainline, if any.
116
# mutter(' revision {%s}', rev_id)
111
# mutter(' revision {%s}' % rev_id)
117
112
branch = self.branch
119
114
rev_history_position = self.history.index(rev_id)
134
129
# check the previous history entry is a parent of this entry
135
130
if rev.parent_ids:
131
if last_rev_id is None and rev_history_position is not None:
132
# what if the start is a ghost ? i.e. conceptually the
134
raise BzrCheckError("revision {%s} has %d parents, but is the "
135
"start of the branch"
136
% (rev_id, len(rev.parent_ids)))
136
137
if last_rev_id is not None:
137
138
for parent_id in rev.parent_ids:
138
139
if parent_id == last_rev_id:
167
168
' value in revision {%s}' % rev_id)
169
170
missing_inventory_sha_cnt += 1
170
mutter("no inventory_sha1 on revision {%s}", rev_id)
171
mutter("no inventory_sha1 on revision {%s}" % rev_id)
171
172
self._check_revision_tree(rev_id)
172
173
self.checked_rev_cnt += 1