~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/check.py

  • Committer: Vincent Ladeuil
  • Date: 2011-07-06 09:22:00 UTC
  • mfrom: (6008 +trunk)
  • mto: (6012.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 6013.
  • Revision ID: v.ladeuil+lp@free.fr-20110706092200-7iai2mwzc0sqdsvf
MergingĀ inĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
so that when the dependent object is checked, matches can be pulled out and
40
40
evaluated in-line rather than re-reading the same data many times.
41
41
check_refs are tuples (kind, value). Currently defined kinds are:
 
42
 
42
43
* 'trees', where value is a revid and the looked up objects are revision trees.
43
44
* 'lefthand-distance', where value is a revid and the looked up objects are the
44
45
  distance along the lefthand path to NULL for that revid.
53
54
from bzrlib.branch import Branch
54
55
from bzrlib.bzrdir import BzrDir
55
56
from bzrlib.revision import NULL_REVISION
56
 
from bzrlib.symbol_versioning import deprecated_function, deprecated_in
57
57
from bzrlib.trace import note
58
58
from bzrlib.workingtree import WorkingTree
59
59
 
 
60
 
60
61
class Check(object):
61
62
    """Check a repository"""
62
63
 
 
64
    def __init__(self, repository, check_repo=True):
 
65
        self.repository = repository
 
66
 
 
67
    def report_results(self, verbose):
 
68
        raise NotImplementedError(self.report_results)
 
69
 
 
70
 
 
71
class VersionedFileCheck(Check):
 
72
    """Check a versioned file repository"""
 
73
 
63
74
    # The Check object interacts with InventoryEntry.check, etc.
64
75
 
65
76
    def __init__(self, repository, check_repo=True):
172
183
        # - we can fill out existence flags at this point
173
184
        # - we can read the revision inventory sha at this point
174
185
        # - we can check properties and serialisers etc.
175
 
        if not self.repository.revision_graph_can_have_wrong_parents():
 
186
        if not self.repository._format.revision_graph_can_have_wrong_parents:
176
187
            # The check against the index isn't needed.
177
188
            self.revs_with_bad_parents_in_index = None
178
189
            for thing in revision_iterator:
330
341
            self.text_key_references[key] = True
331
342
 
332
343
 
333
 
@deprecated_function(deprecated_in((1,6,0)))
334
 
def check(branch, verbose):
335
 
    """Run consistency checks on a branch.
336
 
 
337
 
    Results are reported through logging.
338
 
 
339
 
    Deprecated in 1.6.  Please use check_dwim instead.
340
 
 
341
 
    :raise BzrCheckError: if there's a consistency error.
342
 
    """
343
 
    check_branch(branch, verbose)
344
 
 
345
 
 
346
 
@deprecated_function(deprecated_in((1,16,0)))
347
 
def check_branch(branch, verbose):
348
 
    """Run consistency checks on a branch.
349
 
 
350
 
    Results are reported through logging.
351
 
 
352
 
    :raise BzrCheckError: if there's a consistency error.
353
 
    """
354
 
    branch.lock_read()
355
 
    try:
356
 
        needed_refs = {}
357
 
        for ref in branch._get_check_refs():
358
 
            needed_refs.setdefault(ref, []).append(branch)
359
 
        result = branch.repository.check([branch.last_revision()], needed_refs)
360
 
        branch_result = result.other_results[0]
361
 
    finally:
362
 
        branch.unlock()
363
 
    branch_result.report_results(verbose)
364
 
 
365
 
 
366
344
def scan_branch(branch, needed_refs, to_unlock):
367
345
    """Scan a branch for refs.
368
346