~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/xml5.py

  • Committer: Martin Pool
  • Date: 2005-10-04 06:44:50 UTC
  • mto: (1185.13.3)
  • mto: This revision was merged to the branch mainline in revision 1403.
  • Revision ID: mbp@sourcefrog.net-20051004064450-6437da8f84d41517
- add test that upgrade completes successfully

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
from bzrlib.xml import ElementTree, SubElement, Element, Serializer
19
19
from bzrlib.inventory import ROOT_ID, Inventory, InventoryEntry
20
 
from bzrlib.revision import Revision, RevisionReference        
 
20
import bzrlib.inventory as inventory
 
21
from bzrlib.revision import Revision        
21
22
from bzrlib.errors import BzrError
22
23
 
23
24
 
45
46
 
46
47
    def _pack_entry(self, ie):
47
48
        """Convert InventoryEntry to XML element"""
48
 
        assert ie.kind == 'directory' or ie.kind == 'file'
 
49
        if not InventoryEntry.versionable_kind(ie.kind):
 
50
            raise AssertionError('unsupported entry kind %s' % ie.kind)
49
51
        e = Element(ie.kind)
50
52
        e.set('name', ie.name)
51
53
        e.set('file_id', ie.file_id)
53
55
        if ie.text_size != None:
54
56
            e.set('text_size', '%d' % ie.text_size)
55
57
 
56
 
        for f in ['text_version', 'text_sha1', 'entry_version']:
 
58
        for f in ['text_sha1', 'revision', 'symlink_target']:
57
59
            v = getattr(ie, f)
58
60
            if v != None:
59
61
                e.set(f, v)
60
62
 
 
63
        if ie.executable:
 
64
            e.set('executable', 'yes')
 
65
 
61
66
        # to be conservative, we don't externalize the root pointers
62
67
        # for now, leaving them as null in the xml form.  in a future
63
68
        # version it will be implied by nested elements.
86
91
        msg.text = rev.message
87
92
        msg.tail = '\n'
88
93
 
89
 
        if rev.parents:
 
94
        if rev.parent_ids:
90
95
            pelts = SubElement(root, 'parents')
91
96
            pelts.tail = pelts.text = '\n'
92
 
            for rr in rev.parents:
93
 
                assert isinstance(rr, RevisionReference)
 
97
            for parent_id in rev.parent_ids:
 
98
                assert isinstance(parent_id, basestring)
94
99
                p = SubElement(pelts, 'revision_ref')
95
100
                p.tail = '\n'
96
 
                assert rr.revision_id
97
 
                p.set('revision_id', rr.revision_id)
98
 
 
 
101
                p.set('revision_id', parent_id)
99
102
        return root
100
103
 
101
104
    
116
119
 
117
120
    def _unpack_entry(self, elt):
118
121
        kind = elt.tag
119
 
        assert kind == 'directory' or kind == 'file'
 
122
        if not InventoryEntry.versionable_kind(kind):
 
123
            raise AssertionError('unsupported entry kind %s' % kind)
120
124
 
121
125
        parent_id = elt.get('parent_id')
122
126
        if parent_id == None:
123
127
            parent_id = ROOT_ID
124
128
 
125
 
        ie = InventoryEntry(elt.get('file_id'),
126
 
                            elt.get('name'),
127
 
                            kind,
128
 
                            parent_id)
129
 
        ie.text_version = elt.get('text_version')
130
 
        ie.entry_version = elt.get('entry_version')
131
 
        ie.text_sha1 = elt.get('text_sha1')
132
 
        v = elt.get('text_size')
133
 
        ie.text_size = v and int(v)
 
129
        if kind == 'directory':
 
130
            ie = inventory.InventoryDirectory(elt.get('file_id'),
 
131
                                              elt.get('name'),
 
132
                                              parent_id)
 
133
        elif kind == 'file':
 
134
            ie = inventory.InventoryFile(elt.get('file_id'),
 
135
                                         elt.get('name'),
 
136
                                         parent_id)
 
137
            ie.text_sha1 = elt.get('text_sha1')
 
138
            if elt.get('executable') == 'yes':
 
139
                ie.executable = True
 
140
            v = elt.get('text_size')
 
141
            ie.text_size = v and int(v)
 
142
        elif kind == 'symlink':
 
143
            ie = inventory.InventoryLink(elt.get('file_id'),
 
144
                                         elt.get('name'),
 
145
                                         parent_id)
 
146
            ie.symlink_target = elt.get('symlink_target')
 
147
        else:
 
148
            raise BzrError("unknown kind %r" % kind)
 
149
        ie.revision = elt.get('revision')
134
150
 
135
151
        return ie
136
152
 
149
165
        for p in parents:
150
166
            assert p.tag == 'revision_ref', \
151
167
                   "bad parent node tag %r" % p.tag
152
 
            rev_ref = RevisionReference(p.get('revision_id'))
153
 
            rev.parents.append(rev_ref)
 
168
            rev.parent_ids.append(p.get('revision_id'))
154
169
 
155
170
        v = elt.get('timezone')
156
171
        rev.timezone = v and int(v)