~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/check.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-08-17 08:40:16 UTC
  • mfrom: (5642.4.6 712474-module-available)
  • Revision ID: pqm@pqm.ubuntu.com-20110817084016-600z65qzqmmt44w7
(vila) ModuleAvailableFeature don't try to imported already imported
 modules. (Vincent Ladeuil)

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.
46
47
  indicating that the revision was found/not found.
47
48
"""
48
49
 
49
 
from bzrlib import errors, osutils
50
 
from bzrlib import repository as _mod_repository
51
 
from bzrlib import revision
 
50
from bzrlib import (
 
51
    errors,
 
52
    ui,
 
53
    )
52
54
from bzrlib.branch import Branch
53
55
from bzrlib.bzrdir import BzrDir
54
 
from bzrlib.errors import BzrCheckError
55
 
from bzrlib.repository import Repository
56
56
from bzrlib.revision import NULL_REVISION
57
 
from bzrlib.symbol_versioning import deprecated_function, deprecated_in
58
57
from bzrlib.trace import note
59
 
import bzrlib.ui
60
58
from bzrlib.workingtree import WorkingTree
61
59
 
 
60
 
62
61
class Check(object):
63
62
    """Check a repository"""
64
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
 
65
74
    # The Check object interacts with InventoryEntry.check, etc.
66
75
 
67
76
    def __init__(self, repository, check_repo=True):
92
101
        if callback_refs is None:
93
102
            callback_refs = {}
94
103
        self.repository.lock_read()
95
 
        self.progress = bzrlib.ui.ui_factory.nested_progress_bar()
 
104
        self.progress = ui.ui_factory.nested_progress_bar()
96
105
        try:
97
106
            self.progress.update('check', 0, 4)
98
107
            if self.check_repo:
174
183
        # - we can fill out existence flags at this point
175
184
        # - we can read the revision inventory sha at this point
176
185
        # - we can check properties and serialisers etc.
177
 
        if not self.repository.revision_graph_can_have_wrong_parents():
 
186
        if not self.repository._format.revision_graph_can_have_wrong_parents:
178
187
            # The check against the index isn't needed.
179
188
            self.revs_with_bad_parents_in_index = None
180
189
            for thing in revision_iterator:
192
201
 
193
202
    def _report_repo_results(self, verbose):
194
203
        note('checked repository %s format %s',
195
 
             self.repository.bzrdir.root_transport,
196
 
             self.repository._format)
 
204
            self.repository.user_url,
 
205
            self.repository._format)
197
206
        note('%6d revisions', self.checked_rev_cnt)
198
207
        note('%6d file-ids', len(self.checked_weaves))
199
208
        if verbose:
291
300
        """Check all the weaves we can get our hands on.
292
301
        """
293
302
        weave_ids = []
294
 
        storebar = bzrlib.ui.ui_factory.nested_progress_bar()
 
303
        storebar = ui.ui_factory.nested_progress_bar()
295
304
        try:
296
305
            self._check_weaves(storebar)
297
306
        finally:
332
341
            self.text_key_references[key] = True
333
342
 
334
343
 
335
 
@deprecated_function(deprecated_in((1,6,0)))
336
 
def check(branch, verbose):
337
 
    """Run consistency checks on a branch.
338
 
 
339
 
    Results are reported through logging.
340
 
 
341
 
    Deprecated in 1.6.  Please use check_dwim instead.
342
 
 
343
 
    :raise BzrCheckError: if there's a consistency error.
344
 
    """
345
 
    check_branch(branch, verbose)
346
 
 
347
 
 
348
 
@deprecated_function(deprecated_in((1,16,0)))
349
 
def check_branch(branch, verbose):
350
 
    """Run consistency checks on a branch.
351
 
 
352
 
    Results are reported through logging.
353
 
 
354
 
    :raise BzrCheckError: if there's a consistency error.
355
 
    """
356
 
    branch.lock_read()
357
 
    try:
358
 
        needed_refs = {}
359
 
        for ref in branch._get_check_refs():
360
 
            needed_refs.setdefault(ref, []).append(branch)
361
 
        result = branch.repository.check([branch.last_revision()], needed_refs)
362
 
        branch_result = result.other_results[0]
363
 
    finally:
364
 
        branch.unlock()
365
 
    branch_result.report_results(verbose)
366
 
 
367
 
 
368
344
def scan_branch(branch, needed_refs, to_unlock):
369
345
    """Scan a branch for refs.
370
346
 
451
427
            if do_repo or do_branch or do_tree:
452
428
                if do_repo:
453
429
                    note("Checking repository at '%s'."
454
 
                         % (repo.bzrdir.root_transport.base,))
 
430
                         % (repo.user_url,))
455
431
                result = repo.check(None, callback_refs=needed_refs,
456
432
                    check_repo=do_repo)
457
433
                result.report_results(verbose)