~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/check.py

  • Committer: Martin Pool
  • Date: 2005-09-13 01:37:23 UTC
  • Revision ID: mbp@sourcefrog.net-20050913013723-7e0026b48cbf08ff
- BROKEN: start refactoring fetch code to work well with weaves

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
import bzrlib.ui
19
19
from bzrlib.trace import note, warning
20
 
from bzrlib.osutils import rename, sha_string
21
20
 
22
21
def _update_store_entry(obj, obj_id, branch, store_name, store):
23
22
    """This is just a meta-function, which handles both revision entries
25
24
    """
26
25
    from bzrlib.trace import mutter
27
26
    import tempfile, os, errno
 
27
    from osutils import rename
28
28
    obj_tmp = tempfile.TemporaryFile()
29
29
    obj.write_xml(obj_tmp)
30
30
    obj_tmp.seek(0)
72
72
    :param inv_id:  The inventory id for this inventory
73
73
    :param branch:  The Branch where this entry will be stored.
74
74
    """
75
 
    raise NotImplementedError("can't update existing inventory entry")
 
75
    _update_store_entry(inv, inv_id, branch,
 
76
            'inventory-store', branch.inventory_store)
76
77
 
77
78
 
78
79
def check(branch):
100
101
        history = branch.revision_history()
101
102
        revno = 0
102
103
        revcount = len(history)
 
104
        mismatch_inv_id = []
103
105
 
104
 
        checked_text_count = 0
 
106
        # for all texts checked, text_id -> sha1
 
107
        checked_texts = {}
105
108
 
106
109
        progress = bzrlib.ui.ui_factory.progress_bar()
107
110
 
152
155
                                    "by {%s}"
153
156
                                    % (rev_id, last_rev_id))
154
157
 
 
158
            if rev.inventory_id != rev_id:
 
159
                mismatch_inv_id.append(rev_id)
 
160
 
155
161
            ## TODO: Check all the required fields are present on the revision.
156
162
 
157
163
            if rev.inventory_sha1:
158
 
                inv_sha1 = branch.get_inventory_sha1(rev_id)
 
164
                inv_sha1 = branch.get_inventory_sha1(rev.inventory_id)
159
165
                if inv_sha1 != rev.inventory_sha1:
160
166
                    raise BzrCheckError('Inventory sha1 hash doesn\'t match'
161
167
                        ' value in revision {%s}' % rev_id)
163
169
                missing_inventory_sha_cnt += 1
164
170
                mutter("no inventory_sha1 on revision {%s}" % rev_id)
165
171
 
166
 
            tree = branch.revision_tree(rev_id)
167
 
            inv = tree.inventory
 
172
            inv = branch.get_inventory(rev.inventory_id)
168
173
            seen_ids = {}
169
174
            seen_names = {}
170
175
 
190
195
                                % (ie.parent_id, rev_id))
191
196
 
192
197
                if ie.kind == 'file':
193
 
                    text = tree.get_file_text(file_id)
194
 
                    checked_text_count += 1 
195
 
                    if ie.text_size != len(text):
 
198
                    if ie.text_id in checked_texts:
 
199
                        fp = checked_texts[ie.text_id]
 
200
                    else:
 
201
                        if not ie.text_id in branch.text_store:
 
202
                            raise BzrCheckError('text {%s} not in text_store' % ie.text_id)
 
203
 
 
204
                        tf = branch.text_store[ie.text_id]
 
205
                        fp = fingerprint_file(tf)
 
206
                        checked_texts[ie.text_id] = fp
 
207
 
 
208
                    if ie.text_size != fp['size']:
196
209
                        raise BzrCheckError('text {%s} wrong size' % ie.text_id)
197
 
                    if ie.text_sha1 != sha_string(text):
 
210
                    if ie.text_sha1 != fp['sha1']:
198
211
                        raise BzrCheckError('text {%s} wrong sha1' % ie.text_id)
199
212
                elif ie.kind == 'directory':
200
213
                    if ie.text_sha1 != None or ie.text_size != None or ie.text_id != None:
207
220
                    raise BzrCheckError('duplicated path %s '
208
221
                                        'in inventory for revision {%s}'
209
222
                                        % (path, rev_id))
210
 
                seen_names[path] = True
 
223
            seen_names[path] = True
211
224
            last_rev_id = rev_id
212
225
 
213
226
    finally:
215
228
 
216
229
    progress.clear()
217
230
 
218
 
    note('checked %d revisions, %d file texts' % (revcount, checked_text_count))
 
231
    note('checked %d revisions, %d file texts' % (revcount, len(checked_texts)))
219
232
    
220
233
    if missing_inventory_sha_cnt:
221
234
        note('%d revisions are missing inventory_sha1' % missing_inventory_sha_cnt)
222
235
 
223
 
    ##if missing_revision_sha_cnt:
224
 
    ##    note('%d parent links are missing revision_sha1' % missing_revision_sha_cnt)
 
236
    if missing_revision_sha_cnt:
 
237
        note('%d parent links are missing revision_sha1' % missing_revision_sha_cnt)
225
238
 
226
239
    if missing_revision_cnt:
227
240
        note('%d revisions are mentioned but not present' % missing_revision_cnt)
234
247
#    if (missing_inventory_sha_cnt
235
248
#        or missing_revision_sha_cnt):
236
249
#        print '  (use "bzr upgrade" to fix them)'
 
250
 
 
251
    if mismatch_inv_id:
 
252
        warning('%d revisions have mismatched inventory ids:' % len(mismatch_inv_id))
 
253
        for rev_id in mismatch_inv_id:
 
254
            warning('  %s', rev_id)