1
# Copyright (C) 2004, 2005 by Martin Pool
 
 
2
# Copyright (C) 2005 by Canonical Ltd
 
 
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.
 
 
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.
 
 
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
 
 
20
######################################################################
 
 
27
from trace import mutter
 
 
28
from errors import bailout
 
 
31
def check(branch, progress=True):
 
 
36
            mutter('checking ' + m)
 
 
37
            out.write('\rchecking: %-50.50s' % m)
 
 
41
            mutter('checking ' + m)
 
 
43
    p('history of %r' % branch.base)
 
 
47
    history = branch.revision_history()
 
 
49
    revcount = len(history)
 
 
55
        p('revision %d/%d' % (revno, revcount))
 
 
56
        mutter('    revision {%s}' % rid)
 
 
57
        rev = branch.get_revision(rid)
 
 
58
        if rev.revision_id != rid:
 
 
59
            bailout('wrong internal revision id in revision {%s}' % rid)
 
 
60
        if rev.precursor != last_ptr:
 
 
61
            bailout('mismatched precursor in revision {%s}' % rid)
 
 
63
        if rid in checked_revs:
 
 
64
            bailout('repeated revision {%s}' % rid)
 
 
67
        ## TODO: Check all the required fields are present on the revision.
 
 
69
        inv = branch.get_inventory(rev.inventory_id)
 
 
73
        p('revision %d/%d file ids' % (revno, revcount))
 
 
75
            if file_id in seen_ids:
 
 
76
                bailout('duplicated file_id {%s} in inventory for revision {%s}'
 
 
85
                p('revision %d/%d file text %d/%d' % (revno, revcount, i, len_inv))
 
 
89
            if ie.parent_id != None:
 
 
90
                if ie.parent_id not in seen_ids:
 
 
91
                    bailout('missing parent {%s} in inventory for revision {%s}'
 
 
92
                            % (ie.parent_id, revid))
 
 
95
                if ie.text_id in checked_texts:
 
 
96
                    fp = checked_texts[ie.text_id]
 
 
98
                    if not ie.text_id in branch.text_store:
 
 
99
                        bailout('text {%s} not in text_store' % ie.text_id)
 
 
101
                    tf = branch.text_store[ie.text_id]
 
 
102
                    fp = osutils.fingerprint_file(tf)
 
 
103
                    checked_texts[ie.text_id] = fp
 
 
105
                if ie.text_size != fp['size']:
 
 
106
                    bailout('text {%s} wrong size' % ie.text_id)
 
 
107
                if ie.text_sha1 != fp['sha1']:
 
 
108
                    bailout('text {%s} wrong sha1' % ie.text_id)
 
 
109
            elif ie.kind == 'directory':
 
 
110
                if ie.text_sha1 != None or ie.text_size != None or ie.text_id != None:
 
 
111
                    bailout('directory {%s} has text in revision {%s}'
 
 
114
        p('revision %d/%d file paths' % (revno, revcount))
 
 
115
        for path, ie in inv.iter_entries():
 
 
116
            if path in seen_names:
 
 
117
                bailout('duplicated path %r in inventory for revision {%s}' % (path, revid))