Package com.google.gerrit.server.git
Class CommitUtil
java.lang.Object
com.google.gerrit.server.git.CommitUtil
Static utilities for working with
RevCommits.-
Method Summary
Modifier and TypeMethodDescriptionvoidaddChangeRevertedNotificationOps(BatchUpdate bu, Change.Id revertedChangeId, Change.Id revertingChangeId, String revertingChangeKey) Notify the owners of a change that their change is being reverted.static org.eclipse.jgit.lib.ObjectIdcreateCommitWithTree(org.eclipse.jgit.lib.ObjectInserter oi, org.eclipse.jgit.lib.PersonIdent authorIdent, org.eclipse.jgit.lib.PersonIdent committerIdent, List<org.eclipse.jgit.revwalk.RevCommit> parents, String commitMessage, org.eclipse.jgit.lib.ObjectId treeId) Creates a commit with the specified tree ID.createRevertChange(ChangeNotes notes, CurrentUser user, RevertInput input, Instant timestamp) Allows creating a revert change.createRevertCommit(String message, ChangeNotes notes, CurrentUser user, Instant ts) Wrapper function for creating a revert Commit.static org.eclipse.jgit.revwalk.RevCommitgetBaseCommit(String project, InternalChangeQuery changeQuery, org.eclipse.jgit.revwalk.RevWalk revWalk, org.eclipse.jgit.lib.Ref destRef, String baseSha1) Returns the parent commit for a new commit.static CommitInfotoCommitInfo(org.eclipse.jgit.revwalk.RevCommit commit) static CommitInfotoCommitInfo(org.eclipse.jgit.revwalk.RevCommit commit, org.eclipse.jgit.revwalk.RevWalk walk)
-
Method Details
-
toCommitInfo
- Throws:
IOException
-
toCommitInfo
public static CommitInfo toCommitInfo(org.eclipse.jgit.revwalk.RevCommit commit, org.eclipse.jgit.revwalk.RevWalk walk) throws IOException - Throws:
IOException
-
createRevertChange
public Change.Id createRevertChange(ChangeNotes notes, CurrentUser user, RevertInput input, Instant timestamp) throws RestApiException, UpdateException, org.eclipse.jgit.errors.ConfigInvalidException, IOException Allows creating a revert change.- Parameters:
notes- ChangeNotes of the change being reverted.user- Current User performing the revert.input- the RevertInput entity for conducting the revert.timestamp- timestamp for the created change.- Returns:
- ObjectId that represents the newly created commit.
- Throws:
RestApiExceptionUpdateExceptionorg.eclipse.jgit.errors.ConfigInvalidExceptionIOException
-
createRevertCommit
public CodeReviewCommit 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:
- that newly created revert commit.
- Throws:
RestApiExceptionIOException
-
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, List<org.eclipse.jgit.revwalk.RevCommit> parents, 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 commitcommitterIdent- of the new commitparents- of the new commit. Can be empty.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
baseSha1is provided, the method verifies it can be used as a base. IfbaseSha1is not provided the tip of thedestRefis 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.
-