~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/xml5.py

  • Committer: Alexander Belchenko
  • Date: 2007-02-17 07:11:47 UTC
  • mto: This revision was merged to the branch mainline in revision 2304.
  • Revision ID: bialix@ukr.net-20070217071147-pc4zm6d4rc8zqv77
Bugfix #85599: ``bzr init`` works with unicode argument LOCATION

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
2
2
#
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
19
19
 
20
20
from bzrlib import (
21
21
    cache_utf8,
22
 
    errors,
23
22
    inventory,
24
23
    )
25
24
from bzrlib.xml_serializer import SubElement, Element, Serializer
149
148
    # This format supports the altered-by hack that reads file ids directly out
150
149
    # of the versionedfile, without doing XML parsing.
151
150
 
152
 
    supported_kinds = set(['file', 'directory', 'symlink'])
153
 
 
154
151
    def write_inventory_to_string(self, inv):
155
152
        """Just call write_inventory with a StringIO and return the value"""
156
153
        sio = cStringIO.StringIO()
193
190
    def _append_entry(self, append, ie):
194
191
        """Convert InventoryEntry to XML element and append to output."""
195
192
        # TODO: should just be a plain assertion
196
 
        if ie.kind not in self.supported_kinds:
197
 
            raise errors.UnsupportedInventoryKind(ie.kind)
 
193
        assert InventoryEntry.versionable_kind(ie.kind), \
 
194
            'unsupported entry kind %s' % ie.kind
198
195
 
199
196
        append("<")
200
197
        append(ie.kind)
220
217
            append('"')
221
218
        if ie.text_size is not None:
222
219
            append(' text_size="%d"' % ie.text_size)
223
 
        if getattr(ie, 'reference_revision', None) is not None:
224
 
            append(' reference_revision="')
225
 
            append(_encode_and_escape(ie.reference_revision))
226
220
        append(" />\n")
227
221
        return
228
222
 
281
275
        """
282
276
        assert elt.tag == 'inventory'
283
277
        root_id = elt.get('file_id') or ROOT_ID
284
 
        root_id = _get_utf8_or_ascii(root_id)
285
 
 
286
278
        format = elt.get('format')
287
279
        if format is not None:
288
280
            if format != '5':
294
286
        inv = Inventory(root_id, revision_id=revision_id)
295
287
        for e in elt:
296
288
            ie = self._unpack_entry(e)
297
 
            if ie.parent_id is None:
 
289
            if ie.parent_id == ROOT_ID:
298
290
                ie.parent_id = root_id
299
291
            inv.add(ie)
300
292
        return inv
301
293
 
302
 
    def _unpack_entry(self, elt):
 
294
    def _unpack_entry(self, elt, none_parents=False):
303
295
        kind = elt.tag
304
296
        if not InventoryEntry.versionable_kind(kind):
305
297
            raise AssertionError('unsupported entry kind %s' % kind)
307
299
        get_cached = _get_utf8_or_ascii
308
300
 
309
301
        parent_id = elt.get('parent_id')
310
 
        if parent_id is not None:
311
 
            parent_id = get_cached(parent_id)
312
 
        file_id = get_cached(elt.get('file_id'))
 
302
        if parent_id is None and not none_parents:
 
303
            parent_id = ROOT_ID
 
304
        # TODO: jam 20060817 At present, caching file ids costs us too 
 
305
        #       much time. It slows down overall read performances from
 
306
        #       approx 500ms to 700ms. And doesn't improve future reads.
 
307
        #       it might be because revision ids and file ids are mixing.
 
308
        #       Consider caching *just* the file ids, for a limited period
 
309
        #       of time.
 
310
        #parent_id = get_cached(parent_id)
 
311
        #file_id = get_cached(elt.get('file_id'))
 
312
        file_id = elt.get('file_id')
313
313
 
314
314
        if kind == 'directory':
315
315
            ie = inventory.InventoryDirectory(file_id,
330
330
                                         parent_id)
331
331
            ie.symlink_target = elt.get('symlink_target')
332
332
        else:
333
 
            raise errors.UnsupportedInventoryKind(kind)
 
333
            raise BzrError("unknown kind %r" % kind)
334
334
        revision = elt.get('revision')
335
335
        if revision is not None:
336
336
            revision = get_cached(revision)