~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/xml4.py

  • Committer: Martin Pool
  • Date: 2005-09-16 09:56:24 UTC
  • Revision ID: mbp@sourcefrog.net-20050916095623-ca0dff452934f21f
- make progress bar more tolerant of out-of-range values

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/env python
 
2
 
1
3
# This program is free software; you can redistribute it and/or modify
2
4
# it under the terms of the GNU General Public License as published by
3
5
# the Free Software Foundation; either version 2 of the License, or
13
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
14
16
 
15
17
 
16
 
from bzrlib.xml_serializer import ElementTree, SubElement, Element, Serializer
 
18
from bzrlib.xml import ElementTree, SubElement, Element, Serializer
17
19
from bzrlib.inventory import ROOT_ID, Inventory, InventoryEntry
18
 
import bzrlib.inventory as inventory
19
 
from bzrlib.revision import Revision        
 
20
from bzrlib.revision import Revision, RevisionReference        
20
21
from bzrlib.errors import BzrError
21
22
 
22
23
 
52
53
        if ie.text_size != None:
53
54
            e.set('text_size', '%d' % ie.text_size)
54
55
 
55
 
        for f in ['text_id', 'text_sha1', 'symlink_target']:
 
56
        for f in ['text_id', 'text_sha1']:
56
57
            v = getattr(ie, f)
57
58
            if v != None:
58
59
                e.set(f, v)
93
94
        if parent_id == None:
94
95
            parent_id = ROOT_ID
95
96
 
96
 
        kind = elt.get('kind')
97
 
        if kind == 'directory':
98
 
            ie = inventory.InventoryDirectory(elt.get('file_id'),
99
 
                                              elt.get('name'),
100
 
                                              parent_id)
101
 
        elif kind == 'file':
102
 
            ie = inventory.InventoryFile(elt.get('file_id'),
103
 
                                         elt.get('name'),
104
 
                                         parent_id)
105
 
            ie.text_id = elt.get('text_id')
106
 
            ie.text_sha1 = elt.get('text_sha1')
107
 
            v = elt.get('text_size')
108
 
            ie.text_size = v and int(v)
109
 
        elif kind == 'symlink':
110
 
            ie = inventory.InventoryLink(elt.get('file_id'),
111
 
                                         elt.get('name'),
112
 
                                         parent_id)
113
 
            ie.symlink_target = elt.get('symlink_target')
114
 
        else:
115
 
            raise BzrError("unknown kind %r" % kind)
116
 
 
117
 
        ## mutter("read inventoryentry: %r", elt.attrib)
 
97
        ie = InventoryEntry(elt.get('file_id'),
 
98
                            elt.get('name'),
 
99
                            elt.get('kind'),
 
100
                            parent_id)
 
101
        ie.text_id = elt.get('text_id')
 
102
        ie.text_sha1 = elt.get('text_sha1')
 
103
 
 
104
        ## mutter("read inventoryentry: %r" % (elt.attrib))
 
105
 
 
106
        v = elt.get('text_size')
 
107
        ie.text_size = v and int(v)
118
108
 
119
109
        return ie
120
110
 
139
129
        if rev.parents:
140
130
            pelts = SubElement(root, 'parents')
141
131
            pelts.tail = pelts.text = '\n'
142
 
            for i, parent_id in enumerate(rev.parents):
 
132
            for rr in rev.parents:
 
133
                assert isinstance(rr, RevisionReference)
143
134
                p = SubElement(pelts, 'revision_ref')
144
135
                p.tail = '\n'
145
 
                assert parent_id
146
 
                p.set('revision_id', parent_id)
147
 
                if i < len(rev.parent_sha1s):
148
 
                    p.set('revision_sha1', rev.parent_sha1s[i])
 
136
                assert rr.revision_id
 
137
                p.set('revision_id', rr.revision_id)
 
138
                if rr.revision_sha1:
 
139
                    p.set('revision_sha1', rr.revision_sha1)
 
140
 
149
141
        return root
150
142
 
151
143
    
172
164
            for p in pelts:
173
165
                assert p.tag == 'revision_ref', \
174
166
                       "bad parent node tag %r" % p.tag
175
 
                rev.parent_ids.append(p.get('revision_id'))
176
 
                rev.parent_sha1s.append(p.get('revision_sha1'))
 
167
                rev_ref = RevisionReference(p.get('revision_id'),
 
168
                                            p.get('revision_sha1'))
 
169
                rev.parents.append(rev_ref)
 
170
 
177
171
            if precursor:
178
172
                # must be consistent
179
 
                prec_parent = rev.parent_ids[0]
 
173
                prec_parent = rev.parents[0].revision_id
180
174
                assert prec_parent == precursor
181
175
        elif precursor:
182
176
            # revisions written prior to 0.0.5 have a single precursor
183
177
            # give as an attribute
184
 
            rev.parent_ids.append(precursor)
185
 
            rev.parent_sha1s.append(precursor_sha1)
 
178
            rev_ref = RevisionReference(precursor, precursor_sha1)
 
179
            rev.parents.append(rev_ref)
186
180
 
187
181
        v = elt.get('timezone')
188
182
        rev.timezone = v and int(v)