Skip to content

Commit e9e7af5

Browse files
committed
cache migrate: include dvc.lock dependencies in --dvc-files
1 parent e18fd34 commit e9e7af5

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

dvc/repo/commit.py

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import TYPE_CHECKING
1+
from typing import TYPE_CHECKING, Set
22

33
from dvc import prompt
44

@@ -7,6 +7,7 @@
77

88
if TYPE_CHECKING:
99
from . import Repo
10+
from .index import IndexView
1011

1112

1213
def _prepare_message(stage, changes):
@@ -88,14 +89,7 @@ def commit_2_to_3(repo: "Repo", dry: bool = False):
8889
outs_filter=lambda o: o.hash_name == "md5-dos2unix",
8990
recursive=True,
9091
)
91-
migrated = set()
92-
for out in view.outs:
93-
dvcfile = out.stage.dvcfile.relpath
94-
if isinstance(out.stage.dvcfile, ProjectFile):
95-
lockfile = out.stage.dvcfile._lockfile.relpath
96-
migrated.add(f"{dvcfile} ({lockfile})")
97-
else:
98-
migrated.add(dvcfile)
92+
migrated = _migrateable_dvcfiles(view)
9993
if not migrated:
10094
ui.write("No DVC files in the repo to migrate to the 3.0 format.")
10195
return
@@ -110,11 +104,41 @@ def commit_2_to_3(repo: "Repo", dry: bool = False):
110104
for out in stage.filter_outs(filter_info)
111105
if outs_filter is not None and outs_filter(out)
112106
}
107+
modified = False
113108
if outs:
114109
for out in outs:
115110
out.update_legacy_hash_name(force=True)
111+
modified = True
112+
deps = {dep for dep in stage.deps if not stage.is_import and dep.is_in_repo}
113+
if deps:
114+
for dep in deps:
115+
dep.update_legacy_hash_name(force=True)
116+
modified = True
117+
if modified:
116118
stage.save(allow_missing=True)
117119
stage.commit(allow_missing=True, relink=True)
118120
if not isinstance(stage.dvcfile, ProjectFile):
119121
ui.write(f"Updating DVC file '{stage.dvcfile.relpath}'")
120122
stage.dump(update_pipeline=False)
123+
124+
125+
def _migrateable_dvcfiles(view: "IndexView") -> Set[str]:
126+
from dvc.dvcfile import ProjectFile
127+
128+
migrated = set()
129+
for stage, filter_info in view._stage_infos:
130+
outs_filter = view._outs_filter
131+
dvcfile = stage.dvcfile.relpath
132+
assert outs_filter
133+
if any(outs_filter(out) for out in stage.filter_outs(filter_info)) or (
134+
not stage.is_import
135+
and any(
136+
dep.is_in_repo and dep.hash_name == "md5-dos2unix" for dep in stage.deps
137+
)
138+
):
139+
if isinstance(stage.dvcfile, ProjectFile):
140+
lockfile = stage.dvcfile._lockfile.relpath
141+
migrated.add(f"{dvcfile} ({lockfile})")
142+
else:
143+
migrated.add(dvcfile)
144+
return migrated

0 commit comments

Comments
 (0)