20
24
######################################################################
21
25
# consistency checks
27
from trace import mutter
28
from errors import bailout
31
def check(branch, progress=True):
36
mutter('checking ' + m)
37
out.write('\rchecking: %-50.50s' % m)
41
mutter('checking ' + m)
43
p('history of %r' % branch.base)
47
history = branch.revision_history()
49
revcount = len(history)
55
p('revision %d/%d' % (revno, revcount))
56
mutter(' revision {%s}' % rid)
57
rev = branch.get_revision(rid)
58
if rev.revision_id != rid:
59
bailout('wrong internal revision id in revision {%s}' % rid)
60
if rev.precursor != last_ptr:
61
bailout('mismatched precursor in revision {%s}' % rid)
63
if rid in checked_revs:
64
bailout('repeated revision {%s}' % rid)
67
## TODO: Check all the required fields are present on the revision.
69
inv = branch.get_inventory(rev.inventory_id)
73
p('revision %d/%d file ids' % (revno, revcount))
75
if file_id in seen_ids:
76
bailout('duplicated file_id {%s} in inventory for revision {%s}'
85
p('revision %d/%d file text %d/%d' % (revno, revcount, i, len_inv))
89
if ie.parent_id != None:
90
if ie.parent_id not in seen_ids:
91
bailout('missing parent {%s} in inventory for revision {%s}'
92
% (ie.parent_id, revid))
95
if ie.text_id in checked_texts:
96
fp = checked_texts[ie.text_id]
98
if not ie.text_id in branch.text_store:
99
bailout('text {%s} not in text_store' % ie.text_id)
101
tf = branch.text_store[ie.text_id]
102
fp = osutils.fingerprint_file(tf)
103
checked_texts[ie.text_id] = fp
105
if ie.text_size != fp['size']:
106
bailout('text {%s} wrong size' % ie.text_id)
107
if ie.text_sha1 != fp['sha1']:
108
bailout('text {%s} wrong sha1' % ie.text_id)
109
elif ie.kind == 'directory':
110
if ie.text_sha1 != None or ie.text_size != None or ie.text_id != None:
111
bailout('directory {%s} has text in revision {%s}'
114
p('revision %d/%d file paths' % (revno, revcount))
115
for path, ie in inv.iter_entries():
116
if path in seen_names:
117
bailout('duplicated path %r in inventory for revision {%s}' % (path, revid))
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")