~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/newinventory.py

  • Committer: mbp at sourcefrog
  • Date: 2005-04-11 02:44:45 UTC
  • Revision ID: mbp@sourcefrog.net-20050411024445-a2d4fa7e39309d2300533a6a
- Experiments in inventory performance

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
def write_inventory(inv, f):
21
21
    el = Element('inventory', {'version': '2'})
 
22
    el.text = '\n'
22
23
    
23
 
    root = Element('root_directory', {'id': 'bogus-root-id'})
 
24
    root = Element('root_directory', {'id': inv.root.file_id})
 
25
    root.tail = root.text = '\n'
24
26
    el.append(root)
25
27
 
26
28
    def descend(parent_el, ie):
42
44
        parent_el.append(el)
43
45
 
44
46
        if kind == 'directory':
 
47
            el.text = '\n' # break before having children
45
48
            l = ie.children.items()
46
49
            l.sort()
47
50
            for child_name, child_ie in l:
50
53
        
51
54
    # walk down through inventory, adding all directories
52
55
 
53
 
    l = inv._root.children.items()
 
56
    l = inv.root.children.items()
54
57
    l.sort()
55
58
    for entry_name, ie in l:
56
59
        descend(root, ie)
60
63
 
61
64
 
62
65
 
 
66
def escape_attr(text):
 
67
    return text.replace("&", "&") \
 
68
           .replace("'", "'") \
 
69
           .replace('"', """) \
 
70
           .replace("<", "&lt;") \
 
71
           .replace(">", "&gt;")
 
72
 
 
73
 
 
74
# This writes out an inventory without building an XML tree first,
 
75
# just to see if it's faster.  Not currently used.
63
76
def write_slacker_inventory(inv, f):
64
77
    def descend(ie):
65
78
        kind = ie.kind
66
 
        f.write('<%s name="%s" id="%s" ' % (kind, ie.name, ie.file_id))
 
79
        f.write('<%s name="%s" id="%s" ' % (kind, escape_attr(ie.name),
 
80
                                            escape_attr(ie.file_id)))
67
81
 
68
82
        if kind == 'file':
69
83
            if ie.text_id:
86
100
            bailout('unknown InventoryEntry kind %r' % kind)
87
101
 
88
102
    f.write('<inventory>\n')
89
 
    f.write('<root_directory id="bogus-root-id">\n')
 
103
    f.write('<root_directory id="%s">\n' % escape_attr(inv.root.file_id))
90
104
 
91
 
    l = inv._root.children.items()
 
105
    l = inv.root.children.items()
92
106
    l.sort()
93
107
    for entry_name, ie in l:
94
108
        descend(ie)
127
141
 
128
142
    inv = Inventory()
129
143
    for el in root_el:
130
 
        descend(inv._root, el)
 
144
        descend(inv.root, el)