/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/inter.py

  • Committer: Gustav Hartvigsson
  • Date: 2021-01-09 21:36:27 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20210109213627-h1xwcutzy9m7a99b
Added 'Case Preserving Working Tree Use Cases' from Canonical Wiki

* Addod a page from the Canonical Bazaar wiki
  with information on the scmeatics of case
  perserving filesystems an a case insensitive
  filesystem works.
  
  * Needs re-work, but this will do as it is the
    same inforamoton as what was on the linked
    page in the currint documentation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
 
18
17
"""Inter-object utility class."""
19
18
 
 
19
from .errors import BzrError
 
20
from .lock import LogicalLockResult
 
21
from .pyutils import get_named_object
 
22
 
 
23
 
 
24
class NoCompatibleInter(BzrError):
 
25
 
 
26
    _fmt = ('No compatible object available for operations from %(source)r '
 
27
            'to %(target)r.')
 
28
 
 
29
    def __init__(self, source, target):
 
30
        self.source = source
 
31
        self.target = target
 
32
 
20
33
 
21
34
class InterObject(object):
22
35
    """This class represents operations taking place between two objects.
32
45
 
33
46
    If the source and target objects implement the locking protocol -
34
47
    lock_read, lock_write, unlock, then the InterObject's lock_read,
35
 
    lock_write and unlock methods may be used (optionally in conjunction with
36
 
    the needs_read_lock and needs_write_lock decorators.)
 
48
    lock_write and unlock methods may be used.
37
49
 
38
50
    When looking for an inter, the most recently registered types are tested
39
51
    first.  So typically the most generic and slowest InterObjects should be
75
87
                       the InterObject instance.
76
88
        :param target: the object to be the 'target' member of
77
89
                       the InterObject instance.
 
90
 
78
91
        If an optimised worker exists it will be used otherwise
79
92
        a default Inter worker instance will be created.
80
93
        """
81
 
        for provider in reversed(klass._optimisers):
 
94
        for i, provider in enumerate(reversed(klass._optimisers)):
 
95
            if isinstance(provider, tuple):
 
96
                provider = get_named_object(provider[0], provider[1])
 
97
                klass._optimisers[-i] = provider
82
98
            if provider.is_compatible(source, target):
83
99
                return provider(source, target)
84
 
        return klass(source, target)
 
100
        raise NoCompatibleInter(source, target)
 
101
 
 
102
    @classmethod
 
103
    def iter_optimisers(klass):
 
104
        for provider in klass._optimisers:
 
105
            if isinstance(provider, tuple):
 
106
                yield get_named_object(provider[0], provider[1])
 
107
            else:
 
108
                yield provider
85
109
 
86
110
    def lock_read(self):
87
111
        """Take out a logical read lock.
90
114
        a read lock and the target a read lock.
91
115
        """
92
116
        self._double_lock(self.source.lock_read, self.target.lock_read)
 
117
        return LogicalLockResult(self.unlock)
93
118
 
94
119
    def lock_write(self):
95
120
        """Take out a logical write lock.
98
123
        a read lock and the target a write lock.
99
124
        """
100
125
        self._double_lock(self.source.lock_read, self.target.lock_write)
 
126
        return LogicalLockResult(self.unlock)
101
127
 
102
128
    @classmethod
103
129
    def register_optimiser(klass, optimiser):
104
130
        """Register an InterObject optimiser."""
105
131
        klass._optimisers.append(optimiser)
106
132
 
 
133
    @classmethod
 
134
    def register_lazy_optimiser(klass, module_name, member_name):
 
135
        # TODO(jelmer): Allow passing in a custom .is_compatible
 
136
        klass._optimisers.append((module_name, member_name))
 
137
 
107
138
    def unlock(self):
108
139
        """Release the locks on source and target."""
109
140
        try: