/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/bzr/xml5.py

  • Committer: Robert Collins
  • Date: 2007-04-19 02:27:44 UTC
  • mto: This revision was merged to the branch mainline in revision 2426.
  • Revision ID: robertc@robertcollins.net-20070419022744-pfdqz42kp1wizh43
``make docs`` now creates a man page at ``man1/bzr.1`` fixing bug 107388.
(Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
2
 
#
3
 
# This program is free software; you can redistribute it and/or modify
4
 
# it under the terms of the GNU General Public License as published by
5
 
# the Free Software Foundation; either version 2 of the License, or
6
 
# (at your option) any later version.
7
 
#
8
 
# This program is distributed in the hope that it will be useful,
9
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
# GNU General Public License for more details.
12
 
#
13
 
# You should have received a copy of the GNU General Public License
14
 
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
from .. import (
18
 
    cache_utf8,
19
 
    errors,
20
 
    osutils,
21
 
    )
22
 
from . import (
23
 
    inventory,
24
 
    xml6,
25
 
    )
26
 
from .xml_serializer import (
27
 
    encode_and_escape,
28
 
    get_utf8_or_ascii,
29
 
    unpack_inventory_entry,
30
 
    )
31
 
 
32
 
 
33
 
class Serializer_v5(xml6.Serializer_v6):
34
 
    """Version 5 serializer
35
 
 
36
 
    Packs objects into XML and vice versa.
37
 
    """
38
 
    format_num = b'5'
39
 
    root_id = inventory.ROOT_ID
40
 
 
41
 
    def _unpack_inventory(self, elt, revision_id, entry_cache=None,
42
 
                          return_from_cache=False):
43
 
        """Construct from XML Element
44
 
        """
45
 
        root_id = elt.get('file_id') or inventory.ROOT_ID
46
 
        root_id = get_utf8_or_ascii(root_id)
47
 
 
48
 
        format = elt.get('format')
49
 
        if format is not None:
50
 
            if format != '5':
51
 
                raise errors.BzrError("invalid format version %r on inventory"
52
 
                                      % format)
53
 
        data_revision_id = elt.get('revision_id')
54
 
        if data_revision_id is not None:
55
 
            revision_id = cache_utf8.encode(data_revision_id)
56
 
        inv = inventory.Inventory(root_id, revision_id=revision_id)
57
 
        # Optimizations tested
58
 
        #   baseline w/entry cache  2.85s
59
 
        #   using inv._byid         2.55s
60
 
        #   avoiding attributes     2.46s
61
 
        #   adding assertions       2.50s
62
 
        #   last_parent cache       2.52s (worse, removed)
63
 
        byid = inv._byid
64
 
        for e in elt:
65
 
            ie = unpack_inventory_entry(e, entry_cache=entry_cache,
66
 
                                        return_from_cache=return_from_cache)
67
 
            parent_id = ie.parent_id
68
 
            if parent_id is None:
69
 
                ie.parent_id = parent_id = root_id
70
 
            try:
71
 
                parent = byid[parent_id]
72
 
            except KeyError:
73
 
                raise errors.BzrError("parent_id {%s} not in inventory"
74
 
                                      % (parent_id,))
75
 
            if ie.file_id in byid:
76
 
                raise inventory.DuplicateFileId(ie.file_id, byid[ie.file_id])
77
 
            if ie.name in parent.children:
78
 
                raise errors.BzrError(
79
 
                    "%s is already versioned" % (
80
 
                        osutils.pathjoin(
81
 
                            inv.id2path(parent_id), ie.name).encode('utf-8'),))
82
 
            parent.children[ie.name] = ie
83
 
            byid[ie.file_id] = ie
84
 
        if revision_id is not None:
85
 
            inv.root.revision = revision_id
86
 
        self._check_cache_size(len(inv), entry_cache)
87
 
        return inv
88
 
 
89
 
    def _check_revisions(self, inv):
90
 
        """Extension point for subclasses to check during serialisation.
91
 
 
92
 
        In this version, no checking is done.
93
 
 
94
 
        :param inv: An inventory about to be serialised, to be checked.
95
 
        :raises: AssertionError if an error has occurred.
96
 
        """
97
 
 
98
 
    def _append_inventory_root(self, append, inv):
99
 
        """Append the inventory root to output."""
100
 
        if inv.root.file_id not in (None, inventory.ROOT_ID):
101
 
            fileid = b''.join([b' file_id="', encode_and_escape(inv.root.file_id), b'"'])
102
 
        else:
103
 
            fileid = b""
104
 
        if inv.revision_id is not None:
105
 
            revid = b''.join([b' revision_id="', encode_and_escape(inv.revision_id), b'"'])
106
 
        else:
107
 
            revid = b""
108
 
        append(b'<inventory%s format="5"%s>\n' % (fileid, revid))
109
 
 
110
 
 
111
 
serializer_v5 = Serializer_v5()