Package com.google.gerrit.server.patch
Class ApplyPatchUtil
java.lang.Object
com.google.gerrit.server.patch.ApplyPatchUtil
Utility for applying a patch.
-
Method Summary
Modifier and TypeMethodDescriptionstatic org.eclipse.jgit.patch.PatchApplier.ResultapplyPatch(org.eclipse.jgit.lib.Repository repo, org.eclipse.jgit.lib.ObjectInserter oi, ApplyPatchInput input, org.eclipse.jgit.revwalk.RevCommit mergeTip) Applies the given patch on top of the merge tip, using the given object inserter.static StringbuildCommitMessage(String message, List<org.eclipse.jgit.revwalk.FooterLine> footerLines, ApplyPatchInput patchInput, String resultPatch, List<org.eclipse.jgit.patch.PatchApplier.Result.Error> errors) Build commit message for commits with applied patch.static StringgetResultPatch(org.eclipse.jgit.lib.Repository repo, org.eclipse.jgit.lib.ObjectReader reader, org.eclipse.jgit.revwalk.RevCommit baseCommit, org.eclipse.jgit.revwalk.RevTree resultTree) Fetch the patch of the result tree.static com.google.common.hash.HashCode
-
Method Details
-
applyPatch
public static org.eclipse.jgit.patch.PatchApplier.Result applyPatch(org.eclipse.jgit.lib.Repository repo, org.eclipse.jgit.lib.ObjectInserter oi, ApplyPatchInput input, org.eclipse.jgit.revwalk.RevCommit mergeTip) throws IOException, RestApiException Applies the given patch on top of the merge tip, using the given object inserter.- Parameters:
repo- to apply the patch inoi- to operate withinput- the patch for applyingmergeTip- the tip to apply the patch on- Returns:
- the tree ID with the applied patch
- Throws:
IOException- if unable to create the jgit PatchApplier objectRestApiException- for any other failure
-
buildCommitMessage
public static String buildCommitMessage(String message, List<org.eclipse.jgit.revwalk.FooterLine> footerLines, ApplyPatchInput patchInput, String resultPatch, List<org.eclipse.jgit.patch.PatchApplier.Result.Error> errors) throws BadRequestException Build commit message for commits with applied patch.Message structure:
- Provided
message. - In case of errors while applying the patch - a warning message which includes the errors; as well as the original patch's header if available, or the full original patch otherwise.
- If there are no explicit errors, but the result change's patch is not the same as the original patch - a warning message which includes the diff; as well as the original patch's header if available, or the full original patch otherwise.
- The provided
footerLines, if any.
- Parameters:
message- the first message piece, excluding footersfooterLines- footer lines to append to the messagepatchInput- API input that triggered this actionresultPatch- to validate accuracy for- Returns:
- the commit message
- Throws:
BadRequestException- if the commit message cannot be sanitized
- Provided
-
getResultPatch
public static String getResultPatch(org.eclipse.jgit.lib.Repository repo, org.eclipse.jgit.lib.ObjectReader reader, org.eclipse.jgit.revwalk.RevCommit baseCommit, org.eclipse.jgit.revwalk.RevTree resultTree) throws IOException Fetch the patch of the result tree.- Parameters:
repo- in which the patch was appliedreader- for the repo objects, includingresultTreebaseCommit- to generate patch againstresultTree- to generate the patch for- Returns:
- the result patch
- Throws:
IOException- if the result patch cannot be written
-
sha1
-