public static FilePath @NotNull [] filterDescindingFiles(FilePath @NotNull [] roots, Project project) {
    final List<FilePath> result = new ArrayList<>();
    ProjectLevelVcsManager manager = ProjectLevelVcsManager.getInstance(project);

    Arrays.sort(roots, FilePathComparator.getInstance());
    final Map<VcsKey, List<FilePath>> chains = new HashMap<>();
    for (FilePath root : roots) {
      final AbstractVcs vcs = manager.getVcsFor(root);
      if (vcs == null) continue;
      if (vcs.allowsNestedRoots()) {
        // just put into result: nested roots are allowed
        result.add(root);
        continue;
      }
      //if (pathsFilter != null && (! pathsFilter.convert(new Pair<FilePath, AbstractVcs>(root, vcs)))) continue;

      final List<FilePath> chain = chains.get(vcs.getKeyInstanceMethod());
      if (chain == null) {
        final List<FilePath> newList = new ArrayList<>();
        newList.add(root);
        chains.put(vcs.getKeyInstanceMethod(), newList);
      }
      else {
        boolean failed = false;
        for (FilePath chainedPath : chain) {
          if (VfsUtilCore.isAncestor(chainedPath.getIOFile(), root.getIOFile(), false)) {
            // do not take this root
            failed = true;
            break;
          }
        }
        if (!failed) {
          chain.add(root);
        }
      }
    }

    for (List<FilePath> filePaths : chains.values()) {
      result.addAll(filePaths);
    }

    return result.toArray(new FilePath[0]);
  }
public static FilePath @NotNull [] filterDescindingFiles(FilePath @NotNull [] roots, Project project)