@Override
  protected @NotNull Result applyChange(@NotNull Project project,
                                        @NotNull VirtualFile fileToPatch,
                                        @NotNull FilePath pathBeforeRename,
                                        @Nullable Supplier<? extends CharSequence> baseContents) throws IOException {
    final Document document = FileDocumentManager.getInstance().getDocument(fileToPatch);
    if (document == null) {
      throw new IOException("Failed to set contents for updated file " + fileToPatch.getPath());
    }

    GenericPatchApplier.AppliedPatch appliedPatch = GenericPatchApplier.apply(document.getText(), myPatch.getHunks());
    if (appliedPatch != null) {
      if (appliedPatch.status == ApplyPatchStatus.ALREADY_APPLIED) {
        return new Result(appliedPatch.status);
      }

      if (appliedPatch.status == ApplyPatchStatus.SUCCESS) {
        VcsFacade.getInstance().runHeavyModificationTask(project, document, () -> document.setText(appliedPatch.patchedText));
        FileDocumentManager.getInstance().saveDocument(document);
        return new Result(appliedPatch.status);
      }
    }

    ApplyPatchStatus status = appliedPatch != null ? appliedPatch.status : ApplyPatchStatus.FAILURE;
    assert status == ApplyPatchStatus.PARTIAL || status == ApplyPatchStatus.FAILURE;
    return new Result(status) {
      @Override
      public ApplyPatchForBaseRevisionTexts getMergeData() {
        return ApplyPatchForBaseRevisionTexts.create(project, fileToPatch, pathBeforeRename, myPatch,
                                                     baseContents != null ? baseContents.get() : null);
      }
    };
  }
@Override
  protected @NotNull Result applyChange(@NotNull Project project,
                                        @NotNull VirtualFile fileToPatch,
                                        @NotNull FilePath pathBeforeRename,
                                        @Nullable Supplier<? extends CharSequence> baseContents)