/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: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2020-08-23 01:15:41 UTC
  • mfrom: (7520.1.4 merge-3.1)
  • Revision ID: breezy.the.bot@gmail.com-20200823011541-nv0oh7nzaganx2qy
Merge lp:brz/3.1.

Merged from https://code.launchpad.net/~jelmer/brz/merge-3.1/+merge/389690

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