/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
119 by mbp at sourcefrog
check revisions are not duplicated in history
24
from sets import Set
25
114 by mbp at sourcefrog
- reactivate basic check command
26
import bzrlib
116 by mbp at sourcefrog
fix up debug output for check command
27
from trace import mutter
117 by mbp at sourcefrog
better messages from check command
28
from errors import bailout
114 by mbp at sourcefrog
- reactivate basic check command
29
30
116 by mbp at sourcefrog
fix up debug output for check command
31
def check(branch):
32
    mutter('checking tree %r' % branch.base)
114 by mbp at sourcefrog
- reactivate basic check command
33
117 by mbp at sourcefrog
better messages from check command
34
    mutter('checking revision history')
114 by mbp at sourcefrog
- reactivate basic check command
35
    last_ptr = None
119 by mbp at sourcefrog
check revisions are not duplicated in history
36
    checked_revs = Set()
114 by mbp at sourcefrog
- reactivate basic check command
37
    for rid in branch.revision_history():
116 by mbp at sourcefrog
fix up debug output for check command
38
        mutter('    revision {%s}' % rid)
114 by mbp at sourcefrog
- reactivate basic check command
39
        rev = branch.get_revision(rid)
117 by mbp at sourcefrog
better messages from check command
40
        if rev.revision_id != rid:
41
            bailout('wrong internal revision id in revision {%s}' % rid)
42
        if rev.precursor != last_ptr:
43
            bailout('mismatched precursor in revision {%s}' % rid)
114 by mbp at sourcefrog
- reactivate basic check command
44
        last_ptr = rid
119 by mbp at sourcefrog
check revisions are not duplicated in history
45
        if rid in checked_revs:
46
            bailout('repeated revision {%s}' % rid)
47
        checked_revs.add(rid)
114 by mbp at sourcefrog
- reactivate basic check command
48
49
    #check_inventory()
116 by mbp at sourcefrog
fix up debug output for check command
50
51
    mutter('branch %s is OK' % branch.base)
52
1 by mbp at sourcefrog
import from baz patch-364
53
    ## TODO: Check that previous-inventory and previous-manifest
54
    ## are the same as those stored in the previous changeset.
55
56
    ## TODO: Check all patches present in patch directory are
57
    ## mentioned in patch history; having an orphaned patch only gives
58
    ## a warning.
59
60
    ## TODO: Check cached data is consistent with data reconstructed
61
    ## from scratch.
62
63
    ## TODO: Check no control files are versioned.
64
65
    ## TODO: Check that the before-hash of each file in a later
66
    ## revision matches the after-hash in the previous revision to
67
    ## touch it.
68
69
70
def check_inventory():
71
    mutter("checking inventory file and ids...")
72
    seen_ids = Set()
73
    seen_names = Set()
74
    
75
    for l in controlfile('inventory').readlines():
76
        parts = l.split()
77
        if len(parts) != 2:
78
            bailout("malformed inventory line: " + `l`)
79
        file_id, name = parts
80
        
81
        if file_id in seen_ids:
82
            bailout("duplicated file id " + file_id)
83
        seen_ids.add(file_id)
84
85
        if name in seen_names:
86
            bailout("duplicated file name in inventory: " + quotefn(name))
87
        seen_names.add(name)
88
        
89
        if is_control_file(name):
90
            raise BzrError("control file %s present in inventory" % quotefn(name))