/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/reconcile.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:
36
36
from bzrlib.versionedfile import AdapterFactory, FulltextContentFactory
37
37
 
38
38
 
39
 
def reconcile(dir, other=None):
 
39
def reconcile(dir, canonicalize_chks=False):
40
40
    """Reconcile the data in dir.
41
41
 
42
42
    Currently this is limited to a inventory 'reweave'.
46
46
    Directly using Reconciler is recommended for library users that
47
47
    desire fine grained control or analysis of the found issues.
48
48
 
49
 
    :param other: another bzrdir to reconcile against.
 
49
    :param canonicalize_chks: Make sure CHKs are in canonical form.
50
50
    """
51
 
    reconciler = Reconciler(dir, other=other)
 
51
    reconciler = Reconciler(dir, canonicalize_chks=canonicalize_chks)
52
52
    reconciler.reconcile()
53
53
 
54
54
 
55
55
class Reconciler(object):
56
56
    """Reconcilers are used to reconcile existing data."""
57
57
 
58
 
    def __init__(self, dir, other=None):
 
58
    def __init__(self, dir, other=None, canonicalize_chks=False):
59
59
        """Create a Reconciler."""
60
60
        self.bzrdir = dir
 
61
        self.canonicalize_chks = canonicalize_chks
61
62
 
62
63
    def reconcile(self):
63
64
        """Perform reconciliation.
98
99
        ui.ui_factory.note('Reconciling repository %s' %
99
100
            self.repo.user_url)
100
101
        self.pb.update("Reconciling repository", 0, 1)
101
 
        repo_reconciler = self.repo.reconcile(thorough=True)
 
102
        if self.canonicalize_chks:
 
103
            try:
 
104
                self.repo.reconcile_canonicalize_chks
 
105
            except AttributeError:
 
106
                raise errors.BzrError(
 
107
                    "%s cannot canonicalize CHKs." % (self.repo,))
 
108
            repo_reconciler = self.repo.reconcile_canonicalize_chks()
 
109
        else:
 
110
            repo_reconciler = self.repo.reconcile(thorough=True)
102
111
        self.inconsistent_parents = repo_reconciler.inconsistent_parents
103
112
        self.garbage_inventories = repo_reconciler.garbage_inventories
104
113
        if repo_reconciler.aborted:
215
224
        only data-loss causing issues (!self.thorough) or all issues
216
225
        (self.thorough) are treated as requiring the reweave.
217
226
        """
218
 
        # local because needing to know about WeaveFile is a wart we want to hide
219
 
        from bzrlib.weave import WeaveFile, Weave
220
227
        transaction = self.repo.get_transaction()
221
228
        self.pb.update('Reading inventory data')
222
229
        self.inventory = self.repo.inventories
494
501
    #  - lock the names list
495
502
    #  - perform a customised pack() that regenerates data as needed
496
503
    #  - unlock the names list
497
 
    # https://bugs.edge.launchpad.net/bzr/+bug/154173
 
504
    # https://bugs.launchpad.net/bzr/+bug/154173
 
505
 
 
506
    def __init__(self, repo, other=None, thorough=False,
 
507
            canonicalize_chks=False):
 
508
        super(PackReconciler, self).__init__(repo, other=other,
 
509
            thorough=thorough)
 
510
        self.canonicalize_chks = canonicalize_chks
498
511
 
499
512
    def _reconcile_steps(self):
500
513
        """Perform the steps to reconcile this repository."""
509
522
        total_inventories = len(list(
510
523
            collection.inventory_index.combined_index.iter_all_entries()))
511
524
        if len(all_revisions):
512
 
            new_pack =  self.repo._reconcile_pack(collection, packs,
513
 
                ".reconcile", all_revisions, self.pb)
 
525
            if self.canonicalize_chks:
 
526
                reconcile_meth = self.repo._canonicalize_chks_pack
 
527
            else:
 
528
                reconcile_meth = self.repo._reconcile_pack
 
529
            new_pack = reconcile_meth(collection, packs, ".reconcile",
 
530
                all_revisions, self.pb)
514
531
            if new_pack is not None:
515
532
                self._discard_and_save(packs)
516
533
        else: