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

  • Committer: John Arbash Meinel
  • Date: 2011-04-20 14:27:19 UTC
  • mto: This revision was merged to the branch mainline in revision 5837.
  • Revision ID: john@arbash-meinel.com-20110420142719-advs1k5vztqzbrgv
Fix bug #767177. Be more agressive with file.close() calls.

Our test suite gets a number of thread leaks and failures because it happens to get async
SFTPFile.close() calls. (if an SFTPFile closes due to __del__ it is done as an async request,
while if you call SFTPFile.close() it is done as a synchronous request.)
We have a couple other cases, probably. Namely SFTPTransport.get() also does an async
prefetch of the content, so if you don't .read() you'll also leak threads that think they
are doing work that you want.

The biggest change here, though, is using a try/finally in a generator, which is not 
python2.4 compatible.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
    revision as _mod_revision,
29
29
    )
30
30
from bzrlib.decorators import needs_read_lock
 
31
from bzrlib.inventory import Inventory
31
32
from bzrlib.osutils import sha_file
32
33
from bzrlib.mutabletree import needs_tree_write_lock
33
34
from bzrlib.transport.memory import MemoryTransport
34
35
 
35
36
 
36
 
class MemoryTree(mutabletree.MutableTree):
 
37
class MemoryTree(mutabletree.MutableInventoryTree):
37
38
    """A MemoryTree is a specialisation of MutableTree.
38
39
 
39
40
    It maintains nearly no state outside of read_lock and write_lock
49
50
        self._locks = 0
50
51
        self._lock_mode = None
51
52
 
 
53
    def is_control_filename(self, filename):
 
54
        # Memory tree doesn't have any control filenames
 
55
        return False
 
56
 
52
57
    @needs_tree_write_lock
53
58
    def _add(self, files, ids, kinds):
54
59
        """See MutableTree._add."""
215
220
            self._parent_ids = []
216
221
        else:
217
222
            self._parent_ids = [self._branch_revision_id]
218
 
        self._inventory = self._basis_tree._inventory._get_mutable_inventory()
 
223
        self._inventory = Inventory(None, self._basis_tree.get_revision_id())
219
224
        self._file_transport = MemoryTransport()
220
225
        # TODO copy the revision trees content, or do it lazy, or something.
221
 
        inventory_entries = self._inventory.iter_entries()
 
226
        inventory_entries = self._basis_tree.iter_entries_by_dir()
222
227
        for path, entry in inventory_entries:
 
228
            self._inventory.add(entry.copy())
223
229
            if path == '':
224
230
                continue
225
231
            if entry.kind == 'directory':