~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/xml5.py

  • Committer: Robert Collins
  • Date: 2005-10-06 07:11:13 UTC
  • mfrom: (1393.1.59)
  • Revision ID: robertc@robertcollins.net-20051006071113-54e61035470e2f49
mergeĀ fromĀ martin

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
    
36
36
    def _pack_inventory(self, inv):
37
37
        """Convert to XML Element"""
38
 
        e = Element('inventory')
 
38
        e = Element('inventory',
 
39
                    format='5')
39
40
        e.text = '\n'
40
41
        if inv.root.file_id not in (None, ROOT_ID):
41
42
            e.set('file_id', inv.root.file_id)
82
83
                       timestamp = '%.9f' % rev.timestamp,
83
84
                       revision_id = rev.revision_id,
84
85
                       inventory_sha1 = rev.inventory_sha1,
 
86
                       format='5',
85
87
                       )
86
88
        if rev.timezone:
87
89
            root.set('timezone', str(rev.timezone))
88
90
        root.text = '\n'
89
 
 
90
91
        msg = SubElement(root, 'message')
91
92
        msg.text = rev.message
92
93
        msg.tail = '\n'
93
 
 
94
94
        if rev.parent_ids:
95
95
            pelts = SubElement(root, 'parents')
96
96
            pelts.tail = pelts.text = '\n'
100
100
                p.tail = '\n'
101
101
                p.set('revision_id', parent_id)
102
102
        return root
103
 
 
104
103
    
105
104
 
106
105
    def _unpack_inventory(self, elt):
108
107
        """
109
108
        assert elt.tag == 'inventory'
110
109
        root_id = elt.get('file_id') or ROOT_ID
 
110
        format = elt.get('format')
 
111
        if format is not None:
 
112
            if format != '5':
 
113
                raise BzrError("invalid format version %r on inventory"
 
114
                                % format)
111
115
        inv = Inventory(root_id)
112
116
        for e in elt:
113
117
            ie = self._unpack_entry(e)
154
158
    def _unpack_revision(self, elt):
155
159
        """XML Element -> Revision object"""
156
160
        assert elt.tag == 'revision'
157
 
        
 
161
        format = elt.get('format')
 
162
        if format is not None:
 
163
            if format != '5':
 
164
                raise BzrError("invalid format version %r on inventory"
 
165
                                % format)
158
166
        rev = Revision(committer = elt.get('committer'),
159
167
                       timestamp = float(elt.get('timestamp')),
160
168
                       revision_id = elt.get('revision_id'),
161
169
                       inventory_sha1 = elt.get('inventory_sha1')
162
170
                       )
163
 
 
164
171
        parents = elt.find('parents') or []
165
172
        for p in parents:
166
173
            assert p.tag == 'revision_ref', \
174
181
        return rev
175
182
 
176
183
 
177
 
 
178
184
serializer_v5 = Serializer_v5()