~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/check.py

  • Committer: Aaron Bentley
  • Date: 2005-10-04 04:32:32 UTC
  • mfrom: (1185.12.6)
  • mto: (1185.12.13)
  • mto: This revision was merged to the branch mainline in revision 1419.
  • Revision ID: aaron.bentley@utoronto.ca-20051004043231-40302a149769263b
merged my own changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 
29
29
import bzrlib.ui
30
30
from bzrlib.trace import note, warning
31
 
from bzrlib.osutils import rename, sha_string, fingerprint_file, sha_strings
 
31
from bzrlib.osutils import rename, sha_string, fingerprint_file
32
32
from bzrlib.trace import mutter
33
33
from bzrlib.errors import BzrCheckError, NoSuchRevision
34
34
from bzrlib.inventory import ROOT_ID
148
148
                                    % (file_id, rev_id))
149
149
            seen_ids[file_id] = True
150
150
        for file_id in inv:
151
 
            self._check_one_entry(rev_id, inv, tree, file_id)
 
151
            ie = inv[file_id]
 
152
            ie.check(self, rev_id, inv, tree)
152
153
        seen_names = {}
153
154
        for path, ie in inv.iter_entries():
154
155
            if path in seen_names:
157
158
                                    % (path, rev_id))
158
159
            seen_names[path] = True
159
160
 
160
 
        
161
 
    def _check_one_entry(self, rev_id, inv, tree, file_id):
162
 
        ie = inv[file_id]
163
 
        if ie.parent_id != None:
164
 
            if not inv.has_id(ie.parent_id):
165
 
                raise BzrCheckError('missing parent {%s} in inventory for revision {%s}'
166
 
                        % (ie.parent_id, rev_id))
167
 
        if ie.kind == 'file':
168
 
            text_version = ie.text_version
169
 
            t = (file_id, text_version)
170
 
            if t in self.checked_texts:
171
 
                prev_sha = self.checked_texts[t] 
172
 
                if prev_sha != ie.text_sha1:
173
 
                    raise BzrCheckError('mismatched sha1 on {%s} in {%s}' %
174
 
                                        (file_id, rev_id))
175
 
                else:
176
 
                    self.repeated_text_cnt += 1
177
 
                    return
178
 
            mutter('check version {%s} of {%s}', rev_id, file_id)
179
 
            file_lines = tree.get_file_lines(file_id)
180
 
            self.checked_text_cnt += 1 
181
 
            if ie.text_size != sum(map(len, file_lines)):
182
 
                raise BzrCheckError('text {%s} wrong size' % ie.text_id)
183
 
            if ie.text_sha1 != sha_strings(file_lines):
184
 
                raise BzrCheckError('text {%s} wrong sha1' % ie.text_id)
185
 
            self.checked_texts[t] = ie.text_sha1
186
 
        elif ie.kind == 'directory':
187
 
            if ie.text_sha1 != None or ie.text_size != None or ie.text_id != None:
188
 
                raise BzrCheckError('directory {%s} has text in revision {%s}'
189
 
                        % (file_id, rev_id))
190
 
        elif ie.kind == 'root_directory':
191
 
            pass
192
 
        else:
193
 
            raise BzrCheckError('unknown entry kind %r in revision {%s}' % 
194
 
                                (ie.kind, rev_id))
195
 
 
196
161
 
197
162
def check(branch):
198
163
    """Run consistency checks on a branch."""