32
32
# raising them. If there's more than one exception it'd be good to see them
35
from bzrlib import errors
35
from bzrlib import errors, osutils
36
36
from bzrlib import repository as _mod_repository
37
37
from bzrlib import revision
38
from bzrlib.branch import Branch
39
from bzrlib.bzrdir import BzrDir
38
40
from bzrlib.errors import BzrCheckError
41
from bzrlib.repository import Repository
42
from bzrlib.symbol_versioning import deprecated_function, deprecated_in
43
from bzrlib.trace import log_error, note
40
from bzrlib.trace import log_error, note
45
from bzrlib.workingtree import WorkingTree
42
47
class Check(object):
43
48
"""Check a repository"""
236
241
seen_names[path] = True
244
@deprecated_function(deprecated_in((1,6,0)))
239
245
def check(branch, verbose):
240
246
"""Run consistency checks on a branch.
242
248
Results are reported through logging.
250
Deprecated in 1.6. Please use check_branch instead.
252
:raise BzrCheckError: if there's a consistency error.
254
check_branch(branch, verbose)
257
def check_branch(branch, verbose):
258
"""Run consistency checks on a branch.
260
Results are reported through logging.
244
262
:raise BzrCheckError: if there's a consistency error.
246
264
branch.lock_read()
248
266
branch_result = branch.check()
249
repo_result = branch.repository.check([branch.last_revision()])
252
269
branch_result.report_results(verbose)
253
repo_result.report_results(verbose)
272
def check_dwim(path, verbose):
273
tree, branch, repo, relpath = BzrDir.open_containing_tree_branch_or_repository(path)
276
note("Checking working tree at '%s'."
277
% (tree.bzrdir.root_transport.base,))
280
if branch is not None:
283
# The branch is in a shared repository
284
repo = branch.repository
286
elif repo is not None:
287
branches = repo.find_branches(using=True)
292
note("Checking repository at '%s'."
293
% (repo.bzrdir.root_transport.base,))
294
result = repo.check()
295
result.report_results(verbose)
296
for branch in branches:
297
note("Checking branch at '%s'."
298
% (branch.bzrdir.root_transport.base,))
299
check_branch(branch, verbose)