/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/index.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:
1
 
# Copyright (C) 2007-2010 Canonical Ltd
 
1
# Copyright (C) 2007-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
31
31
 
32
32
from bzrlib.lazy_import import lazy_import
33
33
lazy_import(globals(), """
34
 
from bzrlib import trace
35
 
from bzrlib.bisect_multi import bisect_multi_bytes
36
 
from bzrlib.revision import NULL_REVISION
37
 
from bzrlib.trace import mutter
 
34
from bzrlib import (
 
35
    bisect_multi,
 
36
    revision as _mod_revision,
 
37
    trace,
 
38
    )
38
39
""")
39
40
from bzrlib import (
40
41
    debug,
444
445
            # We already did this
445
446
            return
446
447
        if 'index' in debug.debug_flags:
447
 
            mutter('Reading entire index %s', self._transport.abspath(self._name))
 
448
            trace.mutter('Reading entire index %s',
 
449
                          self._transport.abspath(self._name))
448
450
        if stream is None:
449
451
            stream = self._transport.get(self._name)
450
452
            if self._base_offset != 0:
462
464
        trailers = 0
463
465
        pos = stream.tell()
464
466
        lines = stream.read().split('\n')
 
467
        # GZ 2009-09-20: Should really use a try/finally block to ensure close
465
468
        stream.close()
466
469
        del lines[-1]
467
470
        _, _, _, trailers = self._parse_lines(lines, pos)
670
673
        if self._nodes is not None:
671
674
            return self._iter_entries_from_total_buffer(keys)
672
675
        else:
673
 
            return (result[1] for result in bisect_multi_bytes(
 
676
            return (result[1] for result in bisect_multi.bisect_multi_bytes(
674
677
                self._lookup_keys_via_location, self._size, keys))
675
678
 
676
679
    def iter_entries_prefix(self, keys):
1287
1290
    def get_parent_map(self, keys):
1288
1291
        """See graph.StackedParentsProvider.get_parent_map"""
1289
1292
        search_keys = set(keys)
1290
 
        if NULL_REVISION in search_keys:
1291
 
            search_keys.discard(NULL_REVISION)
1292
 
            found_parents = {NULL_REVISION:[]}
 
1293
        if _mod_revision.NULL_REVISION in search_keys:
 
1294
            search_keys.discard(_mod_revision.NULL_REVISION)
 
1295
            found_parents = {_mod_revision.NULL_REVISION:[]}
1293
1296
        else:
1294
1297
            found_parents = {}
1295
1298
        for index, key, value, refs in self.iter_entries(search_keys):
1296
1299
            parents = refs[0]
1297
1300
            if not parents:
1298
 
                parents = (NULL_REVISION,)
 
1301
                parents = (_mod_revision.NULL_REVISION,)
1299
1302
            found_parents[key] = parents
1300
1303
        return found_parents
1301
1304
 
1433
1436
        """
1434
1437
        indices_info = zip(self._index_names, self._indices)
1435
1438
        if 'index' in debug.debug_flags:
1436
 
            mutter('CombinedGraphIndex reordering: currently %r, promoting %r',
1437
 
                   indices_info, hit_indices)
 
1439
            trace.mutter('CombinedGraphIndex reordering: currently %r, '
 
1440
                         'promoting %r', indices_info, hit_indices)
1438
1441
        hit_names = []
1439
1442
        unhit_names = []
1440
1443
        new_hit_indices = []
1457
1460
        self._indices = new_hit_indices + unhit_indices
1458
1461
        self._index_names = hit_names + unhit_names
1459
1462
        if 'index' in debug.debug_flags:
1460
 
            mutter('CombinedGraphIndex reordered: %r', self._indices)
 
1463
            trace.mutter('CombinedGraphIndex reordered: %r', self._indices)
1461
1464
        return hit_names
1462
1465
 
1463
1466
    def _move_to_front_by_name(self, hit_names):