/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/check.py

  • Committer: Martin Pool
  • Date: 2005-09-22 00:34:03 UTC
  • Revision ID: mbp@sourcefrog.net-20050922003403-c2102480b4e54424
- more refactoring of check code

- add checks for valid file types

Show diffs side-by-side

added added

removed removed

Lines of Context:
84
84
 
85
85
 
86
86
    def check_one_rev(self, rev_id, last_rev_id):
 
87
        """Check one revision.
 
88
 
 
89
        rev_id - the one to check
 
90
 
 
91
        last_rev_id - the previous one on the mainline, if any.
 
92
        """
 
93
 
87
94
        # mutter('    revision {%s}' % rev_id)
88
95
        branch = self.branch
89
96
        rev = branch.get_revision(rev_id)
118
125
            missing_inventory_sha_cnt += 1
119
126
            mutter("no inventory_sha1 on revision {%s}" % rev_id)
120
127
 
121
 
        tree = branch.revision_tree(rev_id)
 
128
        self._check_revision_tree(rev_id)
 
129
 
 
130
    def _check_revision_tree(self, rev_id):
 
131
        tree = self.branch.revision_tree(rev_id)
122
132
        inv = tree.inventory
123
133
        seen_ids = {}
124
 
        seen_names = {}
125
 
 
126
 
        ## p('revision %d/%d file ids' % (revno, revcount))
127
134
        for file_id in inv:
128
135
            if file_id in seen_ids:
129
136
                raise BzrCheckError('duplicated file_id {%s} '
130
137
                                    'in inventory for revision {%s}'
131
138
                                    % (file_id, rev_id))
132
139
            seen_ids[file_id] = True
133
 
 
134
 
        i = 0
135
140
        for file_id in inv:
136
 
            i += 1
137
 
            if i & 31 == 0:
138
 
                self.progress.tick()
139
 
 
140
 
            ie = inv[file_id]
141
 
 
142
 
            if ie.parent_id != None:
143
 
                if ie.parent_id not in seen_ids:
144
 
                    raise BzrCheckError('missing parent {%s} in inventory for revision {%s}'
145
 
                            % (ie.parent_id, rev_id))
146
 
 
147
 
            if ie.kind == 'file':
148
 
                text = tree.get_file_text(file_id)
149
 
                self.checked_text_cnt += 1 
150
 
                if ie.text_size != len(text):
151
 
                    raise BzrCheckError('text {%s} wrong size' % ie.text_id)
152
 
                if ie.text_sha1 != sha_string(text):
153
 
                    raise BzrCheckError('text {%s} wrong sha1' % ie.text_id)
154
 
            elif ie.kind == 'directory':
155
 
                if ie.text_sha1 != None or ie.text_size != None or ie.text_id != None:
156
 
                    raise BzrCheckError('directory {%s} has text in revision {%s}'
157
 
                            % (file_id, rev_id))
158
 
 
159
 
        self.progress.tick()
 
141
            self._check_one_entry(rev_id, inv, tree, file_id)
 
142
        seen_names = {}
160
143
        for path, ie in inv.iter_entries():
161
144
            if path in seen_names:
162
145
                raise BzrCheckError('duplicated path %s '
163
146
                                    'in inventory for revision {%s}'
164
147
                                    % (path, rev_id))
165
148
            seen_names[path] = True
166
 
        
 
149
 
 
150
        
 
151
    def _check_one_entry(self, rev_id, inv, tree, file_id):
 
152
        ie = inv[file_id]
 
153
        if ie.parent_id != None:
 
154
            if not inv.has_id(ie.parent_id):
 
155
                raise BzrCheckError('missing parent {%s} in inventory for revision {%s}'
 
156
                        % (ie.parent_id, rev_id))
 
157
        if ie.kind == 'file':
 
158
            text = tree.get_file_text(file_id)
 
159
            self.checked_text_cnt += 1 
 
160
            if ie.text_size != len(text):
 
161
                raise BzrCheckError('text {%s} wrong size' % ie.text_id)
 
162
            if ie.text_sha1 != sha_string(text):
 
163
                raise BzrCheckError('text {%s} wrong sha1' % ie.text_id)
 
164
        elif ie.kind == 'directory':
 
165
            if ie.text_sha1 != None or ie.text_size != None or ie.text_id != None:
 
166
                raise BzrCheckError('directory {%s} has text in revision {%s}'
 
167
                        % (file_id, rev_id))
 
168
        elif ie.kind == 'root_directory':
 
169
            pass
 
170
        else:
 
171
            raise BzrCheckError('unknown entry kind %r in revision {%s}' % 
 
172
                                (ie.kind, rev_id))
167
173
 
168
174
 
169
175
def check(branch):