20
20
######################################################################
21
21
# consistency checks
26
from trace import mutter
27
from errors import bailout
23
30
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
59
mutter(' revision {%s}' % rid)
59
60
rev = branch.get_revision(rid)
60
61
if rev.revision_id != rid:
61
raise BzrCheckError('wrong internal revision id in revision {%s}' % rid)
62
bailout('wrong internal revision id in revision {%s}' % rid)
62
63
if rev.precursor != last_ptr:
63
raise BzrCheckError('mismatched precursor in revision {%s}' % rid)
64
bailout('mismatched precursor in revision {%s}' % rid)
65
66
if rid in checked_revs:
66
raise BzrCheckError('repeated revision {%s}' % rid)
67
checked_revs[rid] = True
67
bailout('repeated revision {%s}' % rid)
69
70
## TODO: Check all the required fields are present on the revision.
71
72
inv = branch.get_inventory(rev.inventory_id)
75
76
p('revision %d/%d file ids' % (revno, revcount))
76
77
for file_id in inv:
77
78
if file_id in seen_ids:
78
raise BzrCheckError('duplicated file_id {%s} in inventory for revision {%s}'
79
bailout('duplicated file_id {%s} in inventory for revision {%s}'
80
seen_ids[file_id] = True
98
99
fp = checked_texts[ie.text_id]
100
101
if not ie.text_id in branch.text_store:
101
raise BzrCheckError('text {%s} not in text_store' % ie.text_id)
102
bailout('text {%s} not in text_store' % ie.text_id)
103
104
tf = branch.text_store[ie.text_id]
104
fp = fingerprint_file(tf)
105
fp = osutils.fingerprint_file(tf)
105
106
checked_texts[ie.text_id] = fp
107
108
if ie.text_size != fp['size']:
108
raise BzrCheckError('text {%s} wrong size' % ie.text_id)
109
bailout('text {%s} wrong size' % ie.text_id)
109
110
if ie.text_sha1 != fp['sha1']:
110
raise BzrCheckError('text {%s} wrong sha1' % ie.text_id)
111
bailout('text {%s} wrong sha1' % ie.text_id)
111
112
elif ie.kind == 'directory':
112
113
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}'
114
bailout('directory {%s} has text in revision {%s}'
114
115
% (file_id, rid))
116
117
p('revision %d/%d file paths' % (revno, revcount))
117
118
for path, ie in inv.iter_entries():
118
119
if path in seen_names:
119
raise BzrCheckError('duplicated path %r in inventory for revision {%s}' % (path, revid))
120
seen_names[path] = True
120
bailout('duplicated path %r in inventory for revision {%s}' % (path, revid))