/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

  • Committer: Jelmer Vernooij
  • Date: 2017-08-29 21:29:35 UTC
  • mfrom: (6754.8.21 lock-context-2)
  • mto: This revision was merged to the branch mainline in revision 6784.
  • Revision ID: jelmer@jelmer.uk-20170829212935-lakl2jhq9sqckejp
Merge lock-context-2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
from . import (
27
27
    errors,
28
 
    mutabletree,
 
28
    lock,
29
29
    revision as _mod_revision,
30
30
    )
31
 
from .decorators import needs_read_lock
32
31
from .bzr.inventory import Inventory
33
32
from .bzr.inventorytree import MutableInventoryTree
34
33
from .osutils import sha_file
35
 
from .mutabletree import needs_tree_write_lock
36
34
from .transport.memory import MemoryTransport
37
35
 
38
36
 
59
57
        # Memory tree doesn't have any control filenames
60
58
        return False
61
59
 
62
 
    @needs_tree_write_lock
63
60
    def _add(self, files, ids, kinds):
64
61
        """See MutableTree._add."""
65
 
        for f, file_id, kind in zip(files, ids, kinds):
66
 
            if kind is None:
67
 
                kind = 'file'
68
 
            if file_id is None:
69
 
                self._inventory.add_path(f, kind=kind)
70
 
            else:
71
 
                self._inventory.add_path(f, kind=kind, file_id=file_id)
 
62
        with self.lock_tree_write():
 
63
            for f, file_id, kind in zip(files, ids, kinds):
 
64
                if kind is None:
 
65
                    kind = 'file'
 
66
                if file_id is None:
 
67
                    self._inventory.add_path(f, kind=kind)
 
68
                else:
 
69
                    self._inventory.add_path(f, kind=kind, file_id=file_id)
72
70
 
73
71
    def basis_tree(self):
74
72
        """See Tree.basis_tree()."""
109
107
            return None, False, None
110
108
        return entry.kind, entry.executable, None
111
109
 
112
 
    @needs_tree_write_lock
113
110
    def rename_one(self, from_rel, to_rel):
114
 
        file_id = self.path2id(from_rel)
115
 
        to_dir, to_tail = os.path.split(to_rel)
116
 
        to_parent_id = self.path2id(to_dir)
117
 
        self._file_transport.move(from_rel, to_rel)
118
 
        self._inventory.rename(file_id, to_parent_id, to_tail)
 
111
        with self.lock_tree_write():
 
112
            file_id = self.path2id(from_rel)
 
113
            to_dir, to_tail = os.path.split(to_rel)
 
114
            to_parent_id = self.path2id(to_dir)
 
115
            self._file_transport.move(from_rel, to_rel)
 
116
            self._inventory.rename(file_id, to_parent_id, to_tail)
119
117
 
120
118
    def path_content_summary(self, path):
121
119
        """See Tree.path_content_summary."""
143
141
            return 0
144
142
        return entry.text_size
145
143
 
146
 
    @needs_read_lock
147
144
    def get_parent_ids(self):
148
145
        """See Tree.get_parent_ids.
149
146
 
150
147
        This implementation returns the current cached value from
151
148
            self._parent_ids.
152
149
        """
153
 
        return list(self._parent_ids)
 
150
        with self.lock_read():
 
151
            return list(self._parent_ids)
154
152
 
155
153
    def has_filename(self, filename):
156
154
        """See Tree.has_filename()."""
170
168
        self._file_transport.mkdir(path)
171
169
        return file_id
172
170
 
173
 
    @needs_read_lock
174
171
    def last_revision(self):
175
172
        """See MutableTree.last_revision."""
176
 
        return self._branch_revision_id
 
173
        with self.lock_read():
 
174
            return self._branch_revision_id
177
175
 
178
176
    def lock_read(self):
179
177
        """Lock the memory tree for reading.
186
184
                self.branch.lock_read()
187
185
                self._lock_mode = "r"
188
186
                self._populate_from_branch()
 
187
            return lock.LogicalLockResult(self.unlock)
189
188
        except:
190
189
            self._locks -= 1
191
190
            raise
203
202
        except:
204
203
            self._locks -= 1
205
204
            raise
 
205
        return lock.LogicalLockResult(self.unlock)
206
206
 
207
207
    def lock_write(self):
208
208
        """See MutableTree.lock_write()."""
214
214
                self._populate_from_branch()
215
215
            elif self._lock_mode == "r":
216
216
                raise errors.ReadOnlyError(self)
 
217
            return lock.LogicalLockResult(self.unlock)
217
218
        except:
218
219
            self._locks -= 1
219
220
            raise
263
264
        else:
264
265
            self._locks -= 1
265
266
 
266
 
    @needs_tree_write_lock
267
267
    def unversion(self, file_ids):
268
268
        """Remove the file ids in file_ids from the current versioned set.
269
269
 
273
273
        :param file_ids: The file ids to stop versioning.
274
274
        :raises: NoSuchId if any fileid is not currently versioned.
275
275
        """
276
 
        # XXX: This should be in mutabletree, but the inventory-save action
277
 
        # is not relevant to memory tree. Until that is done in unlock by
278
 
        # working tree, we cannot share the implementation.
279
 
        for file_id in file_ids:
280
 
            if self._inventory.has_id(file_id):
281
 
                self._inventory.remove_recursive_id(file_id)
282
 
            else:
283
 
                raise errors.NoSuchId(self, file_id)
 
276
        with self.lock_tree_write():
 
277
            # XXX: This should be in mutabletree, but the inventory-save action
 
278
            # is not relevant to memory tree. Until that is done in unlock by
 
279
            # working tree, we cannot share the implementation.
 
280
            for file_id in file_ids:
 
281
                if self._inventory.has_id(file_id):
 
282
                    self._inventory.remove_recursive_id(file_id)
 
283
                else:
 
284
                    raise errors.NoSuchId(self, file_id)
284
285
 
285
286
    def set_parent_ids(self, revision_ids, allow_leftmost_as_ghost=False):
286
287
        """See MutableTree.set_parent_trees()."""