~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/weave.py

Adding sha1 check when weave extracts a text.

Show diffs side-by-side

added added

removed removed

Lines of Context:
71
71
from difflib import SequenceMatcher
72
72
 
73
73
from bzrlib.trace import mutter
74
 
from bzrlib.errors import WeaveError, WeaveFormatError, WeaveParentMismatch, \
75
 
        WeaveRevisionNotPresent, WeaveRevisionAlreadyPresent
 
74
from bzrlib.errors import (WeaveError, WeaveFormatError, WeaveParentMismatch,
 
75
        WeaveRevisionNotPresent, WeaveRevisionAlreadyPresent)
 
76
import bzrlib.errors as errors
76
77
from bzrlib.tsort import topo_sort
77
78
 
78
79
 
548
549
    def get_iter(self, name_or_index):
549
550
        """Yield lines for the specified version."""
550
551
        incls = [self.maybe_lookup(name_or_index)]
 
552
        if len(incls) == 1:
 
553
            index= incls[0]
 
554
            s = sha.new()
 
555
        else:
 
556
            # We don't have sha1 sums for multiple entries
 
557
            s = None
551
558
        for origin, lineno, line in self._extract(incls):
 
559
            if s:
 
560
                s.update(line)
552
561
            yield line
 
562
        if s:
 
563
            expected_sha1 = self._sha1s[index]
 
564
            measured_sha1 = s.hexdigest() 
 
565
            if measured_sha1 != expected_sha1:
 
566
                raise errors.WeaveInvalidChecksum(
 
567
                        'file %s, revision %s, expected: %s, measured %s' 
 
568
                        % (self._weave_name, self._names[index],
 
569
                           expected_sha1, measured_sha1))
553
570
 
554
571
 
555
572
    def get_text(self, name_or_index):