/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-01 07:15:43 UTC
  • mfrom: (6770.3.2 py3_test_cleanup)
  • Revision ID: jelmer@jelmer.uk-20170901071543-1t83321xkog9qrxh
Merge lp:~gz/brz/py3_test_cleanup

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 .decorators import needs_read_lock
 
33
from .bzr.inventory import Inventory
 
34
from .bzr.inventorytree import MutableInventoryTree
 
35
from .osutils import sha_file
 
36
from .mutabletree import needs_tree_write_lock
 
37
from .transport.memory import MemoryTransport
 
38
 
 
39
 
 
40
class MemoryTree(MutableInventoryTree):
37
41
    """A MemoryTree is a specialisation of MutableTree.
38
42
 
39
43
    It maintains nearly no state outside of read_lock and write_lock
44
48
    def __init__(self, branch, revision_id):
45
49
        """Construct a MemoryTree for branch using revision_id."""
46
50
        self.branch = branch
47
 
        self.bzrdir = branch.bzrdir
 
51
        self.controldir = branch.controldir
48
52
        self._branch_revision_id = revision_id
49
53
        self._locks = 0
50
54
        self._lock_mode = None
51
55
 
 
56
    def get_config_stack(self):
 
57
        return self.branch.get_config_stack()
 
58
 
 
59
    def is_control_filename(self, filename):
 
60
        # Memory tree doesn't have any control filenames
 
61
        return False
 
62
 
52
63
    @needs_tree_write_lock
53
64
    def _add(self, files, ids, kinds):
54
65
        """See MutableTree._add."""
176
187
                self.branch.lock_read()
177
188
                self._lock_mode = "r"
178
189
                self._populate_from_branch()
 
190
            return lock.LogicalLockResult(self.unlock)
179
191
        except:
180
192
            self._locks -= 1
181
193
            raise
193
205
        except:
194
206
            self._locks -= 1
195
207
            raise
 
208
        return lock.LogicalLockResult(self.unlock)
196
209
 
197
210
    def lock_write(self):
198
211
        """See MutableTree.lock_write()."""
204
217
                self._populate_from_branch()
205
218
            elif self._lock_mode == "r":
206
219
                raise errors.ReadOnlyError(self)
 
220
            return lock.LogicalLockResult(self.unlock)
207
221
        except:
208
222
            self._locks -= 1
209
223
            raise
215
229
            self._parent_ids = []
216
230
        else:
217
231
            self._parent_ids = [self._branch_revision_id]
218
 
        self._inventory = self._basis_tree._inventory._get_mutable_inventory()
 
232
        self._inventory = Inventory(None, self._basis_tree.get_revision_id())
219
233
        self._file_transport = MemoryTransport()
220
234
        # TODO copy the revision trees content, or do it lazy, or something.
221
 
        inventory_entries = self._inventory.iter_entries()
 
235
        inventory_entries = self._basis_tree.iter_entries_by_dir()
222
236
        for path, entry in inventory_entries:
 
237
            self._inventory.add(entry.copy())
223
238
            if path == '':
224
239
                continue
225
240
            if entry.kind == 'directory':
283
298
            self._branch_revision_id = revision_ids[0]
284
299
        self._allow_leftmost_as_ghost = allow_leftmost_as_ghost
285
300
        self._set_basis()
286
 
    
 
301
 
287
302
    def _set_basis(self):
288
303
        try:
289
304
            self._basis_tree = self.branch.repository.revision_tree(