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
parent.revision_sha1,
219
rev_to_sha1[parent.revision_id]))
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
227
def add_sha(rev_id, sha1):
230
raise BzrError('A Null revision should always'
231
'have a null sha1 hash')
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]))
241
rev_to_sha[rev_id] = sha1
243
add_sha(self.info.base, self.info.base_sha1)
244
# All of the contained revisions were checked
245
# in _validate_revisions
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)
251
for rev in self.info.real_revisions:
252
for parent in rev.parents:
253
add_sha(parent.revision_id, parent.revision_sha1)
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
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))
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.
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.
227
store_base_sha1 = branch.get_revision_sha1(self.info.base)
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)
284
self._validate_inventory(branch, tree)
237
286
return self.info, tree