code: def _choose_update_target(repo, branch, remote, cfg_remote):
      """Select a target to update `repo` from.
  
      Note: This function is not concerned with _how_ the update is done (e.g.,
      merge, reset, ...).
  
      Parameters
      ----------
      repo : Repo instance
      branch : str
          The current branch.
      remote : str
          The remote which updates are coming from.
      cfg_remote : str
          The configured upstream remote.
  
      Returns
      -------
      str (the target) or None if a choice wasn't made.
      """
      target = None
      if cfg_remote and remote == cfg_remote:
          # Use the configured cfg_remote branch as the target.
          #
          # In this scenario, it's tempting to use FETCH_HEAD as the target. For
          # a merge, that would be the equivalent of 'git pull REMOTE'. But doing
          # so would be problematic when the GitRepo.fetch() call was passed
          # all_=True. Given we can't use FETCH_HEAD, it's tempting to use the
          # branch.*.merge value, but that assumes a value for remote.*.fetch.
          target = repo.call_git_oneline(
              [
                  "rev-parse",
                  "--symbolic-full-name",
                  "--abbrev-ref=strict",
                  f"{repo.get_corresponding_branch(branch) or ''}"
                  "@{upstream}",
              ],
              read_only=True,
          )
      elif branch:
          remote_branch = "{}/{}".format(remote, branch)
          if repo.commit_exists(remote_branch):
              target = remote_branch
      return target
  
imports: import logging
  from os.path import lexists
  import itertools
  from datalad.interface.base import Interface
  from datalad.interface.base import build_doc, eval_results
  from datalad.interface.results import get_status_dict, YieldDatasets
  from datalad.support.constraints import EnsureBool, EnsureChoice, EnsureStr, EnsureNone
  from datalad.support.annexrepo import AnnexRepo
  from datalad.support.exceptions import CapturedException, CommandError
  from datalad.support.param import Parameter
  from datalad.interface.common_opts import recursion_flag, recursion_limit
  from datalad.distribution.dataset import require_dataset
  from .dataset import EnsureDataset, datasetmethod
label_desc: Use image node_id 3 for calling a global function with example usage: _choose_update_target(repo, branch, remote, cfg_remote) and returns: target