/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1 by mbp at sourcefrog
import from baz patch-364
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
114 by mbp at sourcefrog
- reactivate basic check command
23
24
import bzrlib
25
26
27
def _ass(a, b):
28
    if a != b:
29
        bzrlib.errors.bailout("check failed: %r != %r" % (a, b))
30
31
def check(branch, verbose=True):
32
    print 'checking tree %r' % branch.base
33
34
    print 'checking entire revision history is present'
35
    last_ptr = None
36
    for rid in branch.revision_history():
37
        print '    revision {%s}' % rid
38
        rev = branch.get_revision(rid)
39
        _ass(rev.revision_id, rid)
40
        _ass(rev.precursor, last_ptr)
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
    print ("tree looks OK")
1 by mbp at sourcefrog
import from baz patch-364
49
    ## TODO: Check that previous-inventory and previous-manifest
50
    ## are the same as those stored in the previous changeset.
51
52
    ## TODO: Check all patches present in patch directory are
53
    ## mentioned in patch history; having an orphaned patch only gives
54
    ## a warning.
55
56
    ## TODO: Check cached data is consistent with data reconstructed
57
    ## from scratch.
58
59
    ## TODO: Check no control files are versioned.
60
61
    ## TODO: Check that the before-hash of each file in a later
62
    ## revision matches the after-hash in the previous revision to
63
    ## touch it.
64
65
66
def check_inventory():
67
    mutter("checking inventory file and ids...")
68
    seen_ids = Set()
69
    seen_names = Set()
70
    
71
    for l in controlfile('inventory').readlines():
72
        parts = l.split()
73
        if len(parts) != 2:
74
            bailout("malformed inventory line: " + `l`)
75
        file_id, name = parts
76
        
77
        if file_id in seen_ids:
78
            bailout("duplicated file id " + file_id)
79
        seen_ids.add(file_id)
80
81
        if name in seen_names:
82
            bailout("duplicated file name in inventory: " + quotefn(name))
83
        seen_names.add(name)
84
        
85
        if is_control_file(name):
86
            raise BzrError("control file %s present in inventory" % quotefn(name))
87
88
89
def check_patches_exist():
90
    """Check constraint of current version: all patches exist"""
91
    mutter("checking all patches are present...")
92
    for pid in revision_history():
93
        read_patch_header(pid)
94
95
96
def check_patch_chaining():
97
    """Check ancestry of patches and history file is consistent"""
98
    mutter("checking patch chaining...")
99
    prev = None
100
    for pid in revision_history():
101
        log_prev = read_patch_header(pid).precursor
102
        if log_prev != prev:
103
            bailout("inconsistent precursor links on " + pid)
104
        prev = pid
105
106
107
def check_patch_uniqueness():
108
    """Make sure no patch is listed twice in the history.
109
110
    This should be implied by having correct ancestry but I'll check it
111
    anyhow."""
112
    mutter("checking history for duplicates...")
113
    seen = Set()
114
    for pid in revision_history():
115
        if pid in seen:
116
            bailout("patch " + pid + " appears twice in history")
117
        seen.add(pid)
118
        
119