Class ApplyPatchUtil


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

      • applyPatch

        public static org.eclipse.jgit.lib.ObjectId 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)
                                         throws BadRequestException
        Build commit message for commits with applied patch.

        Message structure:

        1. Provided message.
        2. In case 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.
        3. 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