1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
1
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
138
138
_to_escaped_map.clear()
141
class Serializer_v5(Serializer):
142
"""Version 5 serializer
141
class Serializer_v8(Serializer):
142
"""This serialiser adds rich roots.
144
Packs objects into XML and vice versa.
144
Its revision format number matches its inventory number.
150
150
support_altered_by_hack = True
151
151
# This format supports the altered-by hack that reads file ids directly out
152
152
# of the versionedfile, without doing XML parsing.
154
154
supported_kinds = set(['file', 'directory', 'symlink'])
156
156
revision_format_num = None
158
158
def _check_revisions(self, inv):
163
163
:param inv: An inventory about to be serialised, to be checked.
164
164
:raises: AssertionError if an error has occured.
166
assert inv.revision_id is not None
167
assert inv.root.revision is not None
167
169
def write_inventory_to_lines(self, inv):
168
170
"""Return a list of lines with the encoded inventory."""
275
277
def _append_inventory_root(self, append, inv):
276
278
"""Append the inventory root to output."""
277
if inv.root.file_id not in (None, ROOT_ID):
278
fileid1 = ' file_id="'
279
fileid2 = _encode_and_escape(inv.root.file_id)
283
279
if inv.revision_id is not None:
284
280
revid1 = ' revision_id="'
285
281
revid2 = _encode_and_escape(inv.revision_id)
289
append('<inventory%s%s format="5"%s%s>\n' % (
290
fileid1, fileid2, revid1, revid2))
285
append('<inventory format="%s"%s%s>\n' % (
286
self.format_num, revid1, revid2))
287
append('<directory file_id="%s name="%s revision="%s />\n' % (
288
_encode_and_escape(inv.root.file_id),
289
_encode_and_escape(inv.root.name),
290
_encode_and_escape(inv.root.revision)))
292
292
def _pack_revision(self, rev):
293
293
"""Revision object -> xml tree"""
294
294
# For the XML format, we need to write them as Unicode rather than as
340
340
prop_elt.tail = '\n'
341
341
top_elt.tail = '\n'
343
def _unpack_inventory(self, elt, revision_id):
344
"""Construct from XML Element
346
assert elt.tag == 'inventory'
347
root_id = elt.get('file_id') or ROOT_ID
348
root_id = _get_utf8_or_ascii(root_id)
343
def _unpack_inventory(self, elt, revision_id=None):
344
"""Construct from XML Element"""
345
if elt.tag != 'inventory':
346
raise errors.UnexpectedInventoryFormat('Root tag is %r' % elt.tag)
350
347
format = elt.get('format')
351
if format is not None:
353
raise BzrError("invalid format version %r on inventory"
355
data_revision_id = elt.get('revision_id')
356
if data_revision_id is not None:
357
revision_id = cache_utf8.encode(data_revision_id)
358
inv = Inventory(root_id, revision_id=revision_id)
348
if format != self.format_num:
349
raise errors.UnexpectedInventoryFormat('Invalid format version %r'
351
revision_id = elt.get('revision_id')
352
if revision_id is not None:
353
revision_id = cache_utf8.encode(revision_id)
354
inv = inventory.Inventory(root_id=None, revision_id=revision_id)
360
356
ie = self._unpack_entry(e)
361
if ie.parent_id is None:
362
ie.parent_id = root_id
364
if revision_id is not None:
365
inv.root.revision = revision_id
358
assert inv.root.revision is not None
368
361
def _unpack_entry(self, elt):