Force-commit all legacy outputs to use DVC 3.0 hashes.
(repo: "Repo", dry: bool = False)
| 90 | @locked |
| 91 | @scm_context |
| 92 | def 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 | |
| 135 | def _migrateable_dvcfiles(view: "IndexView") -> set[str]: |
no test coverage detected