public void checkpoint(SegmentInfos segmentInfos, boolean isCommit) throws IOException {

    if (infoStream != null) {
      message("now checkpoint \"" + segmentInfos.getCurrentSegmentFileName() + "\" [" + segmentInfos.size() + " segments " + "; isCommit = " + isCommit + "]");
    }

    // Try again now to delete any previously un-deletable
    // files (because they were in use, on Windows):
    deletePendingFiles();

    // Incref the files:
    incRef(segmentInfos, isCommit);

    if (isCommit) {
      // Append to our commits list:
      commits.add(new CommitPoint(commitsToDelete, directory, segmentInfos));

      // Tell policy so it can remove commits:
      policy.onCommit(commits);

      // Decref files for commits that were deleted by the policy:
      deleteCommits();
    } else {

      final List<String> docWriterFiles;
      if (docWriter != null) {
        docWriterFiles = docWriter.openFiles();
        if (docWriterFiles != null)
          // We must incRef these files before decRef'ing
          // last files to make sure we don't accidentally
          // delete them:
          incRef(docWriterFiles);
      } else
        docWriterFiles = null;

      // DecRef old files from the last checkpoint, if any:
      int size = lastFiles.size();
      if (size > 0) {
        for(int i=0;i<size;i++)
          decRef(lastFiles.get(i));
        lastFiles.clear();
      }

      // Save files so we can decr on next checkpoint/commit:
      lastFiles.add(segmentInfos.files(directory, false));

      if (docWriterFiles != null)
        lastFiles.add(docWriterFiles);
    }
  }