Class ApplyPatchUtil


  • public final class ApplyPatchUtil
    extends Object
    Utility for applying a patch.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      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)
      Applies the given patch on top of the merge tip, using the given object inserter.
      static String buildCommitMessage​(String message, List<org.eclipse.jgit.revwalk.FooterLine> footerLines, String originalPatch, String resultPatch, List<org.eclipse.jgit.patch.PatchApplier.Result.Error> errors)
      Build commit message for commits with applied patch.
      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)
      Fetch the patch of the result tree.
    • Method Detail

      • 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 in
        oi - to operate with
        input - the patch for applying
        mergeTip - the tip to apply the patch on
        Returns:
        the tree ID with the applied patch
        Throws:
        IOException - if unable to create the jgit PatchApplier object
        RestApiException - for any other failure
      • buildCommitMessage

        public static String buildCommitMessage​(String message,
                                                List<org.eclipse.jgit.revwalk.FooterLine> footerLines,
                                                String originalPatch,
                                                String resultPatch,
                                                List<org.eclipse.jgit.patch.PatchApplier.Result.Error> errors)
                                         throws BadRequestException
        Build commit message for commits with applied patch.

        Message structure:

        1. Provided message.
        2. 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.
        3. 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.
        4. The provided footerLines, if any.
        Parameters:
        message - the first message piece, excluding footers
        footerLines - footer lines to append to the message
        originalPatch - to compare the result patch to
        resultPatch - to validate accuracy for
        Returns:
        the commit message
        Throws:
        BadRequestException - if the commit message cannot be sanitized
      • 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 applied
        reader - for the repo objects, including resultTree
        baseCommit - to generate patch against
        resultTree - to generate the patch for
        Returns:
        the result patch
        Throws:
        IOException - if the result patch cannot be written