96
# FIXME: detect the weave type and dispatch
97
from bzrlib.trace import mutter
98
from weave import Weave
98
return read_weave_v5(f)
101
def read_weave_v5(f):
102
from weave import Weave, WeaveFormatError
99
103
w = Weave(getattr(f, 'name', None))
104
def _read_weave_v5(f, w):
105
"""Private helper routine to read a weave format 5 file into memory.
107
This is only to be used by read_weave and WeaveFile.__init__.
109
# 200 0 2075.5080 1084.0360 bzrlib.weavefile:104(_read_weave_v5)
110
# +60412 0 366.5900 366.5900 +<method 'readline' of 'file' objects>
111
# +59982 0 320.5280 320.5280 +<method 'startswith' of 'str' objects>
112
# +59363 0 297.8080 297.8080 +<method 'append' of 'list' objects>
113
# replace readline call with iter over all lines ->
114
# safe because we already suck on memory.
115
# 200 0 1492.7170 802.6220 bzrlib.weavefile:104(_read_weave_v5)
116
# +59982 0 329.9100 329.9100 +<method 'startswith' of 'str' objects>
117
# +59363 0 320.2980 320.2980 +<method 'append' of 'list' objects>
118
# replaced startswith with slice lookups:
119
# 200 0 851.7250 501.1120 bzrlib.weavefile:104(_read_weave_v5)
120
# +59363 0 311.8780 311.8780 +<method 'append' of 'list' objects>
121
# +200 0 30.2500 30.2500 +<method 'readlines' of 'file' objects>
123
from weave import WeaveFormatError
125
lines = iter(f.readlines())
128
106
if l != FORMAT_1:
129
107
raise WeaveFormatError('invalid weave file header: %r' % l)
137
114
w._parents.append(map(int, l[2:].split(' ')))
139
116
w._parents.append([])
141
l = lines.next()[:-1]
142
assert '1 ' == l[0:2]
118
l = f.readline()[:-1]
119
assert l.startswith('1 ')
143
120
w._sha1s.append(l[2:])
146
assert 'n ' == l[0:2]
123
assert l.startswith('n ')
148
125
assert name not in w._name_map
149
126
w._names.append(name)
150
127
w._name_map[name] = ver
159
136
raise WeaveFormatError('unexpected line %r' % l)
142
elif l.startswith('. '):
167
143
w._weave.append(l[2:]) # include newline
144
elif l.startswith(', '):
169
145
w._weave.append(l[2:-1]) # exclude newline
171
147
w._weave.append(('}', None))