/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: 2018-06-14 17:59:16 UTC
  • mto: This revision was merged to the branch mainline in revision 7065.
  • Revision ID: jelmer@jelmer.uk-20180614175916-a2e2xh5k533guq1x
Move breezy.plugins.git to breezy.git.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
  indicating that the revision was found/not found.
35
35
"""
36
36
 
37
 
import contextlib
 
37
from __future__ import absolute_import
38
38
 
39
39
from . import (
40
40
    errors,
 
41
    ui,
41
42
    )
 
43
from .branch import Branch
42
44
from .controldir import ControlDir
 
45
from .revision import NULL_REVISION
 
46
from .sixish import (
 
47
    viewitems,
 
48
    )
43
49
from .trace import note
 
50
from .workingtree import WorkingTree
44
51
from .i18n import gettext
45
52
 
46
 
 
47
53
class Check(object):
48
54
    """Check a repository"""
49
55
 
54
60
        raise NotImplementedError(self.report_results)
55
61
 
56
62
 
57
 
def scan_branch(branch, needed_refs, exit_stack):
 
63
def scan_branch(branch, needed_refs, to_unlock):
58
64
    """Scan a branch for refs.
59
65
 
60
66
    :param branch:  The branch to schedule for checking.
61
67
    :param needed_refs: Refs we are accumulating.
62
 
    :param exit_stack: The exit stack accumulating.
 
68
    :param to_unlock: The unlock list accumulating.
63
69
    """
64
70
    note(gettext("Checking branch at '%s'.") % (branch.base,))
65
 
    exit_stack.enter_context(branch.lock_read())
 
71
    branch.lock_read()
 
72
    to_unlock.append(branch)
66
73
    branch_refs = branch._get_check_refs()
67
74
    for ref in branch_refs:
68
75
        reflist = needed_refs.setdefault(ref, [])
69
76
        reflist.append(branch)
70
77
 
71
78
 
72
 
def scan_tree(base_tree, tree, needed_refs, exit_stack):
 
79
def scan_tree(base_tree, tree, needed_refs, to_unlock):
73
80
    """Scan a tree for refs.
74
81
 
75
82
    :param base_tree: The original tree check opened, used to detect duplicate
76
83
        tree checks.
77
84
    :param tree:  The tree to schedule for checking.
78
85
    :param needed_refs: Refs we are accumulating.
79
 
    :param exit_stack: The exit stack accumulating.
 
86
    :param to_unlock: The unlock list accumulating.
80
87
    """
81
88
    if base_tree is not None and tree.basedir == base_tree.basedir:
82
89
        return
83
90
    note(gettext("Checking working tree at '%s'.") % (tree.basedir,))
84
 
    exit_stack.enter_context(tree.lock_read())
 
91
    tree.lock_read()
 
92
    to_unlock.append(tree)
85
93
    tree_refs = tree._get_check_refs()
86
94
    for ref in tree_refs:
87
95
        reflist = needed_refs.setdefault(ref, [])
96
104
    """
97
105
    try:
98
106
        base_tree, branch, repo, relpath = \
99
 
            ControlDir.open_containing_tree_branch_or_repository(path)
 
107
                        ControlDir.open_containing_tree_branch_or_repository(path)
100
108
    except errors.NotBranchError:
101
109
        base_tree = branch = repo = None
102
110
 
103
 
    with contextlib.ExitStack() as exit_stack:
104
 
        needed_refs = {}
 
111
    to_unlock = []
 
112
    needed_refs= {}
 
113
    try:
105
114
        if base_tree is not None:
106
115
            # If the tree is a lightweight checkout we won't see it in
107
116
            # repo.find_branches - add now.
108
117
            if do_tree:
109
 
                scan_tree(None, base_tree, needed_refs, exit_stack)
 
118
                scan_tree(None, base_tree, needed_refs, to_unlock)
110
119
            branch = base_tree.branch
111
120
        if branch is not None:
112
121
            # We have a branch
114
123
                # The branch is in a shared repository
115
124
                repo = branch.repository
116
125
        if repo is not None:
117
 
            exit_stack.enter_context(repo.lock_read())
118
 
            branches = list(repo.find_branches(using=True))
 
126
            repo.lock_read()
 
127
            to_unlock.append(repo)
 
128
            branches = repo.find_branches(using=True)
119
129
            saw_tree = False
120
130
            if do_branch or do_tree:
121
131
                for branch in branches:
126
136
                        except (errors.NotLocalUrl, errors.NoWorkingTree):
127
137
                            pass
128
138
                        else:
129
 
                            scan_tree(base_tree, tree, needed_refs, exit_stack)
 
139
                            scan_tree(base_tree, tree, needed_refs, to_unlock)
130
140
                    if do_branch:
131
 
                        scan_branch(branch, needed_refs, exit_stack)
 
141
                        scan_branch(branch, needed_refs, to_unlock)
132
142
            if do_branch and not branches:
133
143
                note(gettext("No branch found at specified location."))
134
144
            if do_tree and base_tree is None and not saw_tree:
138
148
                    note(gettext("Checking repository at '%s'.")
139
149
                         % (repo.user_url,))
140
150
                result = repo.check(None, callback_refs=needed_refs,
141
 
                                    check_repo=do_repo)
 
151
                    check_repo=do_repo)
142
152
                result.report_results(verbose)
143
153
        else:
144
154
            if do_tree:
147
157
                note(gettext("No branch found at specified location."))
148
158
            if do_repo:
149
159
                note(gettext("No repository found at specified location."))
 
160
    finally:
 
161
        for thing in to_unlock:
 
162
            thing.unlock()