~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/xml4.py

  • Committer: Martin Pool
  • Date: 2005-10-04 02:54:54 UTC
  • mfrom: (1399.1.12)
  • mto: (1185.13.3)
  • mto: This revision was merged to the branch mainline in revision 1400.
  • Revision ID: mbp@sourcefrog.net-20051004025454-a8da093aebf1fb24
[merge] refactoring from robert to use different Entry classes
for files, directories, etc.

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
import bzrlib.inventory as inventory
20
21
from bzrlib.revision import Revision        
21
22
from bzrlib.errors import BzrError
22
23
 
94
95
        if parent_id == None:
95
96
            parent_id = ROOT_ID
96
97
 
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
 
        ie.symlink_target = elt.get('symlink_target')
 
98
        kind = elt.get('kind')
 
99
        if kind == 'directory':
 
100
            ie = inventory.InventoryDirectory(elt.get('file_id'),
 
101
                                              elt.get('name'),
 
102
                                              parent_id)
 
103
        elif kind == 'file':
 
104
            ie = inventory.InventoryFile(elt.get('file_id'),
 
105
                                         elt.get('name'),
 
106
                                         parent_id)
 
107
            ie.text_id = elt.get('text_id')
 
108
            ie.text_sha1 = elt.get('text_sha1')
 
109
            v = elt.get('text_size')
 
110
            ie.text_size = v and int(v)
 
111
        elif kind == 'symlink':
 
112
            ie = inventory.InventoryLink(elt.get('file_id'),
 
113
                                         elt.get('name'),
 
114
                                         parent_id)
 
115
            ie.symlink_target = elt.get('symlink_target')
 
116
        else:
 
117
            raise BzrError("unknown kind %r" % kind)
104
118
 
105
119
        ## mutter("read inventoryentry: %r" % (elt.attrib))
106
120
 
107
 
        v = elt.get('text_size')
108
 
        ie.text_size = v and int(v)
109
 
 
110
121
        return ie
111
122
 
112
123