~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/check.py

  • Committer: Martin Pool
  • Date: 2005-06-06 11:53:29 UTC
  • Revision ID: mbp@sourcefrog.net-20050606115329-1596352add25bffd
- merge aaron's updated merge/pull code

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
# consistency checks
22
22
 
23
23
import sys
24
 
from sets import Set
25
24
 
26
 
import bzrlib
27
25
from trace import mutter
28
26
from errors import bailout
29
27
import osutils
31
29
def check(branch, progress=True):
32
30
    out = sys.stdout
33
31
 
 
32
    # TODO: factor out
 
33
    if not (hasattr(out, 'isatty') and out.isatty()):
 
34
        progress=False
 
35
 
34
36
    if progress:
35
37
        def p(m):
36
38
            mutter('checking ' + m)
42
44
 
43
45
    p('history of %r' % branch.base)
44
46
    last_ptr = None
45
 
    checked_revs = Set()
 
47
    checked_revs = {}
46
48
    
47
49
    history = branch.revision_history()
48
50
    revno = 0
62
64
        last_ptr = rid
63
65
        if rid in checked_revs:
64
66
            bailout('repeated revision {%s}' % rid)
65
 
        checked_revs.add(rid)
 
67
        checked_revs[rid] = True
66
68
 
67
69
        ## TODO: Check all the required fields are present on the revision.
68
70
 
69
71
        inv = branch.get_inventory(rev.inventory_id)
70
 
        seen_ids = Set()
71
 
        seen_names = Set()
 
72
        seen_ids = {}
 
73
        seen_names = {}
72
74
 
73
75
        p('revision %d/%d file ids' % (revno, revcount))
74
76
        for file_id in inv:
75
77
            if file_id in seen_ids:
76
78
                bailout('duplicated file_id {%s} in inventory for revision {%s}'
77
 
                        % (file_id, revid))
78
 
            seen_ids.add(file_id)
 
79
                        % (file_id, rid))
 
80
            seen_ids[file_id] = True
79
81
 
80
82
        i = 0
81
83
        len_inv = len(inv)
89
91
            if ie.parent_id != None:
90
92
                if ie.parent_id not in seen_ids:
91
93
                    bailout('missing parent {%s} in inventory for revision {%s}'
92
 
                            % (ie.parent_id, revid))
 
94
                            % (ie.parent_id, rid))
93
95
 
94
96
            if ie.kind == 'file':
95
97
                if ie.text_id in checked_texts:
109
111
            elif ie.kind == 'directory':
110
112
                if ie.text_sha1 != None or ie.text_size != None or ie.text_id != None:
111
113
                    bailout('directory {%s} has text in revision {%s}'
112
 
                            % (file_id, revid))
 
114
                            % (file_id, rid))
113
115
 
114
116
        p('revision %d/%d file paths' % (revno, revcount))
115
117
        for path, ie in inv.iter_entries():
116
118
            if path in seen_names:
117
119
                bailout('duplicated path %r in inventory for revision {%s}' % (path, revid))
118
 
            seen_names.add(path)
 
120
            seen_names[path] = True
119
121
 
120
122
 
121
123
    p('done')
122
124
    if progress:
123
125
        print 
124
 
 
 
126
    print 'checked %d revisions, %d file texts' % (revcount, len(checked_texts))
125
127