code: def lock_repo(repo: "Repo"):
      depth: int = repo._lock_depth
      repo._lock_depth += 1
  
      try:
          if depth > 0:
              yield
          else:
              with repo.lock:
                  repo._reset()
                  yield
                  # Graph cache is no longer valid after we release the repo.lock
                  repo._reset()
      finally:
          repo._lock_depth = depth
  
imports: import os
  from collections import defaultdict
  from contextlib import contextmanager
  from functools import wraps
  from typing import TYPE_CHECKING, Callable, ContextManager, Iterable, Optional, Tuple, Union
  from dvc.exceptions import DvcException, NotDvcRepoError, OutputNotFoundError, RevCollectionError
  from dvc.ignore import DvcIgnoreFilter
  from dvc.log import logger
  from dvc.utils.objects import cached_property
label_desc: Use image node_id 1 for calling a global function with example usage: lock_repo(repo) without return types