24
######################################################################
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")
22
"""Run consistency checks on a branch.
26
from bzrlib.trace import mutter
27
from bzrlib.errors import BzrCheckError
28
from bzrlib.osutils import fingerprint_file
29
from bzrlib.progress import ProgressBar
33
pb = ProgressBar(show_spinner=True)
37
history = branch.revision_history()
39
revcount = len(history)
45
pb.update('checking revision', revno, revcount)
46
mutter(' revision {%s}' % rid)
47
rev = branch.get_revision(rid)
48
if rev.revision_id != rid:
49
raise BzrCheckError('wrong internal revision id in revision {%s}' % rid)
50
if rev.precursor != last_ptr:
51
raise BzrCheckError('mismatched precursor in revision {%s}' % rid)
53
if rid in checked_revs:
54
raise BzrCheckError('repeated revision {%s}' % rid)
55
checked_revs[rid] = True
57
## TODO: Check all the required fields are present on the revision.
59
inv = branch.get_inventory(rev.inventory_id)
63
## p('revision %d/%d file ids' % (revno, revcount))
65
if file_id in seen_ids:
66
raise BzrCheckError('duplicated file_id {%s} '
67
'in inventory for revision {%s}'
69
seen_ids[file_id] = True
80
if ie.parent_id != None:
81
if ie.parent_id not in seen_ids:
82
raise BzrCheckError('missing parent {%s} in inventory for revision {%s}'
83
% (ie.parent_id, rid))
86
if ie.text_id in checked_texts:
87
fp = checked_texts[ie.text_id]
89
if not ie.text_id in branch.text_store:
90
raise BzrCheckError('text {%s} not in text_store' % ie.text_id)
92
tf = branch.text_store[ie.text_id]
93
fp = fingerprint_file(tf)
94
checked_texts[ie.text_id] = fp
96
if ie.text_size != fp['size']:
97
raise BzrCheckError('text {%s} wrong size' % ie.text_id)
98
if ie.text_sha1 != fp['sha1']:
99
raise BzrCheckError('text {%s} wrong sha1' % ie.text_id)
100
elif ie.kind == 'directory':
101
if ie.text_sha1 != None or ie.text_size != None or ie.text_id != None:
102
raise BzrCheckError('directory {%s} has text in revision {%s}'
106
for path, ie in inv.iter_entries():
107
if path in seen_names:
108
raise BzrCheckError('duplicated path %r '
109
'in inventory for revision {%s}'
111
seen_names[path] = True
115
print 'checked %d revisions, %d file texts' % (revcount, len(checked_texts))