/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 read_changeset.py

  • Committer: John Arbash Meinel
  • Date: 2005-07-02 19:05:34 UTC
  • mto: (0.5.85) (1185.82.1 bzr-w-changeset)
  • mto: This revision was merged to the branch mainline in revision 1738.
  • Revision ID: john@arbash-meinel.com-20050702190534-5d151ec01dbcfbc0
Moving the validation into part of the reading.

Show diffs side-by-side

added added

removed removed

Lines of Context:
190
190
        rev_to_sha1 = {}
191
191
 
192
192
        for rev, rev_info in zip(self.info.real_revisions, self.info.revisions):
 
193
            assert rev.revision_id == rev_info.rev_id
193
194
            sio = StringIO()
194
195
            pack_xml(rev, sio)
195
196
            sio.seek(0)
211
212
                if parent.revision_id in rev_to_sha1:
212
213
                    if parent.revision_sha1 != rev_to_sha1[parent.revision_id]:
213
214
                        raise BzrError('Parent revision checksum mismatch.'
214
 
                                ' A parent was referenced with an incorrect checksum'
 
215
                                ' A parent was referenced with an'
 
216
                                ' incorrect checksum'
215
217
                                ': {%r} %s != %s' % (parent.revision_id,
216
 
                                                    parent.revision_sha1,
217
 
                                                    rev_to_sha1[parent.revision_id]))
218
 
 
219
 
 
220
 
 
221
 
 
 
218
                                            parent.revision_sha1,
 
219
                                            rev_to_sha1[parent.revision_id]))
 
220
 
 
221
    def _validate_references_from_branch(self, branch):
 
222
        """Now that we have a branch which should have some of the
 
223
        revisions we care about, go through and validate all of them
 
224
        that we can.
 
225
        """
 
226
        rev_to_sha = {}
 
227
        def add_sha(rev_id, sha1):
 
228
            if rev_id is None:
 
229
                if sha1 is not None:
 
230
                    raise BzrError('A Null revision should always'
 
231
                        'have a null sha1 hash')
 
232
                return
 
233
            if rev_id in rev_to_sha:
 
234
                # This really should have been validated as part
 
235
                # of _validate_revisions but lets do it again
 
236
                if sha1 != rev_to_sha[rev_id]:
 
237
                    raise BzrError('** Revision %r referenced with 2 different'
 
238
                            ' sha hashes %s != %s' % (rev_id,
 
239
                                sha1, rev_to_sha[rev_id]))
 
240
            else:
 
241
                rev_to_sha[rev_id] = sha1
 
242
 
 
243
        add_sha(self.info.base, self.info.base_sha1)
 
244
        # All of the contained revisions were checked
 
245
        # in _validate_revisions
 
246
        checked = {}
 
247
        for rev_info in self.info.revisions:
 
248
            checked[rev_info.rev_id] = True
 
249
            add_sha(rev_info.rev_id, rev_info.sha1)
 
250
                
 
251
        for rev in self.info.real_revisions:
 
252
            for parent in rev.parents:
 
253
                add_sha(parent.revision_id, parent.revision_sha1)
 
254
 
 
255
        missing = {}
 
256
        for rev_id, sha1 in rev_to_sha.iteritems():
 
257
            if rev_id in branch.revision_store:
 
258
                local_sha1 = branch.get_revision_sha1(rev_id)
 
259
                if sha1 != local_sha1:
 
260
                    raise BzrError('sha1 mismatch. For revision_id {%s}' 
 
261
                            'local: %s, cset: %s' % (rev_id, local_sha1, sha1))
 
262
            elif rev_id not in checked:
 
263
                missing[rev_id] = sha1
 
264
 
 
265
        if len(missing) > 0:
 
266
            # I don't know if this is an error yet
 
267
            from bzrlib.trace import warning
 
268
            warning('Not all revision hashes could be validated.'
 
269
                    ' Unable validate %d hashes' % len(missing))
 
270
 
 
271
    def _validate_inventory(self, branch, tree):
 
272
        """At this point we should have generated the ChangesetTree,
 
273
        so build up an inventory, and make sure the hashes match.
 
274
        """
 
275
        
222
276
    def get_info_and_tree(self, branch):
223
277
        """Return the meta information, and a Changeset tree which can
224
278
        be used to populate the local stores and working tree, respectively.
225
279
        """
226
 
        if self.info.base:
227
 
            store_base_sha1 = branch.get_revision_sha1(self.info.base) 
228
 
        else:
229
 
            store_base_sha1 = None
230
 
        if store_base_sha1 != self.info.base_sha1:
231
 
            raise BzrError('Base revision sha1 hash in store'
232
 
                    ' does not match the one read in the changeset'
233
 
                    ' (%s != %s)' % (store_base_sha1, self.info.base_sha1))
 
280
        self._validate_references_from_branch(branch)
234
281
        tree = ChangesetTree(branch.revision_tree(self.info.base))
235
282
        self._update_tree(tree)
236
283
 
 
284
        self._validate_inventory(branch, tree)
 
285
 
237
286
        return self.info, tree
238
287
 
239
288
    def _next(self):