/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 13:20:38 UTC
  • Revision ID: mbp@sourcefrog.net-20050328132038-3a8a5fb9f1023ee1
more check functions

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
from sets import Set
 
25
 
 
26
import bzrlib
 
27
from trace import mutter
 
28
from errors import bailout
 
29
 
 
30
 
 
31
def check(branch):
 
32
    mutter('checking tree %r' % branch.base)
 
33
 
 
34
    mutter('checking revision history')
 
35
    last_ptr = None
 
36
    checked_revs = Set()
 
37
    for rid in branch.revision_history():
 
38
        mutter('    revision {%s}' % rid)
 
39
        rev = branch.get_revision(rid)
 
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)
 
44
        last_ptr = rid
 
45
        if rid in checked_revs:
 
46
            bailout('repeated revision {%s}' % rid)
 
47
        checked_revs.add(rid)
 
48
 
 
49
        ## TODO: Check all the required fields are present on the revision.
 
50
 
 
51
        inv = branch.get_inventory(rev.inventory_id)
 
52
        check_inventory(branch, inv)
 
53
 
 
54
    mutter('branch %s is OK' % branch.base)
 
55
 
 
56
 
 
57
 
 
58
def check_inventory(branch, inv):
 
59
    seen_ids = Set()
 
60
    seen_names = Set()
 
61
 
 
62
    for path, ie in inv.iter_entries():
 
63
        if path in seen_names:
 
64
            bailout('duplicated path %r in inventory' % path)
 
65
        seen_names.add(path)
 
66
        if ie.kind == 'file':
 
67
            if not ie.text_id in branch.text_store:
 
68
                bailout('text {%s} not in text_store' % ie.text_id)
 
69