/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/weave.py

  • Committer: Martin
  • Date: 2017-05-24 20:47:06 UTC
  • mto: This revision was merged to the branch mainline in revision 6635.
  • Revision ID: gzlist@googlemail.com-20170524204706-jvole7jqnplsj8ts
Rename report_delta param from filter to predicate with tests and release notes

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
# Author: Martin Pool <mbp@canonical.com>
18
18
 
19
 
 
20
19
"""Weave - storage of related text file versions"""
21
20
 
 
21
from __future__ import absolute_import
22
22
 
23
23
# XXX: If we do weaves this way, will a merge still behave the same
24
24
# way if it's done in a different order?  That's a pretty desirable
67
67
# FIXME: the conflict markers should be *7* characters
68
68
 
69
69
from copy import copy
70
 
from cStringIO import StringIO
71
70
import os
72
71
 
73
 
from bzrlib.lazy_import import lazy_import
 
72
from .lazy_import import lazy_import
74
73
lazy_import(globals(), """
75
 
from bzrlib import tsort
 
74
from breezy import tsort
76
75
""")
77
 
from bzrlib import (
 
76
from . import (
78
77
    errors,
79
78
    osutils,
80
79
    )
81
 
from bzrlib.errors import (WeaveError, WeaveFormatError, WeaveParentMismatch,
 
80
from .errors import (WeaveError, WeaveFormatError, WeaveParentMismatch,
82
81
        RevisionAlreadyPresent,
83
82
        RevisionNotPresent,
84
83
        UnavailableRepresentation,
85
84
        )
86
 
from bzrlib.osutils import dirname, sha, sha_strings, split_lines
87
 
import bzrlib.patiencediff
88
 
from bzrlib.revision import NULL_REVISION
89
 
from bzrlib.symbol_versioning import *
90
 
from bzrlib.trace import mutter
91
 
from bzrlib.versionedfile import (
 
85
from .osutils import dirname, sha, sha_strings, split_lines
 
86
from . import patiencediff
 
87
from .revision import NULL_REVISION
 
88
from .sixish import (
 
89
    BytesIO,
 
90
    )
 
91
from .symbol_versioning import *
 
92
from .trace import mutter
 
93
from .versionedfile import (
92
94
    AbsentContentFactory,
93
95
    adapter_registry,
94
96
    ContentFactory,
95
97
    sort_groupcompress,
96
98
    VersionedFile,
97
99
    )
98
 
from bzrlib.weavefile import _read_weave_v5, write_weave_v5
 
100
from .weavefile import _read_weave_v5, write_weave_v5
99
101
 
100
102
 
101
103
class WeaveContentFactory(ContentFactory):
231
233
        self._name_map = {}
232
234
        self._weave_name = weave_name
233
235
        if matcher is None:
234
 
            self._matcher = bzrlib.patiencediff.PatienceSequenceMatcher
 
236
            self._matcher = patiencediff.PatienceSequenceMatcher
235
237
        else:
236
238
            self._matcher = matcher
237
239
        if get_scope is None:
688
690
        WFE = WeaveFormatError
689
691
 
690
692
        # wow.
691
 
        #  449       0   4474.6820   2356.5590   bzrlib.weave:556(_extract)
 
693
        #  449       0   4474.6820   2356.5590   breezy.weave:556(_extract)
692
694
        #  +285282   0   1676.8040   1676.8040   +<isinstance>
693
695
        # 1.6 seconds in 'isinstance'.
694
696
        # changing the first isinstance:
695
 
        #  449       0   2814.2660   1577.1760   bzrlib.weave:556(_extract)
 
697
        #  449       0   2814.2660   1577.1760   breezy.weave:556(_extract)
696
698
        #  +140414   0    762.8050    762.8050   +<isinstance>
697
699
        # note that the inline time actually dropped (less function calls)
698
700
        # and total processing time was halved.
699
701
        # we're still spending ~1/4 of the method in isinstance though.
700
702
        # so lets hard code the acceptable string classes we expect:
701
 
        #  449       0   1202.9420    786.2930   bzrlib.weave:556(_extract)
 
703
        #  449       0   1202.9420    786.2930   breezy.weave:556(_extract)
702
704
        # +71352     0    377.5560    377.5560   +<method 'append' of 'list'
703
705
        #                                          objects>
704
706
        # yay, down to ~1/4 the initial extract time, and our inline time
705
707
        # has shrunk again, with isinstance no longer dominating.
706
708
        # tweaking the stack inclusion test to use a set gives:
707
 
        #  449       0   1122.8030    713.0080   bzrlib.weave:556(_extract)
 
709
        #  449       0   1122.8030    713.0080   breezy.weave:556(_extract)
708
710
        # +71352     0    354.9980    354.9980   +<method 'append' of 'list'
709
711
        #                                          objects>
710
712
        # - a 5% win, or possibly just noise. However with large istacks that
750
752
 
751
753
        NOT FOR PUBLIC USE.
752
754
        """
753
 
        if isinstance(name_or_index, (int, long)):
 
755
        # GZ 2017-04-01: This used to check for long as well, but I don't think
 
756
        # there are python implementations with sys.maxsize > sys.maxint
 
757
        if isinstance(name_or_index, int):
754
758
            return name_or_index
755
759
        else:
756
760
            return self._lookup(name_or_index)
805
809
            name = self._idx_to_name(i)
806
810
            sha1s[name] = sha()
807
811
            texts[name] = []
808
 
            new_inc = set([name])
 
812
            new_inc = {name}
809
813
            for p in self._parents[i]:
810
814
                new_inc.update(inclusions[self._idx_to_name(p)])
811
815
 
878
882
                raise errors.WeaveTextDiffers(name, self, other)
879
883
            self_parents = self._parents[this_idx]
880
884
            other_parents = other._parents[other_idx]
881
 
            n1 = set([self._names[i] for i in self_parents])
882
 
            n2 = set([other._names[i] for i in other_parents])
 
885
            n1 = {self._names[i] for i in self_parents}
 
886
            n2 = {other._names[i] for i in other_parents}
883
887
            if not self._compatible_parents(n1, n2):
884
888
                raise WeaveParentMismatch("inconsistent parents "
885
889
                    "for version {%s}: %s vs %s" % (name, n1, n2))
920
924
        self._transport = transport
921
925
        self._filemode = filemode
922
926
        try:
923
 
            _read_weave_v5(self._transport.get(name + WeaveFile.WEAVE_SUFFIX), self)
 
927
            f = self._transport.get(name + WeaveFile.WEAVE_SUFFIX)
 
928
            _read_weave_v5(BytesIO(f.read()), self)
924
929
        except errors.NoSuchFile:
925
930
            if not create:
926
931
                raise
940
945
    def copy_to(self, name, transport):
941
946
        """See VersionedFile.copy_to()."""
942
947
        # as we are all in memory always, just serialise to the new place.
943
 
        sio = StringIO()
 
948
        sio = BytesIO()
944
949
        write_weave_v5(self, sio)
945
950
        sio.seek(0)
946
951
        transport.put_file(name + WeaveFile.WEAVE_SUFFIX, sio, self._filemode)
948
953
    def _save(self):
949
954
        """Save the weave."""
950
955
        self._check_write_ok()
951
 
        sio = StringIO()
 
956
        sio = BytesIO()
952
957
        write_weave_v5(self, sio)
953
958
        sio.seek(0)
954
959
        bytes = sio.getvalue()