/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: 2019-05-20 03:57:29 UTC
  • mto: This revision was merged to the branch mainline in revision 7328.
  • Revision ID: jelmer@jelmer.uk-20190520035729-9rxvefxkvbbivygy
use default_user_agent function.

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