Skip to content

Commit c7d1966

Browse files
committed
fixup
1 parent 2bd64cc commit c7d1966

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

dvc/external_repo.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ def close(self):
178178
self.scm.close()
179179

180180
def fetch_external(self, paths: Iterable, cache, **kwargs):
181+
# `RepoTree` will try downloading it to the repo's cache
182+
# instead of `cache_dir`, need to change on all instances
183+
with self.with_cache(cache.cache_dir):
184+
return self._fetch_to_cache(paths, cache, **kwargs)
185+
186+
def _fetch_to_cache(self, paths: Iterable, cache, **kwargs):
181187
"""Fetch specified external repo paths into cache.
182188
183189
Returns 3-tuple in the form
@@ -197,14 +203,13 @@ def download_update(result):
197203
for path in paths:
198204
if not self.repo_tree.exists(path):
199205
raise PathMissingError(path, self.url)
200-
with self.with_cache(cache.cache_dir):
201-
save_info = cache.save(
202-
path,
203-
self.repo_tree,
204-
None,
205-
save_link=False,
206-
download_callback=download_update,
207-
)
206+
save_info = cache.save(
207+
path,
208+
self.repo_tree,
209+
None,
210+
save_link=False,
211+
download_callback=download_update,
212+
)
208213
save_infos.append(save_info)
209214

210215
return sum(download_results), failed, save_infos
@@ -214,7 +219,7 @@ def get_external(self, src, dest):
214219
repo = self.in_repo(src)
215220
if repo:
216221
cache = repo.cache.local
217-
_, _, save_infos = self.fetch_external([src], cache)
222+
_, _, save_infos = self._fetch_to_cache([src], cache)
218223
cache.checkout(PathInfo(dest), save_infos[0])
219224
else:
220225
path = PathInfo(self.root_dir) / src
@@ -233,7 +238,7 @@ def get_checksum(self, path_info, cache):
233238
return self.repo_tree.get_file_hash(path_info)
234239

235240
def in_repo(self, path):
236-
tree = self.repo_tree.in_subtree(path)
241+
tree = self.repo_tree.in_subtree(PathInfo(self.root_dir) / path)
237242
return tree.repo if tree else None
238243

239244
@property

dvc/repo/tree.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,15 @@ def __init__(
253253
): # pylint: disable=super-init-not-called
254254
subrepos = subrepos or []
255255
subrepos.sort(key=lambda r: len(r.root_dir), reverse=True)
256-
dvctrees = [DvcTree(repo, **kwargs) for repo in subrepos]
257-
self._kwargs = kwargs
258-
self._dvctrees = {
259-
os.path.abspath(tree.repo.root_dir): tree for tree in dvctrees
260-
}
256+
dvctrees = [
257+
(os.path.abspath(repo.root_dir), DvcTree(repo, **kwargs))
258+
for repo in subrepos
259+
]
260+
self._dvctrees = dict(
261+
sorted(dvctrees, key=lambda v: len(v[0]), reverse=True)
262+
)
261263
self.tree = tree
264+
self._kwargs = kwargs
262265

263266
@property
264267
def fetch(self):
@@ -275,7 +278,7 @@ def _find_subtree_with_prefix(self, path):
275278
# dvctrees is already ordered from low to high
276279
path_prefix = os.path.abspath(path)
277280
for pref, tree in self._dvctrees.items():
278-
if os.path.abspath(path_prefix).startswith(pref):
281+
if path_prefix.startswith(pref):
279282
return pref, tree
280283
return "", None
281284

0 commit comments

Comments
 (0)