~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/xml5.py

  • Committer: John Arbash Meinel
  • Date: 2006-08-10 01:30:06 UTC
  • mto: This revision was merged to the branch mainline in revision 1926.
  • Revision ID: john@arbash-meinel.com-20060810013006-85a7758a1e69228c
Cache revision ids and file ids as part of xml processing. A custom xml parser could just call decode/encode directly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
 
18
from bzrlib import (
 
19
    cache_utf8,
 
20
    )
18
21
from bzrlib.xml_serializer import SubElement, Element, Serializer
19
22
from bzrlib.inventory import ROOT_ID, Inventory, InventoryEntry
20
23
import bzrlib.inventory as inventory
125
128
                raise BzrError("invalid format version %r on inventory"
126
129
                                % format)
127
130
        revision_id = elt.get('revision_id')
 
131
        if revision_id is not None:
 
132
            revision_id = cache_utf8.get_cached_unicode(revision_id)
128
133
        inv = Inventory(root_id, revision_id=revision_id)
129
134
        for e in elt:
130
135
            ie = self._unpack_entry(e)
139
144
        if not InventoryEntry.versionable_kind(kind):
140
145
            raise AssertionError('unsupported entry kind %s' % kind)
141
146
 
 
147
        get_cached = cache_utf8.get_cached_unicode
 
148
 
142
149
        parent_id = elt.get('parent_id')
143
150
        if parent_id == None:
144
151
            parent_id = ROOT_ID
 
152
        parent_id = get_cached(parent_id)
 
153
        file_id = get_cached(elt.get('file_id'))
145
154
 
146
155
        if kind == 'directory':
147
 
            ie = inventory.InventoryDirectory(elt.get('file_id'),
 
156
            ie = inventory.InventoryDirectory(file_id,
148
157
                                              elt.get('name'),
149
158
                                              parent_id)
150
159
        elif kind == 'file':
151
 
            ie = inventory.InventoryFile(elt.get('file_id'),
 
160
            ie = inventory.InventoryFile(file_id,
152
161
                                         elt.get('name'),
153
162
                                         parent_id)
154
163
            ie.text_sha1 = elt.get('text_sha1')
157
166
            v = elt.get('text_size')
158
167
            ie.text_size = v and int(v)
159
168
        elif kind == 'symlink':
160
 
            ie = inventory.InventoryLink(elt.get('file_id'),
 
169
            ie = inventory.InventoryLink(file_id,
161
170
                                         elt.get('name'),
162
171
                                         parent_id)
163
172
            ie.symlink_target = elt.get('symlink_target')
164
173
        else:
165
174
            raise BzrError("unknown kind %r" % kind)
166
 
        ie.revision = elt.get('revision')
 
175
        revision = elt.get('revision')
 
176
        if revision is not None:
 
177
            revision = get_cached(revision)
 
178
        ie.revision = revision
167
179
 
168
180
        return ie
169
181
 
176
188
            if format != '5':
177
189
                raise BzrError("invalid format version %r on inventory"
178
190
                                % format)
 
191
        get_cached = cache_utf8.get_cached_unicode
179
192
        rev = Revision(committer = elt.get('committer'),
180
193
                       timestamp = float(elt.get('timestamp')),
181
 
                       revision_id = elt.get('revision_id'),
 
194
                       revision_id = get_cached(elt.get('revision_id')),
182
195
                       inventory_sha1 = elt.get('inventory_sha1')
183
196
                       )
184
197
        parents = elt.find('parents') or []
185
198
        for p in parents:
186
199
            assert p.tag == 'revision_ref', \
187
200
                   "bad parent node tag %r" % p.tag
188
 
            rev.parent_ids.append(p.get('revision_id'))
 
201
            rev.parent_ids.append(get_cached(p.get('revision_id')))
189
202
        self._unpack_revision_properties(elt, rev)
190
203
        v = elt.get('timezone')
191
204
        rev.timezone = v and int(v)