20
20
######################################################################
21
21
# consistency checks
26
from trace import mutter
27
from errors import bailout
30
23
def check(branch, progress=True):
26
from bzrlib.trace import mutter
27
from bzrlib.errors import BzrCheckError
28
from bzrlib.osutils import fingerprint_file
33
if not (hasattr(out, 'isatty') and out.isatty()):
35
38
mutter('checking ' + m)
55
58
mutter(' revision {%s}' % rid)
56
59
rev = branch.get_revision(rid)
57
60
if rev.revision_id != rid:
58
bailout('wrong internal revision id in revision {%s}' % rid)
61
raise BzrCheckError('wrong internal revision id in revision {%s}' % rid)
59
62
if rev.precursor != last_ptr:
60
bailout('mismatched precursor in revision {%s}' % rid)
63
raise BzrCheckError('mismatched precursor in revision {%s}' % rid)
62
65
if rid in checked_revs:
63
bailout('repeated revision {%s}' % rid)
66
raise BzrCheckError('repeated revision {%s}' % rid)
67
checked_revs[rid] = True
66
69
## TODO: Check all the required fields are present on the revision.
68
71
inv = branch.get_inventory(rev.inventory_id)
72
75
p('revision %d/%d file ids' % (revno, revcount))
73
76
for file_id in inv:
74
77
if file_id in seen_ids:
75
bailout('duplicated file_id {%s} in inventory for revision {%s}'
78
raise BzrCheckError('duplicated file_id {%s} in inventory for revision {%s}'
80
seen_ids[file_id] = True
95
98
fp = checked_texts[ie.text_id]
97
100
if not ie.text_id in branch.text_store:
98
bailout('text {%s} not in text_store' % ie.text_id)
101
raise BzrCheckError('text {%s} not in text_store' % ie.text_id)
100
103
tf = branch.text_store[ie.text_id]
101
fp = osutils.fingerprint_file(tf)
104
fp = fingerprint_file(tf)
102
105
checked_texts[ie.text_id] = fp
104
107
if ie.text_size != fp['size']:
105
bailout('text {%s} wrong size' % ie.text_id)
108
raise BzrCheckError('text {%s} wrong size' % ie.text_id)
106
109
if ie.text_sha1 != fp['sha1']:
107
bailout('text {%s} wrong sha1' % ie.text_id)
110
raise BzrCheckError('text {%s} wrong sha1' % ie.text_id)
108
111
elif ie.kind == 'directory':
109
112
if ie.text_sha1 != None or ie.text_size != None or ie.text_id != None:
110
bailout('directory {%s} has text in revision {%s}'
113
raise BzrCheckError('directory {%s} has text in revision {%s}'
111
114
% (file_id, rid))
113
116
p('revision %d/%d file paths' % (revno, revcount))
114
117
for path, ie in inv.iter_entries():
115
118
if path in seen_names:
116
bailout('duplicated path %r in inventory for revision {%s}' % (path, revid))
119
raise BzrCheckError('duplicated path %r in inventory for revision {%s}' % (path, revid))
120
seen_names[path] = True
126
print 'checked %d revisions, %d file texts' % (revcount, len(checked_texts))