MCPcopy
hub / github.com/treeverse/dvc / commit_2_to_3

Function commit_2_to_3

dvc/repo/commit.py:92–132  ·  view source on GitHub ↗

Force-commit all legacy outputs to use DVC 3.0 hashes.

(repo: "Repo", dry: bool = False)

Source from the content-addressed store, hash-verified

90@locked
91@scm_context
92def commit_2_to_3(repo: "Repo", dry: bool = False):
93 """Force-commit all legacy outputs to use DVC 3.0 hashes."""
94 from dvc.dvcfile import ProjectFile
95 from dvc.ui import ui
96
97 view = repo.index.targets_view(
98 targets=None,
99 outs_filter=lambda o: o.hash_name == "md5-dos2unix",
100 recursive=True,
101 )
102 migrated = _migrateable_dvcfiles(view)
103 if not migrated:
104 ui.write("No DVC files in the repo to migrate to the 3.0 format.")
105 return
106 if dry:
107 ui.write("Entries in following DVC files will be migrated to the 3.0 format:")
108 ui.write("\n".join(sorted(f"\t{file}" for file in migrated)))
109 return
110 for stage, filter_info in view._stage_infos:
111 outs_filter = view._outs_filter
112 outs = {
113 out
114 for out in stage.filter_outs(filter_info)
115 if outs_filter is not None and outs_filter(out)
116 }
117 modified = False
118 if outs:
119 for out in outs:
120 out.update_legacy_hash_name(force=True)
121 modified = True
122 deps = {dep for dep in stage.deps if not stage.is_import and dep.is_in_repo}
123 if deps:
124 for dep in deps:
125 dep.update_legacy_hash_name(force=True)
126 modified = True
127 if modified:
128 stage.save(allow_missing=True)
129 stage.commit(allow_missing=True, relink=True)
130 if not isinstance(stage.dvcfile, ProjectFile):
131 ui.write(f"Updating DVC file '{stage.dvcfile.relpath}'")
132 stage.dump(update_pipeline=False)
133
134
135def _migrateable_dvcfiles(view: "IndexView") -> set[str]:

Callers 1

runMethod · 0.90

Calls 10

_migrateable_dvcfilesFunction · 0.85
targets_viewMethod · 0.80
writeMethod · 0.80
joinMethod · 0.80
filter_outsMethod · 0.80
outs_filterFunction · 0.70
saveMethod · 0.45
commitMethod · 0.45
dumpMethod · 0.45

Tested by

no test coverage detected