~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/weave.py

  • Committer: Jelmer Vernooij
  • Date: 2011-01-14 00:36:56 UTC
  • mto: (5582.12.2 weave-plugin)
  • mto: This revision was merged to the branch mainline in revision 5718.
  • Revision ID: jelmer@samba.org-20110114003656-0enxoqf6lc0yt3d6
Move bzrlib.weavefile.

Show diffs side-by-side

added added

removed removed

Lines of Context:
102
102
    sort_groupcompress,
103
103
    VersionedFile,
104
104
    )
105
 
from bzrlib.weavefile import _read_weave_v5, write_weave_v5
106
105
 
107
106
 
108
107
class WeaveError(BzrError):
951
950
                setattr(self, attr, copy(getattr(otherweave, attr)))
952
951
 
953
952
 
954
 
class WeaveFile(Weave):
955
 
    """A WeaveFile represents a Weave on disk and writes on change."""
956
 
 
957
 
    WEAVE_SUFFIX = '.weave'
958
 
 
959
 
    def __init__(self, name, transport, filemode=None, create=False, access_mode='w', get_scope=None):
960
 
        """Create a WeaveFile.
961
 
 
962
 
        :param create: If not True, only open an existing knit.
963
 
        """
964
 
        super(WeaveFile, self).__init__(name, access_mode, get_scope=get_scope,
965
 
            allow_reserved=False)
966
 
        self._transport = transport
967
 
        self._filemode = filemode
968
 
        try:
969
 
            _read_weave_v5(self._transport.get(name + WeaveFile.WEAVE_SUFFIX), self)
970
 
        except errors.NoSuchFile:
971
 
            if not create:
972
 
                raise
973
 
            # new file, save it
974
 
            self._save()
975
 
 
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,
982
 
            check_content)
983
 
        self._save()
984
 
        return result
985
 
 
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.
989
 
        sio = StringIO()
990
 
        write_weave_v5(self, sio)
991
 
        sio.seek(0)
992
 
        transport.put_file(name + WeaveFile.WEAVE_SUFFIX, sio, self._filemode)
993
 
 
994
 
    def _save(self):
995
 
        """Save the weave."""
996
 
        self._check_write_ok()
997
 
        sio = StringIO()
998
 
        write_weave_v5(self, sio)
999
 
        sio.seek(0)
1000
 
        bytes = sio.getvalue()
1001
 
        path = self._weave_name + WeaveFile.WEAVE_SUFFIX
1002
 
        try:
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)
1007
 
 
1008
 
    @staticmethod
1009
 
    def get_suffixes():
1010
 
        """See VersionedFile.get_suffixes()."""
1011
 
        return [WeaveFile.WEAVE_SUFFIX]
1012
 
 
1013
 
    def insert_record_stream(self, stream):
1014
 
        super(WeaveFile, self).insert_record_stream(stream)
1015
 
        self._save()
1016
 
 
1017
 
 
1018
953
def _reweave(wa, wb, pb=None, msg=None):
1019
954
    """Combine two weaves and return the result.
1020
955