/breezy/trunk

To get this branch, use:
bzr branch https://code.breezy-vcs.org/breezy/trunk

« back to all changes in this revision

Viewing changes to breezy/bzr/weave.py

  • Committer: Jelmer Vernooij
  • Date: 2017-07-23 22:06:41 UTC
  • mfrom: (6738 trunk)
  • mto: This revision was merged to the branch mainline in revision 6739.
  • Revision ID: jelmer@jelmer.uk-20170723220641-69eczax9bmv8d6kk
Merge trunk, address review comments.

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
    errors,
78
78
    osutils,
79
79
    )
80
 
from ..errors import (WeaveError, WeaveFormatError, WeaveParentMismatch,
81
 
        RevisionAlreadyPresent,
82
 
        RevisionNotPresent,
83
 
        UnavailableRepresentation,
84
 
        )
 
80
from ..errors import (
 
81
    RevisionAlreadyPresent,
 
82
    RevisionNotPresent,
 
83
    UnavailableRepresentation,
 
84
    )
85
85
from ..osutils import dirname, sha, sha_strings, split_lines
86
86
from .. import patiencediff
87
87
from ..revision import NULL_REVISION
99
99
from .weavefile import _read_weave_v5, write_weave_v5
100
100
 
101
101
 
 
102
class WeaveError(errors.BzrError):
 
103
 
 
104
    _fmt = "Error in processing weave: %(msg)s"
 
105
 
 
106
    def __init__(self, msg=None):
 
107
        errors.BzrError.__init__(self)
 
108
        self.msg = msg
 
109
 
 
110
 
 
111
class WeaveRevisionAlreadyPresent(WeaveError):
 
112
 
 
113
    _fmt = "Revision {%(revision_id)s} already present in %(weave)s"
 
114
 
 
115
    def __init__(self, revision_id, weave):
 
116
 
 
117
        WeaveError.__init__(self)
 
118
        self.revision_id = revision_id
 
119
        self.weave = weave
 
120
 
 
121
 
 
122
class WeaveRevisionNotPresent(WeaveError):
 
123
 
 
124
    _fmt = "Revision {%(revision_id)s} not present in %(weave)s"
 
125
 
 
126
    def __init__(self, revision_id, weave):
 
127
        WeaveError.__init__(self)
 
128
        self.revision_id = revision_id
 
129
        self.weave = weave
 
130
 
 
131
 
 
132
class WeaveFormatError(WeaveError):
 
133
 
 
134
    _fmt = "Weave invariant violated: %(what)s"
 
135
 
 
136
    def __init__(self, what):
 
137
        WeaveError.__init__(self)
 
138
        self.what = what
 
139
 
 
140
 
 
141
class WeaveParentMismatch(WeaveError):
 
142
 
 
143
    _fmt = "Parents are mismatched between two revisions. %(msg)s"
 
144
 
 
145
 
 
146
class WeaveInvalidChecksum(WeaveError):
 
147
 
 
148
    _fmt = "Text did not match its checksum: %(msg)s"
 
149
 
 
150
 
 
151
class WeaveTextDiffers(WeaveError):
 
152
 
 
153
    _fmt = ("Weaves differ on text content. Revision:"
 
154
            " {%(revision_id)s}, %(weave_a)s, %(weave_b)s")
 
155
 
 
156
    def __init__(self, revision_id, weave_a, weave_b):
 
157
        WeaveError.__init__(self)
 
158
        self.revision_id = revision_id
 
159
        self.weave_a = weave_a
 
160
        self.weave_b = weave_b
 
161
 
 
162
 
 
163
class WeaveTextDiffers(WeaveError):
 
164
 
 
165
    _fmt = ("Weaves differ on text content. Revision:"
 
166
            " {%(revision_id)s}, %(weave_a)s, %(weave_b)s")
 
167
 
 
168
    def __init__(self, revision_id, weave_a, weave_b):
 
169
        WeaveError.__init__(self)
 
170
        self.revision_id = revision_id
 
171
        self.weave_a = weave_a
 
172
        self.weave_b = weave_b
 
173
 
 
174
 
102
175
class WeaveContentFactory(ContentFactory):
103
176
    """Content factory for streaming from weaves.
104
177
 
528
601
 
529
602
    def get_ancestry(self, version_ids, topo_sorted=True):
530
603
        """See VersionedFile.get_ancestry."""
531
 
        if isinstance(version_ids, basestring):
 
604
        if isinstance(version_ids, bytes):
532
605
            version_ids = [version_ids]
533
606
        i = self._inclusions([self._lookup(v) for v in version_ids])
534
607
        return [self._idx_to_name(v) for v in i]
535
608
 
536
 
    def _check_lines(self, text):
537
 
        if not isinstance(text, list):
538
 
            raise ValueError("text should be a list, not %s" % type(text))
539
 
 
540
 
        for l in text:
541
 
            if not isinstance(l, basestring):
542
 
                raise ValueError("text line should be a string or unicode, not %s"
543
 
                                 % type(l))
544
 
 
545
 
 
546
 
 
547
609
    def _check_versions(self, indexes):
548
610
        """Check everything in the sequence of indexes is valid"""
549
611
        for i in indexes:
762
824
        expected_sha1 = self._sha1s[int_index]
763
825
        measured_sha1 = sha_strings(result)
764
826
        if measured_sha1 != expected_sha1:
765
 
            raise errors.WeaveInvalidChecksum(
 
827
            raise WeaveInvalidChecksum(
766
828
                    'file %s, revision %s, expected: %s, measured %s'
767
829
                    % (self._weave_name, version_id,
768
830
                       expected_sha1, measured_sha1))
839
901
            hd = sha1s[version].hexdigest()
840
902
            expected = self._sha1s[i]
841
903
            if hd != expected:
842
 
                raise errors.WeaveInvalidChecksum(
 
904
                raise WeaveInvalidChecksum(
843
905
                        "mismatched sha1 for version %s: "
844
906
                        "got %s, expected %s"
845
907
                        % (version, hd, expected))
875
937
        this_idx = self._name_map.get(name, -1)
876
938
        if this_idx != -1:
877
939
            if self._sha1s[this_idx] != other._sha1s[other_idx]:
878
 
                raise errors.WeaveTextDiffers(name, self, other)
 
940
                raise WeaveTextDiffers(name, self, other)
879
941
            self_parents = self._parents[this_idx]
880
942
            other_parents = other._parents[other_idx]
881
943
            n1 = {self._names[i] for i in self_parents}
1010
1072
                    lines = list(difflib.unified_diff(lines, lines_b,
1011
1073
                            wa._weave_name, wb._weave_name))
1012
1074
                    mutter('lines:\n%s', ''.join(lines))
1013
 
                    raise errors.WeaveTextDiffers(name, wa, wb)
 
1075
                    raise WeaveTextDiffers(name, wa, wb)
1014
1076
        else:
1015
1077
            lines = wb.get_lines(name)
1016
1078
        wr._add(name, lines, [wr._lookup(i) for i in combined_parents[name]])