~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/check.py

  • Committer: Martin Pool
  • Date: 2005-06-20 03:28:33 UTC
  • Revision ID: mbp@sourcefrog.net-20050620032833-9702a10d71763aab
- updated check for revision parents and sha1

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
def check(branch):
22
22
    """Run consistency checks on a branch.
 
23
 
 
24
    TODO: Also check non-mailine revisions mentioned as parents.
23
25
    """
24
26
    from bzrlib.trace import mutter
25
27
    from bzrlib.errors import BzrCheckError
30
32
 
31
33
    try:
32
34
        pb = ProgressBar(show_spinner=True)
33
 
        last_ptr = None
34
 
        checked_revs = {}
 
35
        last_rev_id = None
35
36
 
36
37
        missing_inventory_sha_cnt = 0
 
38
        missing_revision_sha_cnt = 0
37
39
 
38
40
        history = branch.revision_history()
39
41
        revno = 0
40
42
        revcount = len(history)
41
43
 
 
44
        # for all texts checked, text_id -> sha1
42
45
        checked_texts = {}
43
46
 
44
47
        for rev_id in history:
47
50
            mutter('    revision {%s}' % rev_id)
48
51
            rev = branch.get_revision(rev_id)
49
52
            if rev.revision_id != rev_id:
50
 
                raise BzrCheckError('wrong internal revision id in revision {%s}' % rev_id)
51
 
            if rev.precursor != last_ptr:
52
 
                raise BzrCheckError('mismatched precursor in revision {%s}' % rev_id)
53
 
            last_ptr = rev_id
54
 
            if rev_id in checked_revs:
55
 
                raise BzrCheckError('repeated revision {%s}' % rev_id)
56
 
            checked_revs[rev_id] = True
 
53
                raise BzrCheckError('wrong internal revision id in revision {%s}'
 
54
                                    % rev_id)
 
55
 
 
56
            # check the previous history entry is a parent of this entry
 
57
            if rev.parents:
 
58
                if last_rev_id is None:
 
59
                    raise BzrCheckError("revision {%s} has %d parents, but is the "
 
60
                                        "start of the branch"
 
61
                                        % (rev_id, len(rev.parents)))
 
62
                for prr in rev.parents:
 
63
                    if prr.revision_id == last_rev_id:
 
64
                        break
 
65
                else:
 
66
                    raise BzrCheckError("previous revision {%s} not listed among "
 
67
                                        "parents of {%s}"
 
68
                                        % (last_rev_id, rev_id))
 
69
 
 
70
                for prr in rev.parents:
 
71
                    if prr.revision_sha1 is None:
 
72
                        missing_revision_sha_cnt += 1
 
73
                        continue
 
74
                    prid = prr.revision_id
 
75
                    actual_sha = branch.get_revision_sha1(prid)
 
76
                    if prr.revision_sha1 != actual_sha:
 
77
                        raise BzrCheckError("mismatched revision sha1 for "
 
78
                                            "parent {%s} of {%s}: %s vs %s"
 
79
                                            % (prid, rev_id,
 
80
                                               prr.revision_sha1, actual_sha))
 
81
            elif last_rev_id:
 
82
                raise BzrCheckError("revision {%s} has no parents listed but preceded "
 
83
                                    "by {%s}"
 
84
                                    % (rev_id, last_rev_id))
57
85
 
58
86
            ## TODO: Check all the required fields are present on the revision.
59
87
 
126
154
                                        'in inventory for revision {%s}'
127
155
                                        % (path, rev_id))
128
156
            seen_names[path] = True
 
157
            last_rev_id = rev_id
129
158
 
130
159
    finally:
131
160
        branch.unlock()
133
162
    pb.clear()
134
163
 
135
164
    print 'checked %d revisions, %d file texts' % (revcount, len(checked_texts))
 
165
    
136
166
    if missing_inventory_sha_cnt:
137
167
        print '%d revisions are missing inventory_sha1' % missing_inventory_sha_cnt
 
168
 
 
169
    if missing_revision_sha_cnt:
 
170
        print '%d parent links are missing revision_sha1' % missing_revision_sha_cnt
 
171
 
 
172
    if (missing_inventory_sha_cnt
 
173
        or missing_revision_sha_cnt):
138
174
        print '  (use "bzr upgrade" to fix them)'