コード例 #1
0
ファイル: gitreformat.py プロジェクト: ghtdak/gitreformat
    def time_warp(self, c_o):
        """
        History rewriting occurs here.  We read everything from the original
        commit, reformat the python, and checkin, mirroring the original
        commit history.
        :param c_o: Commit object representing "before"
        :return: None
        """

        log.info('warping: {} | {} | {:f} MB | {}s'.format(
                time_convert(c_o.authored_date, c_o.author_tz_offset),
                c_o.summary,
                resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1000,
                time.clock()))

        items = self.handle_commit(c_o)

        parent_commits = tuple(self.converted[v] for v in c_o.parents)

        # for the singular case of init / root / the genesis
        if len(parent_commits) == 0:
            parent_commits = {c_o}

        self.repo.head.reference = c_o
        self.repo.head.reset(index=True, working_tree=True)

        idx = IndexFile(self.repo)

        idx.add(items)

        idx.write_tree()

        com_msg = [c_o.message]

        com_msg.extend('\n'.join(self.convert_errors))
        self.convert_errors = []  # todo: rearchitect - too easy to forget

        com_msg.append(
                '\n[gitreformat yapf-ify (github/ghtdak) on {}]'.format(
                        time.strftime('%c')))
        com_msg.append('\n[from commit: {}]'.format(c_o.hexsha))

        c_n = idx.commit(
                ''.join(com_msg),
                parent_commits=parent_commits,
                author=c_o.author,
                author_date=time_convert(c_o.authored_date,
                                         c_o.author_tz_offset),
                committer=c_o.committer,
                commit_date=time_convert(c_o.committed_date,
                                         c_o.committer_tz_offset))

        self.repo.head.reference = c_n
        self.repo.head.reset(index=True, working_tree=True)

        self.verify_paths(c_o.tree, c_n.tree)

        self.converted[c_o] = c_n

        return c_n
コード例 #2
0
ファイル: gitreformat.py プロジェクト: battyone/gitreformat
    def time_warp(self, c_o):
        """
        History rewriting occurs here.  We read everything from the original
        commit, reformat the python, and checkin, mirroring the original
        commit history.
        :param c_o: Commit object representing "before"
        :return: None
        """

        log.info('warping: {} | {} | {:f} MB | {}s'.format(
            time_convert(c_o.authored_date, c_o.author_tz_offset), c_o.summary,
            resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1000,
            time.clock()))

        items = self.handle_commit(c_o)

        parent_commits = tuple(self.converted[v] for v in c_o.parents)

        # for the singular case of init / root / the genesis
        if len(parent_commits) == 0:
            parent_commits = {c_o}

        self.repo.head.reference = c_o
        self.repo.head.reset(index=True, working_tree=True)

        idx = IndexFile(self.repo)

        idx.add(items)

        idx.write_tree()

        com_msg = [c_o.message]

        com_msg.extend('\n'.join(self.convert_errors))
        self.convert_errors = []  # todo: rearchitect - too easy to forget

        com_msg.append('\n[gitreformat yapf-ify (github/ghtdak) on {}]'.format(
            time.strftime('%c')))
        com_msg.append('\n[from commit: {}]'.format(c_o.hexsha))

        c_n = idx.commit(''.join(com_msg),
                         parent_commits=parent_commits,
                         author=c_o.author,
                         author_date=time_convert(c_o.authored_date,
                                                  c_o.author_tz_offset),
                         committer=c_o.committer,
                         commit_date=time_convert(c_o.committed_date,
                                                  c_o.committer_tz_offset))

        self.repo.head.reference = c_n
        self.repo.head.reset(index=True, working_tree=True)

        self.verify_paths(c_o.tree, c_n.tree)

        self.converted[c_o] = c_n

        return c_n
コード例 #3
0
def git_commit(index: IndexFile, message: str) -> Commit:
    """
    Commit all staged files in the current repo.

    :param IndexFile index:
        the current index of the current branch of the current repo
    :param message:
        the commit message to include with the files to be committed
    :return:
        a record of the commit (:py:class:`~git.objects.commit.Commit`), itself
    """
    return index.commit(message, author=get_author())