/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: Jelmer Vernooij
  • Date: 2019-01-02 18:49:15 UTC
  • mto: This revision was merged to the branch mainline in revision 7235.
  • Revision ID: jelmer@jelmer.uk-20190102184915-0da9k4jk49kql994
Fix import for git-objects.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 bzrlib import (
 
17
from __future__ import absolute_import
 
18
 
 
19
from .. import (
18
20
    cache_utf8,
19
21
    errors,
 
22
    osutils,
 
23
    )
 
24
from . import (
20
25
    inventory,
21
26
    xml6,
22
 
    xml8,
23
 
    )
 
27
    )
 
28
from .xml_serializer import (
 
29
    encode_and_escape,
 
30
    get_utf8_or_ascii,
 
31
    unpack_inventory_entry,
 
32
    )
 
33
 
24
34
 
25
35
class Serializer_v5(xml6.Serializer_v6):
26
36
    """Version 5 serializer
27
37
 
28
38
    Packs objects into XML and vice versa.
29
39
    """
30
 
    format_num = '5'
 
40
    format_num = b'5'
31
41
    root_id = inventory.ROOT_ID
32
42
 
33
43
    def _unpack_inventory(self, elt, revision_id, entry_cache=None,
35
45
        """Construct from XML Element
36
46
        """
37
47
        root_id = elt.get('file_id') or inventory.ROOT_ID
38
 
        root_id = xml8._get_utf8_or_ascii(root_id)
 
48
        root_id = get_utf8_or_ascii(root_id)
39
49
 
40
50
        format = elt.get('format')
41
51
        if format is not None:
52
62
        #   avoiding attributes     2.46s
53
63
        #   adding assertions       2.50s
54
64
        #   last_parent cache       2.52s (worse, removed)
55
 
        unpack_entry = self._unpack_entry
56
65
        byid = inv._byid
57
66
        for e in elt:
58
 
            ie = unpack_entry(e, entry_cache=entry_cache,
59
 
                              return_from_cache=return_from_cache)
 
67
            ie = unpack_inventory_entry(e, entry_cache=entry_cache,
 
68
                                        return_from_cache=return_from_cache)
60
69
            parent_id = ie.parent_id
61
70
            if parent_id is None:
62
71
                ie.parent_id = parent_id = root_id
69
78
                raise errors.DuplicateFileId(ie.file_id,
70
79
                                             byid[ie.file_id])
71
80
            if ie.name in parent.children:
72
 
                raise errors.BzrError("%s is already versioned"
73
 
                    % (osutils.pathjoin(inv.id2path(parent_id),
74
 
                       ie.name).encode('utf-8'),))
 
81
                raise errors.BzrError(
 
82
                    "%s is already versioned" % (
 
83
                        osutils.pathjoin(
 
84
                            inv.id2path(parent_id), ie.name).encode('utf-8'),))
75
85
            parent.children[ie.name] = ie
76
86
            byid[ie.file_id] = ie
77
87
        if revision_id is not None:
91
101
    def _append_inventory_root(self, append, inv):
92
102
        """Append the inventory root to output."""
93
103
        if inv.root.file_id not in (None, inventory.ROOT_ID):
94
 
            fileid1 = ' file_id="'
95
 
            fileid2 = xml8._encode_and_escape(inv.root.file_id)
 
104
            fileid1 = b' file_id="'
 
105
            fileid2 = encode_and_escape(inv.root.file_id)
96
106
        else:
97
 
            fileid1 = ""
98
 
            fileid2 = ""
 
107
            fileid1 = b""
 
108
            fileid2 = b""
99
109
        if inv.revision_id is not None:
100
 
            revid1 = ' revision_id="'
101
 
            revid2 = xml8._encode_and_escape(inv.revision_id)
 
110
            revid1 = b' revision_id="'
 
111
            revid2 = encode_and_escape(inv.revision_id)
102
112
        else:
103
 
            revid1 = ""
104
 
            revid2 = ""
105
 
        append('<inventory%s%s format="5"%s%s>\n' % (
 
113
            revid1 = b""
 
114
            revid2 = b""
 
115
        append(b'<inventory%s%s format="5"%s%s>\n' % (
106
116
            fileid1, fileid2, revid1, revid2))
107
117
 
108
118