mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-19 07:18:27 +01:00
erepo: drop dvcx for_write support
This commit is contained in:
committed by
Peter Rowlands (변기호)
parent
1b2291ca83
commit
f69b3533e4
+8
-32
@@ -23,11 +23,10 @@ logger = logging.getLogger(__name__)
|
|||||||
def _external_repo(
|
def _external_repo(
|
||||||
url,
|
url,
|
||||||
rev: Optional[str] = None,
|
rev: Optional[str] = None,
|
||||||
for_write: bool = False,
|
|
||||||
**kwargs,
|
**kwargs,
|
||||||
) -> Iterator["Repo"]:
|
) -> Iterator["Repo"]:
|
||||||
logger.debug("Creating external repo %s@%s", url, rev)
|
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
|
# 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
|
# (which may not be the default branch), use origin/HEAD here to get
|
||||||
# the tip of the default branch
|
# the tip of the default branch
|
||||||
@@ -38,11 +37,6 @@ def _external_repo(
|
|||||||
config.update(kwargs.pop("config", None) or {})
|
config.update(kwargs.pop("config", None) or {})
|
||||||
|
|
||||||
main_root = "/"
|
main_root = "/"
|
||||||
if for_write:
|
|
||||||
# we already checked out needed revision
|
|
||||||
rev = None
|
|
||||||
main_root = path
|
|
||||||
|
|
||||||
repo_kwargs = dict(
|
repo_kwargs = dict(
|
||||||
root_dir=path,
|
root_dir=path,
|
||||||
url=url,
|
url=url,
|
||||||
@@ -58,8 +52,6 @@ def _external_repo(
|
|||||||
yield repo
|
yield repo
|
||||||
finally:
|
finally:
|
||||||
repo.close()
|
repo.close()
|
||||||
if for_write:
|
|
||||||
_remove(path)
|
|
||||||
|
|
||||||
|
|
||||||
def open_repo(url, *args, **kwargs):
|
def open_repo(url, *args, **kwargs):
|
||||||
@@ -140,20 +132,19 @@ def _get_remote_config(url):
|
|||||||
repo.close()
|
repo.close()
|
||||||
|
|
||||||
|
|
||||||
def _cached_clone(url, rev, for_write=False):
|
def _cached_clone(url, rev):
|
||||||
"""Clone an external git repo to a temporary directory.
|
"""Clone an external git repo to a temporary directory.
|
||||||
|
|
||||||
Returns the path to a local temporary directory with the specified
|
Returns the path to a local temporary directory with the specified
|
||||||
revision checked out. If for_write is set prevents reusing this dir via
|
revision checked out.
|
||||||
cache.
|
|
||||||
"""
|
"""
|
||||||
from shutil import copytree
|
from shutil import copytree
|
||||||
|
|
||||||
# even if we have already cloned this repo, we may need to
|
# even if we have already cloned this repo, we may need to
|
||||||
# fetch/fast-forward to get specified rev
|
# 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]
|
return CLONES[url][0]
|
||||||
|
|
||||||
# Copy to a new dir to keep the clone clean
|
# 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)
|
logger.debug("erepo: making a copy of %s clone", url)
|
||||||
copytree(clone_path, repo_path)
|
copytree(clone_path, repo_path)
|
||||||
|
|
||||||
# Check out the specified revision
|
CLONES[url] = (repo_path, shallow)
|
||||||
if for_write:
|
|
||||||
_git_checkout(repo_path, rev)
|
|
||||||
else:
|
|
||||||
CLONES[url] = (repo_path, shallow)
|
|
||||||
return repo_path
|
return repo_path
|
||||||
|
|
||||||
|
|
||||||
@wrap_with(threading.Lock())
|
@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.
|
"""Get or create a clean clone of the url.
|
||||||
|
|
||||||
The cloned is reactualized with git pull unless rev is a known sha.
|
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)
|
logger.debug("erepo: git clone '%s' to a temporary dir", url)
|
||||||
clone_path = tempfile.mkdtemp("dvc-clone")
|
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
|
# If rev is a tag or branch name try shallow clone first
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -249,17 +236,6 @@ def _merge_upstream(git: "Git"):
|
|||||||
pass
|
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):
|
def _remove(path):
|
||||||
from dvc.utils.fs import remove
|
from dvc.utils.fs import remove
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user