code: def _get_repo_path(pathname, levels=None):
      
  
      if os.path.isfile(pathname):
          current_dir = os.path.abspath(os.path.dirname(pathname))
      elif os.path.isdir(pathname):
          current_dir = os.path.abspath(pathname)
      else:
          return None
  
      current_level = 0
  
      while levels is None or current_level <= levels:
          if os.path.exists(os.path.join(current_dir, '.git')):
              return current_dir
  
          current_level += 1
          if current_dir == os.path.dirname(current_dir):
              break
  
          current_dir = os.path.dirname(current_dir)
  
      return None
docs: Given a file or directory name, determine the root of the git repository
      this path is under.  If given, this won't look any higher than ``levels``
      (that is, if ``levels=0`` then the given path must be the root of the git
      repository and is returned if so.
  
      Returns `None` if the given path could not be determined to belong to a git
      repo.