~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/xml8.py

  • Committer: Robert Collins
  • Date: 2010-05-06 07:48:22 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506074822-0bsgf2j4h8jx0xkk
Added ``bzrlib.tests.matchers`` as a place to put matchers, along with
our first in-tree matcher. See the module docstring for details.
(Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
 
1
# Copyright (C) 2005-2010 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
28
28
    Element,
29
29
    SubElement,
30
30
    XMLSerializer,
 
31
    escape_invalid_chars,
31
32
    )
32
 
from bzrlib.inventory import ROOT_ID, Inventory, InventoryEntry
 
33
from bzrlib.inventory import InventoryEntry
33
34
from bzrlib.revision import Revision
34
35
from bzrlib.errors import BzrError
35
36
 
167
168
        :raises: AssertionError if an error has occurred.
168
169
        """
169
170
        if inv.revision_id is None:
170
 
            raise AssertionError()
 
171
            raise AssertionError("inv.revision_id is None")
171
172
        if inv.root.revision is None:
172
 
            raise AssertionError()
 
173
            raise AssertionError("inv.root.revision is None")
173
174
 
174
175
    def _check_cache_size(self, inv_size, entry_cache):
175
176
        """Check that the entry_cache is large enough.
345
346
            root.set('timezone', str(rev.timezone))
346
347
        root.text = '\n'
347
348
        msg = SubElement(root, 'message')
348
 
        msg.text = rev.message
 
349
        msg.text = escape_invalid_chars(rev.message)[0]
349
350
        msg.tail = '\n'
350
351
        if rev.parent_ids:
351
352
            pelts = SubElement(root, 'parents')
370
371
            prop_elt.tail = '\n'
371
372
        top_elt.tail = '\n'
372
373
 
373
 
    def _unpack_inventory(self, elt, revision_id=None, entry_cache=None):
 
374
    def _unpack_inventory(self, elt, revision_id=None, entry_cache=None,
 
375
                          return_from_cache=False):
374
376
        """Construct from XML Element"""
375
377
        if elt.tag != 'inventory':
376
378
            raise errors.UnexpectedInventoryFormat('Root tag is %r' % elt.tag)
383
385
            revision_id = cache_utf8.encode(revision_id)
384
386
        inv = inventory.Inventory(root_id=None, revision_id=revision_id)
385
387
        for e in elt:
386
 
            ie = self._unpack_entry(e, entry_cache=entry_cache)
 
388
            ie = self._unpack_entry(e, entry_cache=entry_cache,
 
389
                                    return_from_cache=return_from_cache)
387
390
            inv.add(ie)
388
391
        self._check_cache_size(len(inv), entry_cache)
389
392
        return inv
390
393
 
391
 
    def _unpack_entry(self, elt, entry_cache=None):
 
394
    def _unpack_entry(self, elt, entry_cache=None, return_from_cache=False):
392
395
        elt_get = elt.get
393
396
        file_id = elt_get('file_id')
394
397
        revision = elt_get('revision')
432
435
                pass
433
436
            else:
434
437
                # Only copying directory entries drops us 2.85s => 2.35s
435
 
                # if cached_ie.kind == 'directory':
436
 
                #     return cached_ie.copy()
437
 
                # return cached_ie
 
438
                if return_from_cache:
 
439
                    if cached_ie.kind == 'directory':
 
440
                        return cached_ie.copy()
 
441
                    return cached_ie
438
442
                return cached_ie.copy()
439
443
 
440
444
        kind = elt.tag