erepo: drop dvcx for_write support

This commit is contained in:
Peter Rowlands
2023-07-12 14:45:11 +09:00
committed by Peter Rowlands (변기호)
parent 1b2291ca83
commit f69b3533e4
+8 -32
View File
@@ -23,11 +23,10 @@ logger = logging.getLogger(__name__)
def _external_repo(
url,
rev: Optional[str] = None,
for_write: bool = False,
**kwargs,
) -> Iterator["Repo"]:
logger.debug("Creating external repo %s@%s", url, rev)
path = _cached_clone(url, rev, for_write=for_write)
path = _cached_clone(url, rev)
# Local HEAD points to the tip of whatever branch we first cloned from
# (which may not be the default branch), use origin/HEAD here to get
# the tip of the default branch
@@ -38,11 +37,6 @@ def _external_repo(
config.update(kwargs.pop("config", None) or {})
main_root = "/"
if for_write:
# we already checked out needed revision
rev = None
main_root = path
repo_kwargs = dict(
root_dir=path,
url=url,
@@ -58,8 +52,6 @@ def _external_repo(
yield repo
finally:
repo.close()
if for_write:
_remove(path)
def open_repo(url, *args, **kwargs):
@@ -140,20 +132,19 @@ def _get_remote_config(url):
repo.close()
def _cached_clone(url, rev, for_write=False):
def _cached_clone(url, rev):
"""Clone an external git repo to a temporary directory.
Returns the path to a local temporary directory with the specified
revision checked out. If for_write is set prevents reusing this dir via
cache.
revision checked out.
"""
from shutil import copytree
# even if we have already cloned this repo, we may need to
# fetch/fast-forward to get specified rev
clone_path, shallow = _clone_default_branch(url, rev, for_write=for_write)
clone_path, shallow = _clone_default_branch(url, rev)
if not for_write and (url) in CLONES:
if url in CLONES:
return CLONES[url][0]
# Copy to a new dir to keep the clone clean
@@ -161,16 +152,12 @@ def _cached_clone(url, rev, for_write=False):
logger.debug("erepo: making a copy of %s clone", url)
copytree(clone_path, repo_path)
# Check out the specified revision
if for_write:
_git_checkout(repo_path, rev)
else:
CLONES[url] = (repo_path, shallow)
CLONES[url] = (repo_path, shallow)
return repo_path
@wrap_with(threading.Lock())
def _clone_default_branch(url, rev, for_write=False): # noqa: C901, PLR0912
def _clone_default_branch(url, rev): # noqa: C901, PLR0912
"""Get or create a clean clone of the url.
The cloned is reactualized with git pull unless rev is a known sha.
@@ -204,7 +191,7 @@ def _clone_default_branch(url, rev, for_write=False): # noqa: C901, PLR0912
logger.debug("erepo: git clone '%s' to a temporary dir", url)
clone_path = tempfile.mkdtemp("dvc-clone")
if not for_write and rev and not Git.is_sha(rev):
if rev and not Git.is_sha(rev):
# If rev is a tag or branch name try shallow clone first
try:
@@ -249,17 +236,6 @@ def _merge_upstream(git: "Git"):
pass
def _git_checkout(repo_path, rev):
from dvc.scm import Git
logger.debug("erepo: git checkout %s@%s", repo_path, rev)
git = Git(repo_path)
try:
git.checkout(rev)
finally:
git.close()
def _remove(path):
from dvc.utils.fs import remove