24
20
######################################################################
25
21
# consistency checks
28
"""Consistency check of tree."""
30
mutter("checking tree")
32
check_patch_chaining()
33
check_patch_uniqueness()
35
mutter("tree looks OK")
36
## TODO: Check that previous-inventory and previous-manifest
37
## are the same as those stored in the previous changeset.
39
## TODO: Check all patches present in patch directory are
40
## mentioned in patch history; having an orphaned patch only gives
43
## TODO: Check cached data is consistent with data reconstructed
46
## TODO: Check no control files are versioned.
48
## TODO: Check that the before-hash of each file in a later
49
## revision matches the after-hash in the previous revision to
53
def check_inventory():
54
mutter("checking inventory file and ids...")
58
for l in controlfile('inventory').readlines():
61
bailout("malformed inventory line: " + `l`)
64
if file_id in seen_ids:
65
bailout("duplicated file id " + file_id)
68
if name in seen_names:
69
bailout("duplicated file name in inventory: " + quotefn(name))
72
if is_control_file(name):
73
raise BzrError("control file %s present in inventory" % quotefn(name))
76
def check_patches_exist():
77
"""Check constraint of current version: all patches exist"""
78
mutter("checking all patches are present...")
79
for pid in revision_history():
80
read_patch_header(pid)
83
def check_patch_chaining():
84
"""Check ancestry of patches and history file is consistent"""
85
mutter("checking patch chaining...")
87
for pid in revision_history():
88
log_prev = read_patch_header(pid).precursor
90
bailout("inconsistent precursor links on " + pid)
94
def check_patch_uniqueness():
95
"""Make sure no patch is listed twice in the history.
97
This should be implied by having correct ancestry but I'll check it
99
mutter("checking history for duplicates...")
101
for pid in revision_history():
103
bailout("patch " + pid + " appears twice in history")
25
from trace import mutter
26
from errors import bailout
29
def check(branch, progress=True):
33
if not (hasattr(out, 'isatty') and out.isatty()):
38
mutter('checking ' + m)
39
out.write('\rchecking: %-50.50s' % m)
43
mutter('checking ' + m)
45
p('history of %r' % branch.base)
49
history = branch.revision_history()
51
revcount = len(history)
57
p('revision %d/%d' % (revno, revcount))
58
mutter(' revision {%s}' % rid)
59
rev = branch.get_revision(rid)
60
if rev.revision_id != rid:
61
bailout('wrong internal revision id in revision {%s}' % rid)
62
if rev.precursor != last_ptr:
63
bailout('mismatched precursor in revision {%s}' % rid)
65
if rid in checked_revs:
66
bailout('repeated revision {%s}' % rid)
67
checked_revs[rid] = True
69
## TODO: Check all the required fields are present on the revision.
71
inv = branch.get_inventory(rev.inventory_id)
75
p('revision %d/%d file ids' % (revno, revcount))
77
if file_id in seen_ids:
78
bailout('duplicated file_id {%s} in inventory for revision {%s}'
80
seen_ids[file_id] = True
87
p('revision %d/%d file text %d/%d' % (revno, revcount, i, len_inv))
91
if ie.parent_id != None:
92
if ie.parent_id not in seen_ids:
93
bailout('missing parent {%s} in inventory for revision {%s}'
94
% (ie.parent_id, rid))
97
if ie.text_id in checked_texts:
98
fp = checked_texts[ie.text_id]
100
if not ie.text_id in branch.text_store:
101
bailout('text {%s} not in text_store' % ie.text_id)
103
tf = branch.text_store[ie.text_id]
104
fp = osutils.fingerprint_file(tf)
105
checked_texts[ie.text_id] = fp
107
if ie.text_size != fp['size']:
108
bailout('text {%s} wrong size' % ie.text_id)
109
if ie.text_sha1 != fp['sha1']:
110
bailout('text {%s} wrong sha1' % ie.text_id)
111
elif ie.kind == 'directory':
112
if ie.text_sha1 != None or ie.text_size != None or ie.text_id != None:
113
bailout('directory {%s} has text in revision {%s}'
116
p('revision %d/%d file paths' % (revno, revcount))
117
for path, ie in inv.iter_entries():
118
if path in seen_names:
119
bailout('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))