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

Remove uses of needs_write_lock.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
See MemoryTree for more details.
20
20
"""
21
21
 
 
22
from __future__ import absolute_import
22
23
 
23
24
import os
24
25
 
25
 
from bzrlib import (
 
26
from . import (
26
27
    errors,
 
28
    lock,
27
29
    mutabletree,
28
30
    revision as _mod_revision,
29
31
    )
30
 
from bzrlib.decorators import needs_read_lock
31
 
from bzrlib.osutils import sha_file
32
 
from bzrlib.mutabletree import needs_tree_write_lock
33
 
from bzrlib.transport.memory import MemoryTransport
34
 
 
35
 
 
36
 
class MemoryTree(mutabletree.MutableTree):
 
32
from .bzr.inventory import Inventory
 
33
from .bzr.inventorytree import MutableInventoryTree
 
34
from .osutils import sha_file
 
35
from .mutabletree import needs_tree_write_lock
 
36
from .transport.memory import MemoryTransport
 
37
 
 
38
 
 
39
class MemoryTree(MutableInventoryTree):
37
40
    """A MemoryTree is a specialisation of MutableTree.
38
41
 
39
42
    It maintains nearly no state outside of read_lock and write_lock
44
47
    def __init__(self, branch, revision_id):
45
48
        """Construct a MemoryTree for branch using revision_id."""
46
49
        self.branch = branch
47
 
        self.bzrdir = branch.bzrdir
 
50
        self.controldir = branch.controldir
48
51
        self._branch_revision_id = revision_id
49
52
        self._locks = 0
50
53
        self._lock_mode = None
51
54
 
 
55
    def get_config_stack(self):
 
56
        return self.branch.get_config_stack()
 
57
 
 
58
    def is_control_filename(self, filename):
 
59
        # Memory tree doesn't have any control filenames
 
60
        return False
 
61
 
52
62
    @needs_tree_write_lock
53
63
    def _add(self, files, ids, kinds):
54
64
        """See MutableTree._add."""
133
143
            return 0
134
144
        return entry.text_size
135
145
 
136
 
    @needs_read_lock
137
146
    def get_parent_ids(self):
138
147
        """See Tree.get_parent_ids.
139
148
 
140
149
        This implementation returns the current cached value from
141
150
            self._parent_ids.
142
151
        """
143
 
        return list(self._parent_ids)
 
152
        with self.lock_read():
 
153
            return list(self._parent_ids)
144
154
 
145
155
    def has_filename(self, filename):
146
156
        """See Tree.has_filename()."""
160
170
        self._file_transport.mkdir(path)
161
171
        return file_id
162
172
 
163
 
    @needs_read_lock
164
173
    def last_revision(self):
165
174
        """See MutableTree.last_revision."""
166
 
        return self._branch_revision_id
 
175
        with self.lock_read():
 
176
            return self._branch_revision_id
167
177
 
168
178
    def lock_read(self):
169
179
        """Lock the memory tree for reading.
176
186
                self.branch.lock_read()
177
187
                self._lock_mode = "r"
178
188
                self._populate_from_branch()
 
189
            return lock.LogicalLockResult(self.unlock)
179
190
        except:
180
191
            self._locks -= 1
181
192
            raise
193
204
        except:
194
205
            self._locks -= 1
195
206
            raise
 
207
        return lock.LogicalLockResult(self.unlock)
196
208
 
197
209
    def lock_write(self):
198
210
        """See MutableTree.lock_write()."""
204
216
                self._populate_from_branch()
205
217
            elif self._lock_mode == "r":
206
218
                raise errors.ReadOnlyError(self)
 
219
            return lock.LogicalLockResult(self.unlock)
207
220
        except:
208
221
            self._locks -= 1
209
222
            raise
215
228
            self._parent_ids = []
216
229
        else:
217
230
            self._parent_ids = [self._branch_revision_id]
218
 
        self._inventory = self._basis_tree._inventory._get_mutable_inventory()
 
231
        self._inventory = Inventory(None, self._basis_tree.get_revision_id())
219
232
        self._file_transport = MemoryTransport()
220
233
        # TODO copy the revision trees content, or do it lazy, or something.
221
 
        inventory_entries = self._inventory.iter_entries()
 
234
        inventory_entries = self._basis_tree.iter_entries_by_dir()
222
235
        for path, entry in inventory_entries:
 
236
            self._inventory.add(entry.copy())
223
237
            if path == '':
224
238
                continue
225
239
            if entry.kind == 'directory':
283
297
            self._branch_revision_id = revision_ids[0]
284
298
        self._allow_leftmost_as_ghost = allow_leftmost_as_ghost
285
299
        self._set_basis()
286
 
    
 
300
 
287
301
    def _set_basis(self):
288
302
        try:
289
303
            self._basis_tree = self.branch.repository.revision_tree(