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

  • Committer: Jelmer Vernooij
  • Date: 2019-06-26 20:58:23 UTC
  • mto: This revision was merged to the branch mainline in revision 7378.
  • Revision ID: jelmer@jelmer.uk-20190626205823-ms7j2rgjd8oj0g97
Use ExitStack in more places.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
import stat
42
42
 
43
43
from breezy import (
 
44
    cleanup,
44
45
    conflicts as _mod_conflicts,
45
46
    errors,
46
47
    filters as _mod_filters,
998
999
    def revert(self, filenames=None, old_tree=None, backups=True,
999
1000
               pb=None, report_changes=False):
1000
1001
        from .conflicts import resolve
1001
 
        with self.lock_tree_write():
 
1002
        with cleanup.ExitStack() as exit_stack:
 
1003
            exit_stack.enter_context(self.lock_tree_write())
1002
1004
            if old_tree is None:
1003
1005
                basis_tree = self.basis_tree()
1004
 
                basis_tree.lock_read()
 
1006
                exit_stack.enter_context(basis_tree.lock_read())
1005
1007
                old_tree = basis_tree
1006
1008
            else:
1007
1009
                basis_tree = None
1008
 
            try:
1009
 
                conflicts = transform.revert(self, old_tree, filenames, backups, pb,
1010
 
                                             report_changes)
1011
 
                if filenames is None and len(self.get_parent_ids()) > 1:
1012
 
                    parent_trees = []
1013
 
                    last_revision = self.last_revision()
1014
 
                    if last_revision != _mod_revision.NULL_REVISION:
1015
 
                        if basis_tree is None:
1016
 
                            basis_tree = self.basis_tree()
1017
 
                            basis_tree.lock_read()
1018
 
                        parent_trees.append((last_revision, basis_tree))
1019
 
                    self.set_parent_trees(parent_trees)
1020
 
                    resolve(self)
1021
 
                else:
1022
 
                    resolve(self, filenames, ignore_misses=True, recursive=True)
1023
 
            finally:
1024
 
                if basis_tree is not None:
1025
 
                    basis_tree.unlock()
 
1010
            conflicts = transform.revert(self, old_tree, filenames, backups, pb,
 
1011
                                         report_changes)
 
1012
            if filenames is None and len(self.get_parent_ids()) > 1:
 
1013
                parent_trees = []
 
1014
                last_revision = self.last_revision()
 
1015
                if last_revision != _mod_revision.NULL_REVISION:
 
1016
                    if basis_tree is None:
 
1017
                        basis_tree = self.basis_tree()
 
1018
                        exit_stack.enter_context(basis_tree.lock_read())
 
1019
                    parent_trees.append((last_revision, basis_tree))
 
1020
                self.set_parent_trees(parent_trees)
 
1021
                resolve(self)
 
1022
            else:
 
1023
                resolve(self, filenames, ignore_misses=True, recursive=True)
1026
1024
            return conflicts
1027
1025
 
1028
1026
    def store_uncommitted(self):