~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/newinventory.py

  • Committer: mbp at sourcefrog
  • Date: 2005-03-30 23:34:24 UTC
  • Revision ID: mbp@sourcefrog.net-20050330233424-68269ee36902dd19
experimental nested-inventory load support

Show diffs side-by-side

added added

removed removed

Lines of Context:
93
93
    for entry_name, ie in l:
94
94
        descend(ie)
95
95
 
96
 
    f.write('</root-directory>\n')
 
96
    f.write('</root_directory>\n')
97
97
    f.write('</inventory>\n')
98
98
    
99
99
 
100
100
 
 
101
def read_new_inventory(f):
 
102
    from inventory import Inventory, InventoryEntry
 
103
    
 
104
    def descend(parent_ie, el):
 
105
        kind = el.tag
 
106
        name = el.get('name')
 
107
        file_id = el.get('id')
 
108
        ie = InventoryEntry(file_id, name, el.tag)
 
109
        parent_ie.children[name] = ie
 
110
        inv._byid[file_id] = ie
 
111
        if kind == 'directory':
 
112
            for child_el in el:
 
113
                descend(ie, child_el)
 
114
        elif kind == 'file':
 
115
            assert len(el) == 0
 
116
            ie.text_id = el.get('text_id')
 
117
            v = el.get('text_size')
 
118
            ie.text_size = v and int(v)
 
119
            ie.text_sha1 = el.get('text_sha1')
 
120
        else:
 
121
            bailout("unknown inventory entry %r" % kind)
 
122
 
 
123
    inv_el = ElementTree().parse(f)
 
124
    assert inv_el.tag == 'inventory'
 
125
    root_el = inv_el[0]
 
126
    assert root_el.tag == 'root_directory'
 
127
 
 
128
    inv = Inventory()
 
129
    for el in root_el:
 
130
        descend(inv._root, el)