~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/check.py

Move WT checking from builtins to check.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
from bzrlib.repository import Repository
41
41
import bzrlib.ui
42
42
from bzrlib.trace import log_error, note
 
43
from bzrlib.workingtree import WorkingTree
43
44
 
44
45
class Check(object):
45
46
    """Check a repository"""
285
286
    result.report_results(verbose)
286
287
 
287
288
 
 
289
def _check_working_tree(tree):
 
290
    # bit hacky, check the tree parent is accurate
 
291
    tree.lock_read()
 
292
    try:
 
293
        tree_basis = tree.basis_tree()
 
294
        tree_basis.lock_read()
 
295
        try:
 
296
            repo_basis = tree.branch.repository.revision_tree(
 
297
                tree.last_revision())
 
298
            if len(list(repo_basis._iter_changes(tree_basis))):
 
299
                raise errors.BzrCheckError(
 
300
                    "Mismatched basis inventory content.")
 
301
            tree._validate()
 
302
        finally:
 
303
            tree_basis.unlock()
 
304
    finally:
 
305
        tree.unlock()
 
306
 
 
307
 
288
308
def check(path, verbose):
289
309
    try:
290
310
        branch = Branch.open_containing(path)[0]
296
316
    except errors.NoRepositoryPresent:
297
317
        repo = None
298
318
 
 
319
    try:
 
320
        tree = WorkingTree.open(path)
 
321
    except (errors.NoWorkingTree, errors.NotLocalUrl):
 
322
        tree = None
 
323
 
 
324
    if tree is not None:
 
325
        _check_working_tree(path)
 
326
 
299
327
    if branch is not None:
300
328
        # We are in a branch
301
329
        if repo is None: