173
168
w._weave.append((intern(l[0]), int(l[2:])))
177
class WeaveFile(Weave):
178
"""A WeaveFile represents a Weave on disk and writes on change."""
180
WEAVE_SUFFIX = '.weave'
182
def __init__(self, name, transport, filemode=None, create=False, access_mode='w', get_scope=None):
183
"""Create a WeaveFile.
185
:param create: If not True, only open an existing knit.
187
super(WeaveFile, self).__init__(name, access_mode, get_scope=get_scope,
188
allow_reserved=False)
189
self._transport = transport
190
self._filemode = filemode
192
_read_weave_v5(self._transport.get(name + WeaveFile.WEAVE_SUFFIX), self)
193
except errors.NoSuchFile:
199
def _add_lines(self, version_id, parents, lines, parent_texts,
200
left_matching_blocks, nostore_sha, random_id, check_content):
201
"""Add a version and save the weave."""
202
self.check_not_reserved_id(version_id)
203
result = super(WeaveFile, self)._add_lines(version_id, parents, lines,
204
parent_texts, left_matching_blocks, nostore_sha, random_id,
209
def copy_to(self, name, transport):
210
"""See VersionedFile.copy_to()."""
211
# as we are all in memory always, just serialise to the new place.
213
write_weave_v5(self, sio)
215
transport.put_file(name + WeaveFile.WEAVE_SUFFIX, sio, self._filemode)
218
"""Save the weave."""
219
self._check_write_ok()
221
write_weave_v5(self, sio)
223
bytes = sio.getvalue()
224
path = self._weave_name + WeaveFile.WEAVE_SUFFIX
226
self._transport.put_bytes(path, bytes, self._filemode)
227
except errors.NoSuchFile:
228
self._transport.mkdir(dirname(path))
229
self._transport.put_bytes(path, bytes, self._filemode)
233
"""See VersionedFile.get_suffixes()."""
234
return [WeaveFile.WEAVE_SUFFIX]
236
def insert_record_stream(self, stream):
237
super(WeaveFile, self).insert_record_stream(stream)