30
30
from bzrlib.trace import note, warning
31
from bzrlib.osutils import rename, sha_string, fingerprint_file, sha_strings
31
from bzrlib.osutils import rename, sha_string, fingerprint_file
32
32
from bzrlib.trace import mutter
33
33
from bzrlib.errors import BzrCheckError, NoSuchRevision
34
34
from bzrlib.inventory import ROOT_ID
148
148
% (file_id, rev_id))
149
149
seen_ids[file_id] = True
150
150
for file_id in inv:
151
self._check_one_entry(rev_id, inv, tree, file_id)
152
ie.check(self, rev_id, inv, tree)
153
154
for path, ie in inv.iter_entries():
154
155
if path in seen_names:
157
158
% (path, rev_id))
158
159
seen_names[path] = True
161
def _check_one_entry(self, rev_id, inv, tree, file_id):
163
if ie.parent_id != None:
164
if not inv.has_id(ie.parent_id):
165
raise BzrCheckError('missing parent {%s} in inventory for revision {%s}'
166
% (ie.parent_id, rev_id))
167
if ie.kind == 'file':
168
text_version = ie.text_version
169
t = (file_id, text_version)
170
if t in self.checked_texts:
171
prev_sha = self.checked_texts[t]
172
if prev_sha != ie.text_sha1:
173
raise BzrCheckError('mismatched sha1 on {%s} in {%s}' %
176
self.repeated_text_cnt += 1
178
mutter('check version {%s} of {%s}', rev_id, file_id)
179
file_lines = tree.get_file_lines(file_id)
180
self.checked_text_cnt += 1
181
if ie.text_size != sum(map(len, file_lines)):
182
raise BzrCheckError('text {%s} wrong size' % ie.text_id)
183
if ie.text_sha1 != sha_strings(file_lines):
184
raise BzrCheckError('text {%s} wrong sha1' % ie.text_id)
185
self.checked_texts[t] = ie.text_sha1
186
elif ie.kind == 'directory':
187
if ie.text_sha1 != None or ie.text_size != None or ie.text_id != None:
188
raise BzrCheckError('directory {%s} has text in revision {%s}'
190
elif ie.kind == 'root_directory':
193
raise BzrCheckError('unknown entry kind %r in revision {%s}' %
197
162
def check(branch):
198
163
"""Run consistency checks on a branch."""