20
20
######################################################################
21
21
# consistency checks
25
from trace import mutter
26
from errors import bailout
23
29
def check(branch, progress=True):
26
from bzrlib.trace import mutter
27
from bzrlib.errors import BzrCheckError
28
from bzrlib.osutils import fingerprint_file
58
58
mutter(' revision {%s}' % rid)
59
59
rev = branch.get_revision(rid)
60
60
if rev.revision_id != rid:
61
raise BzrCheckError('wrong internal revision id in revision {%s}' % rid)
61
bailout('wrong internal revision id in revision {%s}' % rid)
62
62
if rev.precursor != last_ptr:
63
raise BzrCheckError('mismatched precursor in revision {%s}' % rid)
63
bailout('mismatched precursor in revision {%s}' % rid)
65
65
if rid in checked_revs:
66
raise BzrCheckError('repeated revision {%s}' % rid)
66
bailout('repeated revision {%s}' % rid)
67
67
checked_revs[rid] = True
69
69
## TODO: Check all the required fields are present on the revision.
98
98
fp = checked_texts[ie.text_id]
100
100
if not ie.text_id in branch.text_store:
101
raise BzrCheckError('text {%s} not in text_store' % ie.text_id)
101
bailout('text {%s} not in text_store' % ie.text_id)
103
103
tf = branch.text_store[ie.text_id]
104
fp = fingerprint_file(tf)
104
fp = osutils.fingerprint_file(tf)
105
105
checked_texts[ie.text_id] = fp
107
107
if ie.text_size != fp['size']:
108
raise BzrCheckError('text {%s} wrong size' % ie.text_id)
108
bailout('text {%s} wrong size' % ie.text_id)
109
109
if ie.text_sha1 != fp['sha1']:
110
raise BzrCheckError('text {%s} wrong sha1' % ie.text_id)
110
bailout('text {%s} wrong sha1' % ie.text_id)
111
111
elif ie.kind == 'directory':
112
112
if ie.text_sha1 != None or ie.text_size != None or ie.text_id != None:
113
raise BzrCheckError('directory {%s} has text in revision {%s}'
113
bailout('directory {%s} has text in revision {%s}'
114
114
% (file_id, rid))
116
116
p('revision %d/%d file paths' % (revno, revcount))
117
117
for path, ie in inv.iter_entries():
118
118
if path in seen_names:
119
raise BzrCheckError('duplicated path %r in inventory for revision {%s}' % (path, revid))
119
bailout('duplicated path %r in inventory for revision {%s}' % (path, revid))
120
120
seen_names[path] = True