code: def _get_dot_git(pathobj, *, ok_missing=False, resolved=False):
      """Given a pathobj to a repository return path to the .git directory
  
      Parameters
      ----------
      pathobj: Path
      ok_missing: bool, optional
        Allow for .git to be missing (useful while sensing before repo is
        initialized)
      resolved : bool, optional
        Whether to resolve any symlinks in the path, at a performance cost.
  
      Raises
      ------
      RuntimeError
        When ok_missing is False and .git path does not exist
  
      Returns
      -------
      Path
        Path to the (resolved) .git directory. If `resolved` is False, and
        the given `pathobj` is not an absolute path, the returned path will
        also be relative.
      """
      dot_git = pathobj / ".git"
      if dot_git.is_dir():
          # deal with the common case immediately, an existing dir
          return dot_git.resolve() if resolved else dot_git
      elif not dot_git.exists():
          # missing or bare
          if (pathobj / "HEAD").exists() and (
              pathobj / "config"
          ).exists():
              return pathobj.resolve() if resolved else pathobj
          elif not ok_missing:
              raise RuntimeError("Missing .git in %s." % pathobj)
          else:
              # resolve to the degree possible
              return dot_git.resolve(strict=False)
      # continue with more special cases
      elif dot_git.is_file():
          with dot_git.open() as f:
              line = f.readline()
              if line.startswith("gitdir: "):
                  dot_git = pathobj / line[7:].strip()
                  return dot_git.resolve() if resolved else dot_git
              else:
                  raise InvalidGitRepositoryError("Invalid .git file")
      raise RuntimeError("Unaccounted condition")
  
imports: import logging
  import re
  import threading
  import time
  from contextlib import contextmanager
  from locale import getpreferredencoding
  from os import environ
  from os.path import lexists
  from typing import Optional
  from weakref import finalize, WeakValueDictionary
  from datalad.cmd import GitWitlessRunner, StdOutErrCapture
  from datalad.config import ConfigManager
  from datalad.dataset.repo import PathBasedFlyweight, RepoInterface, path_based_str_repr
  from datalad.runner.nonasyncrunner import STDERR_FILENO, STDOUT_FILENO
  from datalad.runner.protocol import GeneratorMixIn
  from datalad.runner.utils import AssemblingDecoderMixIn, LineSplitter
  from datalad.support.exceptions import CommandError, GitIgnoreError, InvalidGitRepositoryError, PathKnownToRepositoryError
  from datalad.utils import ensure_list, lock_if_required, Path
label_desc: Use image node_id 3 for calling a global function with example usage: _get_dot_git(pathobj) and returns: unknown, unknown, dot_git, unknown