Skip to content

Commit 86b9a1c

Browse files
get: recoup cache optimal location
1 parent f126f24 commit 86b9a1c

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

dvc/external_repo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def external_repo(url=None, rev=None, rev_lock=None, cache_dir=None):
3333
repo.close()
3434

3535

36-
def cached_clone(url, rev=None, clone_path=None, **_ignored_kwargs):
36+
def cached_clone(url, rev=None, **_ignored_kwargs):
3737
"""Clone an external git repo to a temporary directory.
3838
3939
Returns the path to a local temporary directory with the specified
@@ -44,7 +44,7 @@ def cached_clone(url, rev=None, clone_path=None, **_ignored_kwargs):
4444
4545
"""
4646

47-
new_path = clone_path or tempfile.mkdtemp("dvc-erepo")
47+
new_path = tempfile.mkdtemp("dvc-erepo")
4848

4949
# Copy and adjust existing clean clone
5050
if (url, None, None) in REPO_CACHE:

dvc/repo/get.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
import shortuuid
55

6+
from dvc.cache import CacheConfig
7+
from dvc.config import Config
68
from dvc.exceptions import (
79
DvcException,
810
NotDvcRepoError,
@@ -49,9 +51,11 @@ def get(url, path, out=None, rev=None):
4951
dpath = os.path.dirname(os.path.abspath(out))
5052
tmp_dir = os.path.join(dpath, "." + str(shortuuid.uuid()))
5153
try:
52-
cached_clone(url, rev=rev, clone_path=tmp_dir)
54+
clone_dir = cached_clone(url, rev=rev)
5355
try:
54-
repo = Repo(tmp_dir)
56+
repo = Repo(clone_dir)
57+
cache_config = CacheConfig(repo.config)
58+
cache_config.set_dir(tmp_dir, level=Config.LEVEL_LOCAL)
5559

5660
# Try any links possible to avoid data duplication.
5761
#
@@ -78,12 +82,13 @@ def get(url, path, out=None, rev=None):
7882
if os.path.isabs(path):
7983
raise FileNotFoundError
8084

81-
fs_copy(os.path.join(tmp_dir, path), out)
85+
fs_copy(os.path.join(clone_dir, path), out)
8286

8387
except (OutputNotFoundError, FileNotFoundError):
8488
raise PathMissingError(path, url)
8589
finally:
8690
remove(tmp_dir)
91+
remove(clone_dir)
8792

8893

8994
def _get_cached(repo, output, out):

0 commit comments

Comments
 (0)