private List<FilePatch> buildAndSavePatchInBatches(@NotNull Path patchFile,
                                                     @NotNull List<Change> textChanges,
                                                     boolean honorExcludedFromCommit) throws IOException, VcsException {
    List<FilePatch> patches = new ArrayList<>();
    if (textChanges.isEmpty()) {
      savePatchFile(myProject, patchFile, patches, null, new CommitContext());
      return patches;
    }

    int batchIndex = 0;
    int baseContentsPreloadSize = Registry.intValue("git.shelve.load.base.in.batches", -1);
    int partitionSize = baseContentsPreloadSize > 0 ? baseContentsPreloadSize : textChanges.size();
    List<List<Change>> partition = Lists.partition(textChanges, partitionSize);
    for (List<Change> list : partition) {
      batchIndex++;
      int finalBatchIndex = batchIndex;
      try {
        runWithSpanThrows(myTracer, Shelve.BatchShelving.getName(), (span) -> {
          span.setAttribute("batch", finalBatchIndex);

          try {
            if (baseContentsPreloadSize > 0) {
              runWithSpan(myTracer, Shelve.PreloadingBaseRevisions.getName(), (preloadSpan) -> {
                preloadSpan.setAttribute("changesSize", list.size());
                preloadBaseRevisions(list);
              });
            }

            ProgressManager.checkCanceled();
            runWithSpanThrows(myTracer, Shelve.BuildingPatches.getName(), (__) -> {
              patches.addAll(IdeaTextPatchBuilder
                               .buildPatch(myProject, list, ProjectKt.getStateStore(myProject).getProjectBasePath(), false,
                                           honorExcludedFromCommit));
            });
            ProgressManager.checkCanceled();

            CommitContext commitContext = computeWithSpan(myTracer, Shelve.StoringBaseRevision.getName(), (__) -> {
              CommitContext context = new CommitContext();
              baseRevisionsOfDvcsIntoContext(list, context);
              return context;
            });

            runWithSpanThrows(myTracer, Shelve.StoringPathFile.getName(), (__) -> {
              savePatchFile(myProject, patchFile, patches, null, commitContext);
            });
          }
          finally {
            ProjectLevelVcsManager.getInstance(myProject).getContentRevisionCache().clearConstantCache();
          }
        });
      }
      catch (IOException | VcsException | RuntimeException e) {
        throw e;
      }
      catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return patches;
  }
private List<FilePatch> buildAndSavePatchInBatches(@NotNull Path patchFile,
                                                     @NotNull List<Change> textChanges,
                                                     boolean honorExcludedFromCommit)