20
20
######################################################################
21
21
# consistency checks
24
24
from sets import Set
27
26
from trace import mutter
28
27
from errors import bailout
32
mutter('checking tree %r' % branch.base)
34
mutter('checking revision history')
30
def check(branch, progress=True):
35
mutter('checking ' + m)
36
out.write('\rchecking: %-50.50s' % m)
40
mutter('checking ' + m)
42
p('history of %r' % branch.base)
36
44
checked_revs = Set()
37
for rid in branch.revision_history():
46
history = branch.revision_history()
48
revcount = len(history)
54
p('revision %d/%d' % (revno, revcount))
38
55
mutter(' revision {%s}' % rid)
39
56
rev = branch.get_revision(rid)
40
57
if rev.revision_id != rid:
49
66
## TODO: Check all the required fields are present on the revision.
51
68
inv = branch.get_inventory(rev.inventory_id)
52
check_inventory(branch, inv)
54
mutter('branch %s is OK' % branch.base)
58
def check_inventory(branch, inv):
62
for path, ie in inv.iter_entries():
63
if path in seen_names:
64
bailout('duplicated path %r in inventory' % path)
67
if not ie.text_id in branch.text_store:
68
bailout('text {%s} not in text_store' % ie.text_id)
72
p('revision %d/%d file ids' % (revno, revcount))
74
if file_id in seen_ids:
75
bailout('duplicated file_id {%s} in inventory for revision {%s}'
84
p('revision %d/%d file text %d/%d' % (revno, revcount, i, len_inv))
88
if ie.parent_id != None:
89
if ie.parent_id not in seen_ids:
90
bailout('missing parent {%s} in inventory for revision {%s}'
91
% (ie.parent_id, rid))
94
if ie.text_id in checked_texts:
95
fp = checked_texts[ie.text_id]
97
if not ie.text_id in branch.text_store:
98
bailout('text {%s} not in text_store' % ie.text_id)
100
tf = branch.text_store[ie.text_id]
101
fp = osutils.fingerprint_file(tf)
102
checked_texts[ie.text_id] = fp
104
if ie.text_size != fp['size']:
105
bailout('text {%s} wrong size' % ie.text_id)
106
if ie.text_sha1 != fp['sha1']:
107
bailout('text {%s} wrong sha1' % ie.text_id)
108
elif ie.kind == 'directory':
109
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
p('revision %d/%d file paths' % (revno, revcount))
114
for path, ie in inv.iter_entries():
115
if path in seen_names:
116
bailout('duplicated path %r in inventory for revision {%s}' % (path, revid))