Skip to content

Commit 0635b0c

Browse files
committed
index: check dep.hash_name for imports
1 parent 06abf73 commit 0635b0c

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

dvc/repo/index.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def is_out_or_ignored(root, directory):
104104
dirs[:] = [d for d in dirs if not is_out_or_ignored(root, d)]
105105

106106

107-
def _load_data_from_tree(index, prefix, ws, key, tree):
107+
def _load_data_from_tree(index, prefix, ws, key, tree, hash_name):
108108
from dvc_data.index import DataIndexEntry, Meta
109109

110110
parents = set()
@@ -117,7 +117,7 @@ def _load_data_from_tree(index, prefix, ws, key, tree):
117117
index[(*prefix, ws, *fkey)] = DataIndexEntry(
118118
key=fkey,
119119
meta=ometa,
120-
hash_info=ohi,
120+
hash_info=ohi if (ohi and ohi.name == hash_name) else None,
121121
)
122122

123123
for parent in parents:
@@ -151,7 +151,7 @@ def _load_data_from_outs(index, prefix, outs):
151151
tree = out.get_obj()
152152

153153
if tree is not None:
154-
_load_data_from_tree(index, prefix, ws, key, tree)
154+
_load_data_from_tree(index, prefix, ws, key, tree, out.hash_name)
155155

156156
entry = DataIndexEntry(
157157
key=key,
@@ -193,16 +193,22 @@ def _load_storage_from_import(storage_map, key, out):
193193
return
194194

195195
dep = out.stage.deps[0]
196-
if not out.hash_info and (
197-
not dep.hash_info or dep.hash_info.name != storage_map[key].cache.odb.hash_name
198-
):
199-
# partial import
196+
if not out.hash_info or dep.fs.version_aware:
197+
if dep.meta and dep.meta.isdir:
198+
meta_token = dep.hash_info.value
199+
else:
200+
meta_token = tokenize(dep.meta.to_dict())
201+
200202
fs_cache = out.repo.cache.fs_cache
201203
storage_map.add_cache(
202204
FileStorage(
203205
key,
204206
fs_cache.fs,
205-
fs_cache.fs.join(fs_cache.path, dep.fs.protocol, tokenize(dep.fs_path)),
207+
fs_cache.fs.join(
208+
fs_cache.path,
209+
dep.fs.protocol,
210+
tokenize(dep.fs_path, meta_token),
211+
),
206212
)
207213
)
208214

dvc/testing/workspace_tests.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ def test_import_file(self, tmp_dir, dvc, remote_version_aware):
106106
(remote_version_aware / "file").write_text("modified")
107107
assert dvc.status().get("file.dvc") == [
108108
{"changed deps": {"remote://upstream/file": "update available"}},
109+
{"changed outs": {"file": "not in cache"}},
109110
]
110111
dvc.update(str(tmp_dir / "file.dvc"))
111112
assert (tmp_dir / "file").read_text() == "modified"
@@ -137,6 +138,7 @@ def test_import_dir(self, tmp_dir, dvc, remote_version_aware):
137138
(remote_version_aware / "data_dir" / "new_file").write_text("new")
138139
assert dvc.status().get("data_dir.dvc") == [
139140
{"changed deps": {"remote://upstream/data_dir": "modified"}},
141+
{"changed outs": {"data_dir": "not in cache"}},
140142
]
141143
dvc.update(str(tmp_dir / "data_dir.dvc"))
142144
assert (tmp_dir / "data_dir" / "subdir" / "file").read_text() == "modified"

0 commit comments

Comments
 (0)