code: def _push(
      dspath,
      content,
      target,
      data,
      force,
      jobs,
      res_kwargs,
      pbars,
      got_path_arg=False,
  ):
      force_git_push = force in ("all", "gitpush")
  
      # nothing recursive in here, we only need a repo to work with
      ds = Dataset(dspath)
      repo = ds.repo
  
      res_kwargs.update(type="dataset", path=dspath)
  
      # content will be unique for every push (even on the same dataset)
      pbar_id = "push-{}-{}".format(target, id(content))
      # register for final orderly take down
      pbars[pbar_id] = ds
      log_progress(
          lgr.info,
          pbar_id,
          "Determine push target",
          unit=" Steps",
          label="Push",
          total=4,
      )
      # pristine input arg
      _target = target
      # verified or auto-detected
      target = None
      if not _target:
          try:
              try:
                  # let Git figure out what needs doing
                  # we will reuse the result further down again, so nothing is wasted
                  wannabe_gitpush = repo.push(
                      remote=None, git_options=["--dry-run"]
                  )
                  # we did not get an explicit push target, get it from Git
                  target = set(
                      p.get("remote", None) for p in wannabe_gitpush
                  )
                  # handle case where a pushinfo record did not have a 'remote'
                  # property -- should not happen, but be robust
                  target.discard(None)
              except CommandError as e:
                  if (
                      "Please make sure you have the correct access rights"
                      in e.stderr
                  ):
                      # there is a default push target but we have no permission
                      yield dict(
                          res_kwargs,
                          status="impossible",
                          message="Attempt to push to default target resulted in following "
                          "error.  Address the error or specify different target with --to: "
                          + e.stderr,
                      )
                      return
                  raise
          except Exception as e:
              lgr.debug(
                  "Dry-run push to determine default push target failed, "
                  "assume no configuration: %s",
                  e,
              )
              target = set()
          if not len(target):
              yield dict(
                  res_kwargs,
                  status="impossible",
                  message="No push target given, and none could be "
                  "auto-detected, please specify via --to",
              )
              return
          elif len(target) > 1:
              # dunno if this can ever happen, but if it does, report
              # nicely
              yield dict(
                  res_kwargs,
                  status="error",
                  message=(
                      "No push target given, "
                      "multiple candidates auto-detected: %s",
                      list(target),
                  ),
              )
              return
          else:
              # can only be a single one at this point
              target = target.pop()
  
      if not target:
          if _target not in repo.get_remotes():
              yield dict(
                  res_kwargs,
                  status="error",
                  message=("Unknown target sibling '%s'.", _target),
              )
              return
          target = _target
  
      log_progress(
          lgr.info,
          pbar_id,
          "Push refspecs",
          label="Push to '{}'".format(target),
          update=1,
          total=4,
      )
  
      # define config var name for potential publication dependencies
      depvar = "remote.{}.datalad-publish-depends".format(target)
      # list of remotes that are publication dependencies for the
      # target remote
      publish_depends = ensure_list(
          ds.config.get(depvar, [], get_all=True)
      )
      if publish_depends:
          lgr.debug(
              "Discovered publication dependencies for '%s': %s'",
              target,
              publish_depends,
          )
  
      # cache repo type
      is_annex_repo = isinstance(ds.repo, AnnexRepo)
  
      # TODO prevent this when `target` is a special remote
      # (possibly redo) a push attempt to figure out what needs pushing
      # do this on the main target only, and apply the result to all
      # dependencies
      try:
          if _target:
              # only do it when an explicit target was given, otherwise
              # we can reuse the result from the auto-probing above
              wannabe_gitpush = repo.push(
                  remote=target, git_options=["--dry-run"]
              )
      except Exception as e:
          lgr.debug(
              "Dry-run push to check push configuration failed, "
              "assume no configuration: %s",
              e,
          )
          wannabe_gitpush = []
      refspecs2push = [
          # if an upstream branch is set, go with it
          p["from_ref"]
          if ds.config.get(
              # refs come in as refs/heads/<branchname>
              # need to cut the prefix
              "branch.{}.remote".format(p["from_ref"][11:]),
              None,
          )
          == target
          and ds.config.get(
              "branch.{}.merge".format(p["from_ref"][11:]), None
          )
          # if not, define target refspec explicitly to avoid having to
          # set an upstream branch, which would happen implicitly from
          # a users POV, and may also be hard to decide when publication
          # dependencies are present
          else "{}:{}".format(p["from_ref"], p["to_ref"])
          for p in wannabe_gitpush
          # TODO: what if a publication dependency doesn't have it yet
          # should we not attempt to push, because the main target has it?
          if "uptodate" not in p["operations"]
          and (
              # cannot think of a scenario where we would want to push a
              # managed branch directly, instead of the corresponding branch
              "refs/heads/adjusted"
              not in p["from_ref"]
          )
      ]
      # TODO this is not right with managed branches
      active_branch = repo.get_active_branch()
      if active_branch and is_annex_repo:
          # we could face a managed branch, in which case we need to
          # determine the actual one and make sure it is sync'ed with the
          # managed one, and push that one instead. following methods can
          # be called unconditionally
          repo.localsync(managed_only=True)
          active_branch = (
              repo.get_corresponding_branch(active_branch)
              or active_branch
          )
  
      if not refspecs2push and not active_branch:
          # nothing was set up for push, and we have no active branch
          # this is a weird one, let's confess and stop here
          # I don't think we need to support such a scenario
          if not active_branch:
              yield dict(
                  res_kwargs,
                  status="impossible",
                  message="There is no active branch, cannot determine remote "
                  "branch",
              )
              return
  
      # make sure that we always push the active branch (the context for the
      # potential path arguments) and the annex branch -- because we claim
      # to know better than any git config
      must_have_branches = [active_branch] if active_branch else []
      if is_annex_repo:
          must_have_branches.append("git-annex")
      for branch in must_have_branches:
          _append_branch_to_refspec_if_needed(ds, refspecs2push, branch)
  
      # we know what to push and where, now dependency processing first
      for r in publish_depends:
          # simply make a call to this function again, all the same, but
          # target is different
          yield from _push(
              dspath,
              content,
              # to this particular dependency
              r,
              data,
              force,
              jobs,
              res_kwargs.copy(),
              pbars,
              got_path_arg=got_path_arg,
          )
  
      # and lastly the primary push target
      target_is_git_remote = (
          repo.config.get("remote.{}.url".format(target), None)
          is not None
      )
  
      # git-annex data copy
      #
      if is_annex_repo:
          if data != "nothing":
              log_progress(
                  lgr.info,
                  pbar_id,
                  "Transfer data",
                  label="Transfer data to '{}'".format(target),
                  update=2,
                  total=4,
              )
              yield from _transfer_data(
                  repo,
                  ds,
                  target,
                  content,
                  data,
                  force,
                  jobs,
                  res_kwargs.copy(),
                  got_path_arg=got_path_arg,
              )
          else:
              lgr.debug(
                  "Data transfer to '%s' disabled by argument", target
              )
      else:
          lgr.debug(
              "No data transfer: %s is not a git annex repository", repo
          )
  
      if not target_is_git_remote:
          # there is nothing that we need to push or sync with on the git-side
          # of things with this remote
          return
  
      log_progress(
          lgr.info,
          pbar_id,
          "Update availability information",
          label="Update availability for '{}'".format(target),
          update=3,
          total=4,
      )
  
      # TODO fetch is only needed if anything was actually transferred. Collect this
      # info and make the following conditional on it
  
      # after file transfer the remote might have different commits to
      # the annex branch. They have to be merged locally, otherwise a
      # push of it further down will fail
      try:
          # fetch remote, let annex sync them locally, so that the push
          # later on works.
          # We have to fetch via the push url (if there is any),
          # not a pull url.
          # The latter might be dumb and without the execution of a
          # post-update hook we might not be able to retrieve the
          # server-side git-annex branch updates (and git-annex does
          # not trigger the hook on copy), but we know we have
          # full access via the push url -- we have just used it to copy.
          lgr.debug(
              "Fetching 'git-annex' branch updates from '%s'", target
          )
          fetch_cmd = ["fetch", target, "git-annex"]
          pushurl = repo.config.get(
              "remote.{}.pushurl".format(target), None
          )
          if pushurl:
              # for some reason overwriting remote.{target}.url
              # does not have any effect...
              fetch_cmd = [
                  "-c",
                  "url.{}.insteadof={}".format(
                      pushurl,
                      repo.config.get(
                          "remote.{}.url".format(target), None
                      ),
                  ),
              ] + fetch_cmd
              lgr.debug(
                  "Sync local annex branch from pushurl after remote "
                  "availability update."
              )
          repo.call_git(fetch_cmd)
          # If no CommandError was raised, it means that remote has git-annex
          # but local repo might not be an annex yet. Since there is nothing to "sync"
          # from us, we just skip localsync without mutating repo into an AnnexRepo
          if is_annex_repo:
              repo.localsync(target)
      except CommandError as e:
          # it is OK if the remote doesn't have a git-annex branch yet
          # (e.g. fresh repo)
          # TODO is this possible? we just copied? Maybe check if anything
          # was actually copied?
          if (
              "fatal: couldn't find remote ref git-annex"
              not in e.stderr.lower()
          ):
              raise
          lgr.debug("Remote does not have a git-annex branch: %s", e)
  
      if not refspecs2push:
          lgr.debug("No refspecs found that need to be pushed")
          return
  
      # and push all relevant branches, plus the git-annex branch to announce
      # local availability info too
      yield from _push_refspecs(
          repo,
          target,
          refspecs2push,
          force_git_push,
          res_kwargs.copy(),
      )
  
imports: from itertools import chain
  import logging
  import re
  from datalad.interface.base import Interface, build_doc, eval_results
  from datalad.interface.common_opts import jobs_opt, recursion_limit, recursion_flag
  from datalad.interface.utils import render_action_summary
  from datalad.interface.results import annexjson2result
  from datalad.log import log_progress
  from datalad.support.annexrepo import AnnexRepo
  from datalad.support.gitrepo import GitRepo
  from datalad.support.param import Parameter
  from datalad.support.constraints import EnsureStr, EnsureNone, EnsureChoice
  from datalad.support.exceptions import CommandError
  from datalad.utils import Path, ensure_list, todo_interface_for_extensions
  from datalad.distribution.dataset import Dataset, EnsureDataset, datasetmethod, require_dataset, resolve_path
  from datalad.core.local.diff import diff_dataset
label_desc: Use image node_id 3 for calling a global function with example usage: _push(dspath, content, target, data, force, jobs, res_kwargs, pbars, got_path_arg) without return types