19
19
from __future__ import absolute_import
21
from .. import lazy_import
21
from cStringIO import StringIO
23
from bzrlib import lazy_import
22
24
lazy_import.lazy_import(globals(),
24
from breezy.bzr import (
32
34
revision as _mod_revision,
37
from ..sixish import (
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]
84
80
# This lets us control the ordering, so that we are able to create
88
(b"committer", encode_utf8(rev.committer)[0]),
84
("committer", encode_utf8(rev.committer)[0]),
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.
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))
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]),
105
101
return bencode.bencode(ret)
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))
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'])
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)
191
187
def read_inventory(self, f, revision_id=None):
196
192
revision_id=None)
199
except xml_serializer.ParseError as e:
195
except xml_serializer.ParseError, e:
200
196
raise errors.UnexpectedInventoryFormat(e)
202
198
def write_inventory_to_lines(self, inv):
204
200
return self.write_inventory(inv, None)
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.
209
205
:param working: If True skip history data - text_sha1, text_size,
210
206
reference_revision, symlink_target.
213
209
self.write_inventory(inv, sio, working)
214
210
return sio.getvalue()