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
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.
46
47
indicating that the revision was found/not found.
49
from bzrlib import errors
50
54
from bzrlib.branch import Branch
51
55
from bzrlib.bzrdir import BzrDir
52
56
from bzrlib.revision import NULL_REVISION
53
from bzrlib.symbol_versioning import deprecated_function, deprecated_in
54
57
from bzrlib.trace import note
56
58
from bzrlib.workingtree import WorkingTree
58
61
class Check(object):
59
62
"""Check a repository"""
64
def __init__(self, repository, check_repo=True):
65
self.repository = repository
67
def report_results(self, verbose):
68
raise NotImplementedError(self.report_results)
71
class VersionedFileCheck(Check):
72
"""Check a versioned file repository"""
61
74
# The Check object interacts with InventoryEntry.check, etc.
63
76
def __init__(self, repository, check_repo=True):
88
101
if callback_refs is None:
89
102
callback_refs = {}
90
103
self.repository.lock_read()
91
self.progress = bzrlib.ui.ui_factory.nested_progress_bar()
104
self.progress = ui.ui_factory.nested_progress_bar()
93
106
self.progress.update('check', 0, 4)
94
107
if self.check_repo:
170
183
# - we can fill out existence flags at this point
171
184
# - we can read the revision inventory sha at this point
172
185
# - we can check properties and serialisers etc.
173
if not self.repository.revision_graph_can_have_wrong_parents():
186
if not self.repository._format.revision_graph_can_have_wrong_parents:
174
187
# The check against the index isn't needed.
175
188
self.revs_with_bad_parents_in_index = None
176
189
for thing in revision_iterator:
328
341
self.text_key_references[key] = True
331
@deprecated_function(deprecated_in((1,6,0)))
332
def check(branch, verbose):
333
"""Run consistency checks on a branch.
335
Results are reported through logging.
337
Deprecated in 1.6. Please use check_dwim instead.
339
:raise BzrCheckError: if there's a consistency error.
341
check_branch(branch, verbose)
344
@deprecated_function(deprecated_in((1,16,0)))
345
def check_branch(branch, verbose):
346
"""Run consistency checks on a branch.
348
Results are reported through logging.
350
:raise BzrCheckError: if there's a consistency error.
355
for ref in branch._get_check_refs():
356
needed_refs.setdefault(ref, []).append(branch)
357
result = branch.repository.check([branch.last_revision()], needed_refs)
358
branch_result = result.other_results[0]
361
branch_result.report_results(verbose)
364
344
def scan_branch(branch, needed_refs, to_unlock):
365
345
"""Scan a branch for refs.