29
29
from bzrlib import inventory
30
30
from bzrlib.revision import NULL_REVISION
32
FORMAT_1 = 'bzr inventory delta v1 (bzr 1.14)'
33
34
def _directory_content(entry):
34
35
"""Serialize the content component of entry which is a directory.
118
119
class InventoryDeltaSerializer(object):
119
"""Serialize and deserialize inventory deltas."""
121
# XXX: really, the serializer and deserializer should be two separate
124
FORMAT_1 = 'bzr inventory delta v1 (bzr 1.14)'
127
"""Create an InventoryDeltaSerializer."""
128
self._versioned_root = None
129
self._tree_references = None
120
"""Serialize inventory deltas."""
122
def __init__(self, versioned_root, tree_references):
123
"""Create an InventoryDeltaSerializer.
125
:param versioned_root: If True, any root entry that is seen is expected
126
to be versioned, and root entries can have any fileid.
127
:param tree_references: If True support tree-reference entries.
129
self._versioned_root = versioned_root
130
self._tree_references = tree_references
130
131
self._entry_to_content = {
131
132
'directory': _directory_content,
132
133
'file': _file_content,
133
134
'symlink': _link_content,
136
def require_flags(self, versioned_root=None, tree_references=None):
137
"""Set the versioned_root and/or tree_references flags for this
140
:param versioned_root: If True, any root entry that is seen is expected
141
to be versioned, and root entries can have any fileid.
142
:param tree_references: If True support tree-reference entries.
144
if versioned_root is not None and self._versioned_root is not None:
145
raise AssertionError(
146
"require_flags(versioned_root=...) already called.")
147
if tree_references is not None and self._tree_references is not None:
148
raise AssertionError(
149
"require_flags(tree_references=...) already called.")
150
self._versioned_root = versioned_root
151
self._tree_references = tree_references
152
136
if tree_references:
153
137
self._entry_to_content['tree-reference'] = _reference_content
184
168
'to_line generated non-str output %r' % lines[-1])
185
169
lines.append(line)
187
lines[0] = "format: %s\n" % InventoryDeltaSerializer.FORMAT_1
171
lines[0] = "format: %s\n" % FORMAT_1
188
172
lines[1] = "parent: %s\n" % old_name
189
173
lines[2] = "version: %s\n" % new_name
190
174
lines[3] = "versioned_root: %s\n" % self._serialize_bool(
244
228
(oldpath_utf8, newpath_utf8, file_id, parent_id, last_modified,
232
class InventoryDeltaDeserializer(object):
233
"""Deserialize inventory deltas."""
236
"""Create an InventoryDeltaDeserializer."""
237
self._versioned_root = None
238
self._tree_references = None
240
def require_flags(self, versioned_root=None, tree_references=None):
241
"""Set the versioned_root and/or tree_references flags for this
244
:param versioned_root: If True, any root entry that is seen is expected
245
to be versioned, and root entries can have any fileid.
246
:param tree_references: If True support tree-reference entries.
248
if versioned_root is not None and self._versioned_root is not None:
249
raise AssertionError(
250
"require_flags(versioned_root=...) already called.")
251
if tree_references is not None and self._tree_references is not None:
252
raise AssertionError(
253
"require_flags(tree_references=...) already called.")
254
self._versioned_root = versioned_root
255
self._tree_references = tree_references
247
257
def _deserialize_bool(self, value):
248
258
if value == "true":
268
278
last_line = bytes.rsplit('\n', 1)[-1]
269
279
raise errors.BzrError('last line not empty: %r' % (last_line,))
270
280
lines = bytes.split('\n')[:-1] # discard the last empty line
271
if not lines or lines[0] != 'format: %s' % InventoryDeltaSerializer.FORMAT_1:
281
if not lines or lines[0] != 'format: %s' % FORMAT_1:
272
282
raise errors.BzrError('unknown format %r' % lines[0:1])
273
283
if len(lines) < 2 or not lines[1].startswith('parent: '):
274
284
raise errors.BzrError('missing parent: marker')