~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/xml5.py

merge from bzr.dev

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
83
86
                       inventory_sha1 = rev.inventory_sha1,
84
87
                       format='5',
85
88
                       )
86
 
        if rev.timezone:
 
89
        if rev.timezone is not None:
87
90
            root.set('timezone', str(rev.timezone))
88
91
        root.text = '\n'
89
92
        msg = SubElement(root, 'message')
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
 
        rev.timezone = v and int(v)
 
204
        if v is None:
 
205
            rev.timezone = 0
 
206
        else:
 
207
            rev.timezone = int(v)
192
208
        rev.message = elt.findtext('message') # text of <message>
193
209
        return rev
194
210