Example #1
0
    def __call__(self, oldrevid, newrevid, new_parents):
        """Replay a commit by simply commiting the same snapshot with different
        parents.

        :param oldrevid: Revision id of the revision to copy.
        :param newrevid: Revision id of the revision to create.
        :param new_parents: Revision ids of the new parent revisions.
        """
        assert isinstance(new_parents, tuple), "CommitBuilderRevisionRewriter: Expected tuple for %r" % new_parents
        mutter('creating copy %r of %r with new parents %r' %
                                   (newrevid, oldrevid, new_parents))
        oldrev = self.repository.get_revision(oldrevid)

        revprops = dict(oldrev.properties)
        revprops[REVPROP_REBASE_OF] = oldrevid

        # Check what new_ie.file_id should be
        # use old and new parent trees to generate new_id map
        nonghost_oldparents = self._get_present_revisions(oldrev.parent_ids)
        nonghost_newparents = self._get_present_revisions(new_parents)
        oldtree = self.repository.revision_tree(oldrevid)
        if self.map_ids:
            fileid_map = map_file_ids(self.repository, nonghost_oldparents,
                nonghost_newparents)
            mappedtree = MapTree(oldtree, fileid_map)
        else:
            mappedtree = oldtree

        try:
            old_base = nonghost_oldparents[0]
        except IndexError:
            old_base = NULL_REVISION
        try:
            new_base = new_parents[0]
        except IndexError:
            new_base = NULL_REVISION
        old_base_tree = self.repository.revision_tree(old_base)
        old_iter_changes = oldtree.iter_changes(old_base_tree)
        iter_changes = wrap_iter_changes(old_iter_changes, mappedtree)
        builder = self.repository.get_commit_builder(branch=None,
            parents=new_parents, committer=oldrev.committer,
            timestamp=oldrev.timestamp, timezone=oldrev.timezone,
            revprops=revprops, revision_id=newrevid,
            config_stack=_mod_config.GlobalStack())
        try:
            for (file_id, relpath, fs_hash) in builder.record_iter_changes(
                    mappedtree, new_base, iter_changes):
                pass
            builder.finish_inventory()
            return builder.commit(oldrev.message)
        except:
            builder.abort()
            raise
Example #2
0
    def __call__(self, oldrevid, newrevid, new_parents):
        """Replay a commit by simply commiting the same snapshot with different
        parents.

        :param oldrevid: Revision id of the revision to copy.
        :param newrevid: Revision id of the revision to create.
        :param new_parents: Revision ids of the new parent revisions.
        """
        assert isinstance(new_parents, tuple), "CommitBuilderRevisionRewriter: Expected tuple for %r" % new_parents
        mutter('creating copy %r of %r with new parents %r' %
                                   (newrevid, oldrevid, new_parents))
        oldrev = self.repository.get_revision(oldrevid)

        revprops = dict(oldrev.properties)
        revprops[REVPROP_REBASE_OF] = oldrevid

        builder = self.repository.get_commit_builder(branch=None,
            parents=new_parents, config=Config(), committer=oldrev.committer,
            timestamp=oldrev.timestamp, timezone=oldrev.timezone,
            revprops=revprops, revision_id=newrevid)
        try:
            # Check what new_ie.file_id should be
            # use old and new parent inventories to generate new_id map
            nonghost_oldparents = self._get_present_revisions(oldrev.parent_ids)
            nonghost_newparents = self._get_present_revisions(new_parents)
            oldtree = self.repository.revision_tree(oldrevid)
            if self.map_ids:
                fileid_map = map_file_ids(self.repository, nonghost_oldparents,
                    nonghost_newparents)
                mappedtree = MapTree(oldtree, fileid_map)
            else:
                mappedtree = oldtree
            old_parent_invs = list(self.repository.iter_inventories(nonghost_oldparents))
            new_parent_invs = list(self.repository.iter_inventories(nonghost_newparents))
            pb = ui.ui_factory.nested_progress_bar()
            try:
                for i, (path, old_ie) in enumerate(mappedtree.inventory.iter_entries()):
                    pb.update('upgrading file', i, len(mappedtree.inventory))
                    ie = self._process_file(old_ie, oldtree, oldrevid, newrevid,
                        old_parent_invs, new_parent_invs, path)
                    builder.record_entry_contents(ie,
                            new_parent_invs, path, mappedtree,
                            mappedtree.path_content_summary(path))
            finally:
                pb.finished()
            builder.finish_inventory()
            return builder.commit(oldrev.message)
        except:
            builder.abort()
            raise
Example #3
0
 def test_empty(self):
     self.assertEquals({}, map_file_ids(None, [], []))