Class CommitUtil


  • public class CommitUtil
    extends Object
    Static utilities for working with RevCommits.
    • Method Detail

      • toCommitInfo

        public static CommitInfo toCommitInfo​(org.eclipse.jgit.revwalk.RevCommit commit,
                                              org.eclipse.jgit.revwalk.RevWalk walk)
                                       throws IOException
        Throws:
        IOException
      • createRevertCommit

        public org.eclipse.jgit.lib.ObjectId createRevertCommit​(String message,
                                                                ChangeNotes notes,
                                                                CurrentUser user,
                                                                Instant ts)
                                                         throws RestApiException,
                                                                IOException
        Wrapper function for creating a revert Commit.
        Parameters:
        message - Commit message for the revert commit.
        notes - ChangeNotes of the change being reverted.
        user - Current User performing the revert.
        ts - Timestamp of creation for the commit.
        Returns:
        ObjectId that represents the newly created commit.
        Throws:
        RestApiException
        IOException
      • createCommitWithTree

        public static org.eclipse.jgit.lib.ObjectId createCommitWithTree​(org.eclipse.jgit.lib.ObjectInserter oi,
                                                                         org.eclipse.jgit.lib.PersonIdent authorIdent,
                                                                         org.eclipse.jgit.lib.PersonIdent committerIdent,
                                                                         org.eclipse.jgit.revwalk.RevCommit parentCommit,
                                                                         String commitMessage,
                                                                         org.eclipse.jgit.lib.ObjectId treeId)
                                                                  throws IOException
        Creates a commit with the specified tree ID.
        Parameters:
        oi - ObjectInserter for inserting the newly created commit.
        authorIdent - of the new commit
        committerIdent - of the new commit
        parentCommit - of the new commit. Can be null.
        commitMessage - for the new commit.
        treeId - of the content for the new commit.
        Returns:
        the newly created commit.
        Throws:
        IOException - if fails to insert the commit.
      • addChangeRevertedNotificationOps

        public void addChangeRevertedNotificationOps​(BatchUpdate bu,
                                                     Change.Id revertedChangeId,
                                                     Change.Id revertingChangeId,
                                                     String revertingChangeKey)
        Notify the owners of a change that their change is being reverted.
        Parameters:
        bu - to append the notification actions to.
        revertedChangeId - to be notified.
        revertingChangeId - to notify about.
        revertingChangeKey - to notify about.
      • getBaseCommit

        public static org.eclipse.jgit.revwalk.RevCommit getBaseCommit​(String project,
                                                                       InternalChangeQuery changeQuery,
                                                                       org.eclipse.jgit.revwalk.RevWalk revWalk,
                                                                       org.eclipse.jgit.lib.Ref destRef,
                                                                       String baseSha1)
                                                                throws IOException,
                                                                       RestApiException
        Returns the parent commit for a new commit.

        If baseSha1 is provided, the method verifies it can be used as a base. If baseSha1 is not provided the tip of the destRef is returned.

        Parameters:
        project - The name of the project.
        changeQuery - Used for looking up the base commit.
        revWalk - Used for parsing the base commit.
        destRef - The destination branch.
        baseSha1 - The hash of the base commit. Nullable.
        Returns:
        the base commit. Either the commit matching the provided hash, or the direct parent if a hash was not provided.
        Throws:
        IOException - if the branch reference cannot be parsed.
        RestApiException - if the base commit cannot be fetched.