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

  • Committer: Jelmer Vernooij
  • Date: 2020-04-05 19:11:34 UTC
  • mto: (7490.7.16 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200405191134-0aebh8ikiwygxma5
Populate the .gitignore file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
from __future__ import absolute_import
38
38
 
39
39
from . import (
 
40
    cleanup,
40
41
    errors,
41
42
    )
42
43
from .controldir import ControlDir
54
55
        raise NotImplementedError(self.report_results)
55
56
 
56
57
 
57
 
def scan_branch(branch, needed_refs, to_unlock):
 
58
def scan_branch(branch, needed_refs, exit_stack):
58
59
    """Scan a branch for refs.
59
60
 
60
61
    :param branch:  The branch to schedule for checking.
61
62
    :param needed_refs: Refs we are accumulating.
62
 
    :param to_unlock: The unlock list accumulating.
 
63
    :param exit_stack: The exit stack accumulating.
63
64
    """
64
65
    note(gettext("Checking branch at '%s'.") % (branch.base,))
65
 
    branch.lock_read()
66
 
    to_unlock.append(branch)
 
66
    exit_stack.enter_context(branch.lock_read())
67
67
    branch_refs = branch._get_check_refs()
68
68
    for ref in branch_refs:
69
69
        reflist = needed_refs.setdefault(ref, [])
70
70
        reflist.append(branch)
71
71
 
72
72
 
73
 
def scan_tree(base_tree, tree, needed_refs, to_unlock):
 
73
def scan_tree(base_tree, tree, needed_refs, exit_stack):
74
74
    """Scan a tree for refs.
75
75
 
76
76
    :param base_tree: The original tree check opened, used to detect duplicate
77
77
        tree checks.
78
78
    :param tree:  The tree to schedule for checking.
79
79
    :param needed_refs: Refs we are accumulating.
80
 
    :param to_unlock: The unlock list accumulating.
 
80
    :param exit_stack: The exit stack accumulating.
81
81
    """
82
82
    if base_tree is not None and tree.basedir == base_tree.basedir:
83
83
        return
84
84
    note(gettext("Checking working tree at '%s'.") % (tree.basedir,))
85
 
    tree.lock_read()
86
 
    to_unlock.append(tree)
 
85
    exit_stack.enter_context(tree.lock_read())
87
86
    tree_refs = tree._get_check_refs()
88
87
    for ref in tree_refs:
89
88
        reflist = needed_refs.setdefault(ref, [])
102
101
    except errors.NotBranchError:
103
102
        base_tree = branch = repo = None
104
103
 
105
 
    to_unlock = []
106
 
    needed_refs = {}
107
 
    try:
 
104
    with cleanup.ExitStack() as exit_stack:
 
105
        needed_refs = {}
108
106
        if base_tree is not None:
109
107
            # If the tree is a lightweight checkout we won't see it in
110
108
            # repo.find_branches - add now.
111
109
            if do_tree:
112
 
                scan_tree(None, base_tree, needed_refs, to_unlock)
 
110
                scan_tree(None, base_tree, needed_refs, exit_stack)
113
111
            branch = base_tree.branch
114
112
        if branch is not None:
115
113
            # We have a branch
117
115
                # The branch is in a shared repository
118
116
                repo = branch.repository
119
117
        if repo is not None:
120
 
            repo.lock_read()
121
 
            to_unlock.append(repo)
122
 
            branches = repo.find_branches(using=True)
 
118
            exit_stack.enter_context(repo.lock_read())
 
119
            branches = list(repo.find_branches(using=True))
123
120
            saw_tree = False
124
121
            if do_branch or do_tree:
125
122
                for branch in branches:
130
127
                        except (errors.NotLocalUrl, errors.NoWorkingTree):
131
128
                            pass
132
129
                        else:
133
 
                            scan_tree(base_tree, tree, needed_refs, to_unlock)
 
130
                            scan_tree(base_tree, tree, needed_refs, exit_stack)
134
131
                    if do_branch:
135
 
                        scan_branch(branch, needed_refs, to_unlock)
 
132
                        scan_branch(branch, needed_refs, exit_stack)
136
133
            if do_branch and not branches:
137
134
                note(gettext("No branch found at specified location."))
138
135
            if do_tree and base_tree is None and not saw_tree:
151
148
                note(gettext("No branch found at specified location."))
152
149
            if do_repo:
153
150
                note(gettext("No repository found at specified location."))
154
 
    finally:
155
 
        for thing in to_unlock:
156
 
            thing.unlock()