/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 bzrlib/xml5.py

  • Committer: John Ferlito
  • Date: 2009-09-02 04:31:45 UTC
  • mto: (4665.7.1 serve-init)
  • mto: This revision was merged to the branch mainline in revision 4913.
  • Revision ID: johnf@inodes.org-20090902043145-gxdsfw03ilcwbyn5
Add a debian init script for bzr --serve

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2008 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
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
from .. import (
 
17
from bzrlib import (
18
18
    cache_utf8,
19
19
    errors,
20
 
    osutils,
21
 
    )
22
 
from . import (
23
20
    inventory,
24
21
    xml6,
25
 
    )
26
 
from .xml_serializer import (
27
 
    encode_and_escape,
28
 
    get_utf8_or_ascii,
29
 
    unpack_inventory_entry,
30
 
    )
31
 
 
 
22
    xml8,
 
23
    )
32
24
 
33
25
class Serializer_v5(xml6.Serializer_v6):
34
26
    """Version 5 serializer
35
27
 
36
28
    Packs objects into XML and vice versa.
37
29
    """
38
 
    format_num = b'5'
 
30
    format_num = '5'
39
31
    root_id = inventory.ROOT_ID
40
32
 
41
 
    def _unpack_inventory(self, elt, revision_id, entry_cache=None,
42
 
                          return_from_cache=False):
 
33
    def _unpack_inventory(self, elt, revision_id, entry_cache=None):
43
34
        """Construct from XML Element
44
35
        """
45
36
        root_id = elt.get('file_id') or inventory.ROOT_ID
46
 
        root_id = get_utf8_or_ascii(root_id)
 
37
        root_id = xml8._get_utf8_or_ascii(root_id)
47
38
 
48
39
        format = elt.get('format')
49
40
        if format is not None:
60
51
        #   avoiding attributes     2.46s
61
52
        #   adding assertions       2.50s
62
53
        #   last_parent cache       2.52s (worse, removed)
 
54
        unpack_entry = self._unpack_entry
63
55
        byid = inv._byid
64
56
        for e in elt:
65
 
            ie = unpack_inventory_entry(e, entry_cache=entry_cache,
66
 
                                        return_from_cache=return_from_cache)
 
57
            ie = unpack_entry(e, entry_cache=entry_cache)
67
58
            parent_id = ie.parent_id
68
59
            if parent_id is None:
69
60
                ie.parent_id = parent_id = root_id
73
64
                raise errors.BzrError("parent_id {%s} not in inventory"
74
65
                                      % (parent_id,))
75
66
            if ie.file_id in byid:
76
 
                raise inventory.DuplicateFileId(ie.file_id, byid[ie.file_id])
 
67
                raise errors.DuplicateFileId(ie.file_id,
 
68
                                             byid[ie.file_id])
77
69
            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'),))
 
70
                raise errors.BzrError("%s is already versioned"
 
71
                    % (osutils.pathjoin(inv.id2path(parent_id),
 
72
                       ie.name).encode('utf-8'),))
82
73
            parent.children[ie.name] = ie
83
74
            byid[ie.file_id] = ie
84
75
        if revision_id is not None:
98
89
    def _append_inventory_root(self, append, inv):
99
90
        """Append the inventory root to output."""
100
91
        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'"'])
 
92
            fileid1 = ' file_id="'
 
93
            fileid2 = xml8._encode_and_escape(inv.root.file_id)
102
94
        else:
103
 
            fileid = b""
 
95
            fileid1 = ""
 
96
            fileid2 = ""
104
97
        if inv.revision_id is not None:
105
 
            revid = b''.join([b' revision_id="', encode_and_escape(inv.revision_id), b'"'])
 
98
            revid1 = ' revision_id="'
 
99
            revid2 = xml8._encode_and_escape(inv.revision_id)
106
100
        else:
107
 
            revid = b""
108
 
        append(b'<inventory%s format="5"%s>\n' % (fileid, revid))
 
101
            revid1 = ""
 
102
            revid2 = ""
 
103
        append('<inventory%s%s format="5"%s%s>\n' % (
 
104
            fileid1, fileid2, revid1, revid2))
109
105
 
110
106
 
111
107
serializer_v5 = Serializer_v5()