/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 bzrlib/transactions.py

  • Committer: John Arbash Meinel
  • Date: 2006-04-25 15:05:42 UTC
  • mfrom: (1185.85.85 bzr-encoding)
  • mto: This revision was merged to the branch mainline in revision 1752.
  • Revision ID: john@arbash-meinel.com-20060425150542-c7b518dca9928691
[merge] the old bzr-encoding changes, reparenting them on bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Canonical Ltd
 
1
# Copyright (C) 2005 by Canonical Ltd
2
2
#   Authors: Robert Collins <robert.collins@canonical.com>
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
13
13
#
14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
 
18
18
"""This module provides a transactional facility.
19
19
 
30
30
write ordering approach we use for consistency 'dirty' is a misleading term.
31
31
A dirty object is one we have modified.
32
32
 
33
 
Both read and write transactions *may* flush unchanged objects out of
34
 
memory, unless they are marked as 'precious' which indicates that
 
33
Both read and write transactions *may* flush unchanged objects out of 
 
34
memory, unless they are marked as 'precious' which indicates that 
35
35
repeated reads cannot be obtained if the object is ejected, or that
36
36
the object is an expensive one for obtaining.
37
37
"""
38
38
 
39
 
from __future__ import absolute_import
40
 
 
41
39
import sys
42
40
 
43
 
from . import errors as errors
44
 
from .identitymap import IdentityMap, NullIdentityMap
45
 
from .trace import mutter
 
41
import bzrlib.errors as errors
 
42
from bzrlib.identitymap import IdentityMap, NullIdentityMap
 
43
from bzrlib.trace import mutter
46
44
 
47
45
 
48
46
class ReadOnlyTransaction(object):
61
59
 
62
60
    def is_clean(self, an_object):
63
61
        """Return True if an_object is clean."""
64
 
        return (an_object in self._clean_objects)
 
62
        return an_object in self._clean_objects
65
63
 
66
64
    def register_clean(self, an_object, precious=False):
67
65
        """Register an_object as being clean.
68
 
 
 
66
        
69
67
        If the precious hint is True, the object will not
70
68
        be ejected from the object identity map ever.
71
69
        """
81
79
 
82
80
    def set_cache_size(self, size):
83
81
        """Set a new cache size."""
84
 
        if size < -1:
85
 
            raise ValueError(size)
 
82
        assert -1 <= size
86
83
        self._limit = size
87
84
        self._trim()
88
85
 
101
98
            # _clean_objects
102
99
            # _clean_queue
103
100
            # 1 missing ?
104
 
            if (sys.getrefcount(self._clean_queue[offset]) <= 7
105
 
                    and not self._clean_queue[offset] in self._precious_objects):
 
101
            if (sys.getrefcount(self._clean_queue[offset]) <= 7 and
 
102
                not self._clean_queue[offset] in self._precious_objects):
106
103
                removed = self._clean_queue[offset]
107
104
                self._clean_objects.remove(removed)
108
105
                del self._clean_queue[offset]
137
134
 
138
135
    def is_dirty(self, an_object):
139
136
        """Return True if an_object is dirty."""
140
 
        return (an_object in self._dirty_objects)
 
137
        return an_object in self._dirty_objects
141
138
 
142
139
    def register_dirty(self, an_object):
143
140
        """Register an_object as being dirty.
144
 
 
 
141
        
145
142
        Dirty objects are not ejected from the identity map
146
143
        until the transaction finishes and get informed
147
144
        when the transaction finishes.
156
153
        """Write transactions allow writes."""
157
154
        return True
158
155
 
159
 
 
 
156
        
160
157
class PassThroughTransaction(object):
161
158
    """A pass through transaction
162
 
 
 
159
    
163
160
    - nothing is cached.
164
161
    - nothing ever gets into the identity map.
165
162
    """
178
175
 
179
176
    def register_clean(self, an_object, precious=False):
180
177
        """Register an_object as being clean.
181
 
 
 
178
        
182
179
        Note that precious is only a hint, and PassThroughTransaction
183
180
        ignores it.
184
181
        """
185
182
 
186
183
    def register_dirty(self, an_object):
187
184
        """Register an_object as being dirty.
188
 
 
 
185
        
189
186
        Dirty objects get informed
190
187
        when the transaction finishes.
191
188
        """