/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-09-06 04:15:55 UTC
  • mfrom: (6754.8.21 lock-context-2)
  • Revision ID: jelmer@jelmer.uk-20170906041555-jtr5qxli38167gc6
Merge lp:~jelmer/brz/lock-context-2.

Show diffs side-by-side

added added

removed removed

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