code: def _collect_indexes(  # noqa: PLR0913
      repo,
      targets=None,
      remote=None,
      all_branches=False,
      with_deps=False,
      all_tags=False,
      recursive=False,
      all_commits=False,
      revs=None,
      workspace=True,
      max_size=None,
      types=None,
      config=None,
      onerror=None,
      push=False,
  ):
      indexes = {}
      collection_exc = None
  
      config = config or {}
      if remote:
          core = config.get("core") or {}
          core["remote"] = remote
          config["core"] = core
  
      def stage_filter(stage: "Stage") -> bool:
          if push and stage.is_repo_import:
              return False
          return True
  
      def outs_filter(out: "Output") -> bool:
          if push and not out.can_push:
              return False
          return True
  
      for rev in repo.brancher(
          revs=revs,
          all_branches=all_branches,
          all_tags=all_tags,
          all_commits=all_commits,
          workspace=workspace,
      ):
          try:
              repo.config.merge(config)
  
              idx = repo.index.targets_view(
                  targets,
                  with_deps=with_deps,
                  recursive=recursive,
                  max_size=max_size,
                  types=types,
                  stage_filter=stage_filter,
                  outs_filter=outs_filter,
              )
  
              idx.data["repo"].onerror = _make_index_onerror(
                  onerror, rev
              )
  
              indexes[rev or "workspace"] = idx
          except Exception as exc:  # noqa: BLE001
              if onerror:
                  onerror(rev, None, exc)
              collection_exc = exc
              logger.warning(
                  "failed to collect '%s', skipping", rev or "workspace"
              )
  
      if not indexes and collection_exc:
          raise collection_exc
  
      return indexes
  
file_path: dvc/dvc/repo/fetch.py
imports: from typing import TYPE_CHECKING, List, Tuple
  from dvc.exceptions import DownloadError
  from dvc.log import logger
  from dvc.ui import ui
  from dvc_data.index import DataIndex, FileStorage
  from .None import locked
label_desc: Use image node_id 2 for calling a global function with example usage: _collect_indexes(repo, targets, remote, all_branches, with_deps, all_tags, recursive, all_commits, revs, workspace, max_size, types, config, onerror, push) and returns: indexes, True, True, False, False