43
46
branch = self.branch
47
missing_inventory_sha_cnt = 0
48
missing_revision_sha_cnt = 0
49
missing_revision_cnt = 0
48
self.checked_text_cnt = 0
49
self.checked_rev_cnt = 0
50
self.missing_inventory_sha_cnt = 0
51
self.missing_revision_cnt = 0
51
53
history = branch.revision_history()
53
55
revcount = len(history)
55
checked_text_count = 0
57
progress = bzrlib.ui.ui_factory.progress_bar()
58
self.progress = bzrlib.ui.ui_factory.progress_bar()
59
59
for rev_id in history:
60
self.progress.update('checking revision', revno, revcount)
61
progress.update('checking revision', revno, revcount)
62
# mutter(' revision {%s}' % rev_id)
63
rev = branch.get_revision(rev_id)
64
if rev.revision_id != rev_id:
65
raise BzrCheckError('wrong internal revision id in revision {%s}'
68
# check the previous history entry is a parent of this entry
70
if last_rev_id is None:
71
raise BzrCheckError("revision {%s} has %d parents, but is the "
73
% (rev_id, len(rev.parent_ids)))
74
for parent_id in rev.parent_ids:
75
if parent_id == last_rev_id:
78
raise BzrCheckError("previous revision {%s} not listed among "
80
% (last_rev_id, rev_id))
82
raise BzrCheckError("revision {%s} has no parents listed "
83
"but preceded by {%s}"
84
% (rev_id, last_rev_id))
86
## TODO: Check all the required fields are present on the revision.
88
if rev.inventory_sha1:
89
inv_sha1 = branch.get_inventory_sha1(rev_id)
90
if inv_sha1 != rev.inventory_sha1:
91
raise BzrCheckError('Inventory sha1 hash doesn\'t match'
92
' value in revision {%s}' % rev_id)
94
missing_inventory_sha_cnt += 1
95
mutter("no inventory_sha1 on revision {%s}" % rev_id)
97
tree = branch.revision_tree(rev_id)
102
## p('revision %d/%d file ids' % (revno, revcount))
104
if file_id in seen_ids:
105
raise BzrCheckError('duplicated file_id {%s} '
106
'in inventory for revision {%s}'
108
seen_ids[file_id] = True
118
if ie.parent_id != None:
119
if ie.parent_id not in seen_ids:
120
raise BzrCheckError('missing parent {%s} in inventory for revision {%s}'
121
% (ie.parent_id, rev_id))
123
if ie.kind == 'file':
124
text = tree.get_file_text(file_id)
125
checked_text_count += 1
126
if ie.text_size != len(text):
127
raise BzrCheckError('text {%s} wrong size' % ie.text_id)
128
if ie.text_sha1 != sha_string(text):
129
raise BzrCheckError('text {%s} wrong sha1' % ie.text_id)
130
elif ie.kind == 'directory':
131
if ie.text_sha1 != None or ie.text_size != None or ie.text_id != None:
132
raise BzrCheckError('directory {%s} has text in revision {%s}'
136
for path, ie in inv.iter_entries():
137
if path in seen_names:
138
raise BzrCheckError('duplicated path %s '
139
'in inventory for revision {%s}'
141
seen_names[path] = True
147
note('checked %d revisions, %d file texts' % (revcount, checked_text_count))
149
if missing_inventory_sha_cnt:
150
note('%d revisions are missing inventory_sha1' % missing_inventory_sha_cnt)
152
##if missing_revision_sha_cnt:
153
## note('%d parent links are missing revision_sha1' % missing_revision_sha_cnt)
155
if missing_revision_cnt:
156
note('%d revisions are mentioned but not present' % missing_revision_cnt)
158
if missing_revision_cnt:
159
print '%d revisions are mentioned but not present' % missing_revision_cnt
161
# stub this out for now because the main bzr branch has references
162
# to revisions that aren't present in the store -- mbp 20050804
163
# if (missing_inventory_sha_cnt
164
# or missing_revision_sha_cnt):
165
# print ' (use "bzr upgrade" to fix them)'
62
self.check_one_rev(rev_id, last_rev_id)
68
def report_results(self):
69
note('checked branch %s format %d',
71
self.branch._branch_format)
73
note('checked %d revisions, %d file texts',
75
self.checked_text_cnt)
77
if self.missing_inventory_sha_cnt:
78
note('%d revisions are missing inventory_sha1',
79
self.missing_inventory_sha_cnt)
81
if self.missing_revision_cnt:
82
note('%d revisions are mentioned but not present',
83
self.missing_revision_cnt)
86
def check_one_rev(self, rev_id, last_rev_id):
87
# mutter(' revision {%s}' % rev_id)
89
rev = branch.get_revision(rev_id)
90
if rev.revision_id != rev_id:
91
raise BzrCheckError('wrong internal revision id in revision {%s}'
94
# check the previous history entry is a parent of this entry
96
if last_rev_id is None:
97
raise BzrCheckError("revision {%s} has %d parents, but is the "
99
% (rev_id, len(rev.parent_ids)))
100
for parent_id in rev.parent_ids:
101
if parent_id == last_rev_id:
104
raise BzrCheckError("previous revision {%s} not listed among "
106
% (last_rev_id, rev_id))
108
raise BzrCheckError("revision {%s} has no parents listed "
109
"but preceded by {%s}"
110
% (rev_id, last_rev_id))
112
if rev.inventory_sha1:
113
inv_sha1 = branch.get_inventory_sha1(rev_id)
114
if inv_sha1 != rev.inventory_sha1:
115
raise BzrCheckError('Inventory sha1 hash doesn\'t match'
116
' value in revision {%s}' % rev_id)
118
missing_inventory_sha_cnt += 1
119
mutter("no inventory_sha1 on revision {%s}" % rev_id)
121
tree = branch.revision_tree(rev_id)
126
## p('revision %d/%d file ids' % (revno, revcount))
128
if file_id in seen_ids:
129
raise BzrCheckError('duplicated file_id {%s} '
130
'in inventory for revision {%s}'
132
seen_ids[file_id] = True
142
if ie.parent_id != None:
143
if ie.parent_id not in seen_ids:
144
raise BzrCheckError('missing parent {%s} in inventory for revision {%s}'
145
% (ie.parent_id, rev_id))
147
if ie.kind == 'file':
148
text = tree.get_file_text(file_id)
149
self.checked_text_cnt += 1
150
if ie.text_size != len(text):
151
raise BzrCheckError('text {%s} wrong size' % ie.text_id)
152
if ie.text_sha1 != sha_string(text):
153
raise BzrCheckError('text {%s} wrong sha1' % ie.text_id)
154
elif ie.kind == 'directory':
155
if ie.text_sha1 != None or ie.text_size != None or ie.text_id != None:
156
raise BzrCheckError('directory {%s} has text in revision {%s}'
160
for path, ie in inv.iter_entries():
161
if path in seen_names:
162
raise BzrCheckError('duplicated path %s '
163
'in inventory for revision {%s}'
165
seen_names[path] = True