~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/check.py

  • Committer: Benoît Pierre
  • Date: 2009-11-02 22:24:29 UTC
  • mto: (4634.96.1 integration-2.0)
  • mto: This revision was merged to the branch mainline in revision 4798.
  • Revision ID: benoit.pierre@gmail.com-20091102222429-xqdyo6n8odh3xbbd
Small fix for handling of short option names in shellcomplete_on_options.

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
 
 
43
42
* 'trees', where value is a revid and the looked up objects are revision trees.
44
43
* 'lefthand-distance', where value is a revid and the looked up objects are the
45
44
  distance along the lefthand path to NULL for that revid.
47
46
  indicating that the revision was found/not found.
48
47
"""
49
48
 
50
 
from bzrlib import (
51
 
    errors,
52
 
    ui,
53
 
    )
 
49
from bzrlib import errors, osutils
 
50
from bzrlib import repository as _mod_repository
 
51
from bzrlib import revision
54
52
from bzrlib.branch import Branch
55
53
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.trace import note
 
57
from bzrlib.symbol_versioning import deprecated_function, deprecated_in
 
58
from bzrlib.trace import log_error, note
 
59
import bzrlib.ui
58
60
from bzrlib.workingtree import WorkingTree
59
61
 
60
 
 
61
62
class Check(object):
62
63
    """Check a repository"""
63
64
 
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
 
 
74
65
    # The Check object interacts with InventoryEntry.check, etc.
75
66
 
76
67
    def __init__(self, repository, check_repo=True):
101
92
        if callback_refs is None:
102
93
            callback_refs = {}
103
94
        self.repository.lock_read()
104
 
        self.progress = ui.ui_factory.nested_progress_bar()
 
95
        self.progress = bzrlib.ui.ui_factory.nested_progress_bar()
105
96
        try:
106
97
            self.progress.update('check', 0, 4)
107
98
            if self.check_repo:
183
174
        # - we can fill out existence flags at this point
184
175
        # - we can read the revision inventory sha at this point
185
176
        # - we can check properties and serialisers etc.
186
 
        if not self.repository._format.revision_graph_can_have_wrong_parents:
 
177
        if not self.repository.revision_graph_can_have_wrong_parents():
187
178
            # The check against the index isn't needed.
188
179
            self.revs_with_bad_parents_in_index = None
189
180
            for thing in revision_iterator:
201
192
 
202
193
    def _report_repo_results(self, verbose):
203
194
        note('checked repository %s format %s',
204
 
            self.repository.user_url,
205
 
            self.repository._format)
 
195
             self.repository.bzrdir.root_transport,
 
196
             self.repository._format)
206
197
        note('%6d revisions', self.checked_rev_cnt)
207
198
        note('%6d file-ids', len(self.checked_weaves))
208
199
        if verbose:
210
201
                len(self.unreferenced_versions))
211
202
        if verbose and len(self.unreferenced_versions):
212
203
                for file_id, revision_id in self.unreferenced_versions:
213
 
                    note('unreferenced version: {%s} in %s', revision_id,
 
204
                    log_error('unreferenced version: {%s} in %s', revision_id,
214
205
                        file_id)
215
206
        if self.missing_inventory_sha_cnt:
216
207
            note('%6d revisions are missing inventory_sha1',
300
291
        """Check all the weaves we can get our hands on.
301
292
        """
302
293
        weave_ids = []
303
 
        storebar = ui.ui_factory.nested_progress_bar()
 
294
        storebar = bzrlib.ui.ui_factory.nested_progress_bar()
304
295
        try:
305
296
            self._check_weaves(storebar)
306
297
        finally:
341
332
            self.text_key_references[key] = True
342
333
 
343
334
 
 
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
 
344
368
def scan_branch(branch, needed_refs, to_unlock):
345
369
    """Scan a branch for refs.
346
370
 
421
445
                    if do_branch:
422
446
                        scan_branch(branch, needed_refs, to_unlock)
423
447
            if do_branch and not branches:
424
 
                note("No branch found at specified location.")
 
448
                log_error("No branch found at specified location.")
425
449
            if do_tree and base_tree is None and not saw_tree:
426
 
                note("No working tree found at specified location.")
 
450
                log_error("No working tree found at specified location.")
427
451
            if do_repo or do_branch or do_tree:
428
452
                if do_repo:
429
453
                    note("Checking repository at '%s'."
430
 
                         % (repo.user_url,))
 
454
                         % (repo.bzrdir.root_transport.base,))
431
455
                result = repo.check(None, callback_refs=needed_refs,
432
456
                    check_repo=do_repo)
433
457
                result.report_results(verbose)
434
458
        else:
435
459
            if do_tree:
436
 
                note("No working tree found at specified location.")
 
460
                log_error("No working tree found at specified location.")
437
461
            if do_branch:
438
 
                note("No branch found at specified location.")
 
462
                log_error("No branch found at specified location.")
439
463
            if do_repo:
440
 
                note("No repository found at specified location.")
 
464
                log_error("No repository found at specified location.")
441
465
    finally:
442
466
        for thing in to_unlock:
443
467
            thing.unlock()