/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/check.py

  • Committer: mbp at sourcefrog
  • Date: 2005-03-28 10:04:39 UTC
  • Revision ID: mbp@sourcefrog.net-20050328100439-80f2cf8bb0e5a621
better messages from check command

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2004, 2005 by Martin Pool
 
2
# Copyright (C) 2005 by Canonical Ltd
 
3
 
 
4
# This program is free software; you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation; either version 2 of the License, or
 
7
# (at your option) any later version.
 
8
 
 
9
# This program is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU General Public License for more details.
 
13
 
 
14
# You should have received a copy of the GNU General Public License
 
15
# along with this program; if not, write to the Free Software
 
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
17
 
 
18
 
 
19
 
 
20
######################################################################
 
21
# consistency checks
 
22
 
 
23
 
 
24
import bzrlib
 
25
from trace import mutter
 
26
from errors import bailout
 
27
 
 
28
 
 
29
def check(branch):
 
30
    mutter('checking tree %r' % branch.base)
 
31
 
 
32
    mutter('checking revision history')
 
33
    last_ptr = None
 
34
    for rid in branch.revision_history():
 
35
        mutter('    revision {%s}' % rid)
 
36
        rev = branch.get_revision(rid)
 
37
        if rev.revision_id != rid:
 
38
            bailout('wrong internal revision id in revision {%s}' % rid)
 
39
        if rev.precursor != last_ptr:
 
40
            bailout('mismatched precursor in revision {%s}' % rid)
 
41
        last_ptr = rid
 
42
 
 
43
    #mutter("checking tree")
 
44
    #check_patches_exist()
 
45
    #check_patch_chaining()
 
46
    #check_patch_uniqueness()
 
47
    #check_inventory()
 
48
 
 
49
    mutter('branch %s is OK' % branch.base)
 
50
 
 
51
    ## TODO: Check that previous-inventory and previous-manifest
 
52
    ## are the same as those stored in the previous changeset.
 
53
 
 
54
    ## TODO: Check all patches present in patch directory are
 
55
    ## mentioned in patch history; having an orphaned patch only gives
 
56
    ## a warning.
 
57
 
 
58
    ## TODO: Check cached data is consistent with data reconstructed
 
59
    ## from scratch.
 
60
 
 
61
    ## TODO: Check no control files are versioned.
 
62
 
 
63
    ## TODO: Check that the before-hash of each file in a later
 
64
    ## revision matches the after-hash in the previous revision to
 
65
    ## touch it.
 
66
 
 
67
 
 
68
def check_inventory():
 
69
    mutter("checking inventory file and ids...")
 
70
    seen_ids = Set()
 
71
    seen_names = Set()
 
72
    
 
73
    for l in controlfile('inventory').readlines():
 
74
        parts = l.split()
 
75
        if len(parts) != 2:
 
76
            bailout("malformed inventory line: " + `l`)
 
77
        file_id, name = parts
 
78
        
 
79
        if file_id in seen_ids:
 
80
            bailout("duplicated file id " + file_id)
 
81
        seen_ids.add(file_id)
 
82
 
 
83
        if name in seen_names:
 
84
            bailout("duplicated file name in inventory: " + quotefn(name))
 
85
        seen_names.add(name)
 
86
        
 
87
        if is_control_file(name):
 
88
            raise BzrError("control file %s present in inventory" % quotefn(name))
 
89
 
 
90
 
 
91
def check_patches_exist():
 
92
    """Check constraint of current version: all patches exist"""
 
93
    mutter("checking all patches are present...")
 
94
    for pid in revision_history():
 
95
        read_patch_header(pid)
 
96
 
 
97
 
 
98
def check_patch_chaining():
 
99
    """Check ancestry of patches and history file is consistent"""
 
100
    mutter("checking patch chaining...")
 
101
    prev = None
 
102
    for pid in revision_history():
 
103
        log_prev = read_patch_header(pid).precursor
 
104
        if log_prev != prev:
 
105
            bailout("inconsistent precursor links on " + pid)
 
106
        prev = pid
 
107
 
 
108
 
 
109
def check_patch_uniqueness():
 
110
    """Make sure no patch is listed twice in the history.
 
111
 
 
112
    This should be implied by having correct ancestry but I'll check it
 
113
    anyhow."""
 
114
    mutter("checking history for duplicates...")
 
115
    seen = Set()
 
116
    for pid in revision_history():
 
117
        if pid in seen:
 
118
            bailout("patch " + pid + " appears twice in history")
 
119
        seen.add(pid)
 
120
        
 
121