951
950
setattr(self, attr, copy(getattr(otherweave, attr)))
954
class WeaveFile(Weave):
955
"""A WeaveFile represents a Weave on disk and writes on change."""
957
WEAVE_SUFFIX = '.weave'
959
def __init__(self, name, transport, filemode=None, create=False, access_mode='w', get_scope=None):
960
"""Create a WeaveFile.
962
:param create: If not True, only open an existing knit.
964
super(WeaveFile, self).__init__(name, access_mode, get_scope=get_scope,
965
allow_reserved=False)
966
self._transport = transport
967
self._filemode = filemode
969
_read_weave_v5(self._transport.get(name + WeaveFile.WEAVE_SUFFIX), self)
970
except errors.NoSuchFile:
976
def _add_lines(self, version_id, parents, lines, parent_texts,
977
left_matching_blocks, nostore_sha, random_id, check_content):
978
"""Add a version and save the weave."""
979
self.check_not_reserved_id(version_id)
980
result = super(WeaveFile, self)._add_lines(version_id, parents, lines,
981
parent_texts, left_matching_blocks, nostore_sha, random_id,
986
def copy_to(self, name, transport):
987
"""See VersionedFile.copy_to()."""
988
# as we are all in memory always, just serialise to the new place.
990
write_weave_v5(self, sio)
992
transport.put_file(name + WeaveFile.WEAVE_SUFFIX, sio, self._filemode)
995
"""Save the weave."""
996
self._check_write_ok()
998
write_weave_v5(self, sio)
1000
bytes = sio.getvalue()
1001
path = self._weave_name + WeaveFile.WEAVE_SUFFIX
1003
self._transport.put_bytes(path, bytes, self._filemode)
1004
except errors.NoSuchFile:
1005
self._transport.mkdir(dirname(path))
1006
self._transport.put_bytes(path, bytes, self._filemode)
1010
"""See VersionedFile.get_suffixes()."""
1011
return [WeaveFile.WEAVE_SUFFIX]
1013
def insert_record_stream(self, stream):
1014
super(WeaveFile, self).insert_record_stream(stream)
1018
953
def _reweave(wa, wb, pb=None, msg=None):
1019
954
"""Combine two weaves and return the result.