/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/chk_serializer.py

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
from __future__ import absolute_import
20
20
 
21
 
from .. import lazy_import
 
21
from cStringIO import StringIO
 
22
 
 
23
from bzrlib import lazy_import
22
24
lazy_import.lazy_import(globals(),
23
25
"""
24
 
from breezy.bzr import (
 
26
from bzrlib import (
25
27
    xml_serializer,
26
28
    )
27
29
""")
28
 
from .. import (
 
30
from bzrlib import (
29
31
    bencode,
30
32
    cache_utf8,
31
33
    errors,
32
34
    revision as _mod_revision,
33
 
    )
34
 
from . import (
35
35
    serializer,
36
36
    )
37
 
from ..sixish import (
38
 
    BytesIO,
39
 
    )
40
 
 
41
37
 
42
38
 
43
39
def _validate_properties(props, _decode=cache_utf8._utf8_decode):
44
40
    # TODO: we really want an 'isascii' check for key
45
41
    # Cast the utf8 properties into Unicode 'in place'
46
 
    for key, value in props.items():
 
42
    for key, value in props.iteritems():
47
43
        props[key] = _decode(value)[0]
48
44
    return props
49
45
 
84
80
        # This lets us control the ordering, so that we are able to create
85
81
        # smaller deltas
86
82
        ret = [
87
 
            (b"format", 10),
88
 
            (b"committer", encode_utf8(rev.committer)[0]),
 
83
            ("format", 10),
 
84
            ("committer", encode_utf8(rev.committer)[0]),
89
85
        ]
90
86
        if rev.timezone is not None:
91
 
            ret.append((b"timezone", rev.timezone))
 
87
            ret.append(("timezone", rev.timezone))
92
88
        # For bzr revisions, the most common property is just 'branch-nick'
93
89
        # which changes infrequently.
94
90
        revprops = {}
95
 
        for key, value in rev.properties.items():
96
 
            revprops[encode_utf8(key)[0]] = encode_utf8(value)[0]
97
 
        ret.append((b'properties', revprops))
 
91
        for key, value in rev.properties.iteritems():
 
92
            revprops[key] = encode_utf8(value)[0]
 
93
        ret.append(('properties', revprops))
98
94
        ret.extend([
99
 
            (b"timestamp", b"%.3f" % rev.timestamp),
100
 
            (b"revision-id", rev.revision_id),
101
 
            (b"parent-ids", rev.parent_ids),
102
 
            (b"inventory-sha1", rev.inventory_sha1),
103
 
            (b"message", encode_utf8(rev.message)[0]),
 
95
            ("timestamp", "%.3f" % rev.timestamp),
 
96
            ("revision-id", rev.revision_id),
 
97
            ("parent-ids", rev.parent_ids),
 
98
            ("inventory-sha1", rev.inventory_sha1),
 
99
            ("message", encode_utf8(rev.message)[0]),
104
100
        ])
105
101
        return bencode.bencode(ret)
106
102
 
113
109
        #       However, to decode all 25k revisions of bzr takes approx 1.3s
114
110
        #       If we remove all extra validation that goes down to about 1.2s.
115
111
        #       Of that time, probably 0.6s is spend in bencode.bdecode().
116
 
        #       Regardless 'time brz log' of everything is 7+s, so 1.3s to
 
112
        #       Regardless 'time bzr log' of everything is 7+s, so 1.3s to
117
113
        #       extract revision texts isn't a majority of time.
118
114
        ret = bencode.bdecode(text)
119
115
        if not isinstance(ret, list):
133
129
                value = validator(value)
134
130
            bits[var_name] = value
135
131
        if len(bits) != len(schema):
136
 
            missing = [key for key, (var_name, _, _) in schema.items()
 
132
            missing = [key for key, (var_name, _, _) in schema.iteritems()
137
133
                       if var_name not in bits]
138
134
            raise ValueError('Revision text was missing expected keys %s.'
139
135
                             ' text %r' % (missing, text))
151
147
    format_num = '9'
152
148
    revision_format_num = None
153
149
    support_altered_by_hack = False
154
 
    supported_kinds = {'file', 'directory', 'symlink', 'tree-reference'}
 
150
    supported_kinds = set(['file', 'directory', 'symlink', 'tree-reference'])
155
151
 
156
152
    def __init__(self, node_size, search_key_name):
157
153
        self.maximum_size = node_size
185
181
                xml_serializer.fromstring(xml_string), revision_id,
186
182
                entry_cache=entry_cache,
187
183
                return_from_cache=return_from_cache)
188
 
        except xml_serializer.ParseError as e:
 
184
        except xml_serializer.ParseError, e:
189
185
            raise errors.UnexpectedInventoryFormat(e)
190
186
 
191
187
    def read_inventory(self, f, revision_id=None):
196
192
                    revision_id=None)
197
193
            finally:
198
194
                f.close()
199
 
        except xml_serializer.ParseError as e:
 
195
        except xml_serializer.ParseError, e:
200
196
            raise errors.UnexpectedInventoryFormat(e)
201
197
 
202
198
    def write_inventory_to_lines(self, inv):
204
200
        return self.write_inventory(inv, None)
205
201
 
206
202
    def write_inventory_to_string(self, inv, working=False):
207
 
        """Just call write_inventory with a BytesIO and return the value.
 
203
        """Just call write_inventory with a StringIO and return the value.
208
204
 
209
205
        :param working: If True skip history data - text_sha1, text_size,
210
206
            reference_revision, symlink_target.
211
207
        """
212
 
        sio = BytesIO()
 
208
        sio = StringIO()
213
209
        self.write_inventory(inv, sio, working)
214
210
        return sio.getvalue()
215
211