Package com.google.gerrit.server.git
Class CommitUtil
- java.lang.Object
-
- com.google.gerrit.server.git.CommitUtil
-
public class CommitUtil extends Object
Static utilities for working withRevCommits.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddChangeRevertedNotificationOps(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, org.eclipse.jgit.revwalk.RevCommit parentCommit, String commitMessage, org.eclipse.jgit.lib.ObjectId treeId)Creates a commit with the specified tree ID.Change.IdcreateRevertChange(ChangeNotes notes, CurrentUser user, RevertInput input, Instant timestamp)Allows creating a revert change.org.eclipse.jgit.lib.ObjectIdcreateRevertCommit(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 Detail
-
toCommitInfo
public static CommitInfo toCommitInfo(org.eclipse.jgit.revwalk.RevCommit commit) throws IOException
- 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 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:
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, org.eclipse.jgit.revwalk.RevCommit parentCommit, String commitMessage, org.eclipse.jgit.lib.ObjectId treeId) throws IOExceptionCreates a commit with the specified tree ID.- Parameters:
oi- ObjectInserter for inserting the newly created commit.authorIdent- of the new commitcommitterIdent- of the new commitparentCommit- 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
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.
-
-