~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/changeset/read_changeset.py

  • Committer: Aaron Bentley
  • Date: 2006-05-12 03:33:24 UTC
  • mto: (1185.82.108 w-changeset)
  • mto: This revision was merged to the branch mainline in revision 1738.
  • Revision ID: aaron.bentley@utoronto.ca-20060512033324-5947a3f509a1cb9d
Disabled validate_revisions (needs info it doesn't have), updated API to repos

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
                              InventoryDirectory, InventoryFile,
18
18
                              InventoryLink)
19
19
 
20
 
from bzrlib.changeset.common import decode, get_header, header_str
 
20
from bzrlib.changeset.common import (decode, get_header, header_str,
 
21
                                     testament_sha1)
21
22
 
22
23
class BadChangeset(Exception): pass
23
24
class MalformedHeader(BadChangeset): pass
199
200
        for rev, rev_info in zip(self.info.real_revisions, self.info.revisions):
200
201
            assert rev.revision_id == rev_info.revision_id
201
202
            sio = StringIO()
202
 
            serializer_v5.write_revision(rev, sio)
203
 
            sio.seek(0)
204
 
            sha1 = sha_file(sio)
205
 
            if sha1 != rev_info.sha1:
206
 
                raise BzrError('Revision checksum mismatch.'
207
 
                    ' For revision_id {%s} supplied sha1 (%s) != measured (%s)'
208
 
                    % (rev.revision_id, rev_info.sha1, sha1))
 
203
            # serializer_v5.write_revision(rev, sio)
 
204
            # sio.seek(0)
 
205
            # sha1 = sha_file(sio)
 
206
            # if sha1 != rev_info.sha1:
 
207
            #     raise BzrError('Revision checksum mismatch.'
 
208
            #         ' For revision_id {%s} supplied sha1 (%s) != measured (%s)'
 
209
            #         % (rev.revision_id, rev_info.sha1, sha1))
 
210
            sha1 = rev_info.sha1
209
211
            if rev_to_sha1.has_key(rev.revision_id):
210
212
                raise BzrError('Revision {%s} given twice in the list'
211
213
                        % (rev.revision_id))
226
228
        ##                                     parent.revision_sha1,
227
229
        ##                                     rev_to_sha1[parent.revision_id]))
228
230
 
229
 
    def _validate_references_from_branch(self, branch):
230
 
        """Now that we have a branch which should have some of the
 
231
    def _validate_references_from_repository(self, repository):
 
232
        """Now that we have a repository which should have some of the
231
233
        revisions we care about, go through and validate all of them
232
234
        that we can.
233
235
        """
265
267
        count = 0
266
268
        missing = {}
267
269
        for revision_id, sha1 in rev_to_sha.iteritems():
268
 
            if branch.has_revision(revision_id):
269
 
                local_sha1 = branch.get_revision_sha1(revision_id)
 
270
            if repository.has_revision(revision_id):
 
271
                local_sha1 = testament_sha1(repository, revision_id)
270
272
                if sha1 != local_sha1:
271
273
                    raise BzrError('sha1 mismatch. For revision id {%s}' 
272
274
                            'local: %s, cset: %s' % (revision_id, local_sha1, sha1))
276
278
                missing[revision_id] = sha1
277
279
 
278
280
        for inv_id, sha1 in inv_to_sha.iteritems():
279
 
            if branch.has_revision(inv_id):
 
281
            if repository.has_revision(inv_id):
280
282
                # TODO: Currently branch.get_inventory_sha1() just returns the value
281
283
                # that is stored in the revision text. Which is *really* bogus, because
282
284
                # that means we aren't validating the actual text, just that we wrote 
283
285
                # and read the string. But for now, what the hell.
284
 
                local_sha1 = branch.get_inventory_sha1(inv_id)
 
286
                local_sha1 = repository.get_inventory_sha1(inv_id)
285
287
                if sha1 != local_sha1:
286
288
                    raise BzrError('sha1 mismatch. For inventory id {%s}' 
287
289
                            'local: %s, cset: %s' % (inv_id, local_sha1, sha1))
311
313
            raise BzrError('Inventory sha hash mismatch.')
312
314
 
313
315
        
314
 
    def get_changeset(self, branch):
 
316
    def get_changeset(self, repository):
315
317
        """Return the meta information, and a Changeset tree which can
316
318
        be used to populate the local stores and working tree, respectively.
317
319
        """
318
 
        self._validate_references_from_branch(branch)
319
 
        cset_tree = ChangesetTree(branch.revision_tree(self.info.base))
 
320
        self._validate_references_from_repository(repository)
 
321
        cset_tree = ChangesetTree(repository.revision_tree(self.info.base))
320
322
        self._update_tree(cset_tree)
321
323
 
322
324
        inv = cset_tree.inventory
626
628
                        ' (unrecognized action): %r' % action_line)
627
629
            valid_actions[action](kind, extra, lines)
628
630
 
629
 
def read_changeset(from_file, branch):
 
631
def read_changeset(from_file, repository):
630
632
    """Read in a changeset from a iterable object (such as a file object)
631
633
 
632
634
    :param from_file: A file-like object to read the changeset information.
633
 
    :param branch: This will be used to build the changeset tree, it needs
634
 
                   to contain the base of the changeset. (Which you probably
635
 
                   won't know about until after the changeset is parsed.)
 
635
    :param repository: This will be used to build the changeset tree, it needs
 
636
                       to contain the base of the changeset. (Which you
 
637
                       probably won't know about until after the changeset is
 
638
                       parsed.)
636
639
    """
637
640
    cr = ChangesetReader(from_file)
638
 
    return cr.get_changeset(branch)
 
641
    return cr.get_changeset(repository)
639
642
 
640
643
class ChangesetTree(Tree):
641
644
    def __init__(self, base_tree):