34
34
indicating that the revision was found/not found.
37
from __future__ import absolute_import
43
from .branch import Branch
42
44
from .controldir import ControlDir
45
from .revision import NULL_REVISION
43
49
from .trace import note
50
from .workingtree import WorkingTree
44
51
from .i18n import gettext
47
53
class Check(object):
48
54
"""Check a repository"""
54
60
raise NotImplementedError(self.report_results)
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.
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.
64
70
note(gettext("Checking branch at '%s'.") % (branch.base,))
65
exit_stack.enter_context(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)
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.
75
82
:param base_tree: The original tree check opened, used to detect duplicate
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.
81
88
if base_tree is not None and tree.basedir == base_tree.basedir:
83
90
note(gettext("Checking working tree at '%s'.") % (tree.basedir,))
84
exit_stack.enter_context(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, [])
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
103
with contextlib.ExitStack() as exit_stack:
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.
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
126
136
except (errors.NotLocalUrl, errors.NoWorkingTree):
129
scan_tree(base_tree, tree, needed_refs, exit_stack)
139
scan_tree(base_tree, tree, needed_refs, to_unlock)
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: