~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/check.py

  • Committer: Robert Collins
  • Date: 2009-05-08 02:06:36 UTC
  • mto: This revision was merged to the branch mainline in revision 4593.
  • Revision ID: robertc@robertcollins.net-20090508020636-f5w6t5ry2g1xluyo
Extract repository access in WorkingTree._check to be data driven, adding a new _get_check_refs method to support this.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
# raising them.  If there's more than one exception it'd be good to see them
33
33
# all.
34
34
 
 
35
"""Checking of bzr objects.
 
36
 
 
37
check_refs is a concept used for optimising check. Objects that depend on other
 
38
objects (e.g. tree on repository) can list the objects they would be requesting
 
39
so that when the dependent object is checked, matches can be pulled out and
 
40
evaluated in-line rather than re-reading the same data many times.
 
41
check_refs are tuples (kind, value). Currently defined kinds are:
 
42
* 'trees', where value is a revid.
 
43
"""
 
44
 
35
45
from bzrlib import errors, osutils
36
46
from bzrlib import repository as _mod_repository
37
47
from bzrlib import revision
296
306
        if tree is not None:
297
307
            note("Checking working tree at '%s'."
298
308
                 % (tree.bzrdir.root_transport.base,))
299
 
            tree._check()
 
309
            tree.lock_read()
 
310
            try:
 
311
                needed_refs = tree._get_check_refs()
 
312
                refs = {}
 
313
                for ref in needed_refs:
 
314
                    kind, value = ref
 
315
                    if kind == 'trees':
 
316
                        refs[ref] = tree.branch.repository.revision_tree(value)
 
317
                    else:
 
318
                        raise AssertionError(
 
319
                            'unknown ref kind for ref %s' % ref)
 
320
                tree._check(refs)
 
321
            finally:
 
322
                tree.unlock()
300
323
        else:
301
324
            log_error("No working tree found at specified location.")
302
325