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

Function add

dvc/repo/add.py:192–241  ·  view source on GitHub ↗
(
    repo: "Repo",
    targets: Union["StrOrBytesPath", Iterator["StrOrBytesPath"]],
    no_commit: bool = False,
    glob: bool = False,
    out: Optional[str] = None,
    remote: Optional[str] = None,
    to_remote: bool = False,
    remote_jobs: Optional[int] = None,
    force: bool = False,
    relink: bool = True,
)

Source from the content-addressed store, hash-verified

190@locked
191@scm_context
192def add(
193 repo: "Repo",
194 targets: Union["StrOrBytesPath", Iterator["StrOrBytesPath"]],
195 no_commit: bool = False,
196 glob: bool = False,
197 out: Optional[str] = None,
198 remote: Optional[str] = None,
199 to_remote: bool = False,
200 remote_jobs: Optional[int] = None,
201 force: bool = False,
202 relink: bool = True,
203) -> list["Stage"]:
204 add_targets = find_targets(targets, glob=glob)
205 if not add_targets:
206 return []
207
208 stages_with_targets = {
209 target: get_or_create_stage(
210 repo,
211 target,
212 out=out,
213 to_remote=to_remote,
214 force=force,
215 )
216 for target in add_targets
217 }
218
219 stages = [stage for stage, _ in stages_with_targets.values()]
220 msg = "Collecting stages from the workspace"
221 with translate_graph_error(stages), ui.status(msg) as st:
222 repo.check_graph(stages=stages, callback=lambda: st.update("Checking graph"))
223
224 if to_remote or out:
225 assert len(stages_with_targets) == 1, "multiple targets are unsupported"
226 (source, (stage, _)) = next(iter(stages_with_targets.items()))
227 _add_transfer(stage, source, remote, to_remote, jobs=remote_jobs, force=force)
228 return [stage]
229
230 with warn_link_failures() as link_failures:
231 for source, (stage, output_exists) in progress_iter(stages_with_targets):
232 try:
233 _add(
234 stage,
235 source if output_exists else None,
236 no_commit=no_commit,
237 relink=relink,
238 )
239 except CacheLinkError:
240 link_failures.append(stage.relpath)
241 return stages

Callers

nothing calls this directly

Calls 12

find_targetsFunction · 0.85
get_or_create_stageFunction · 0.85
translate_graph_errorFunction · 0.85
_add_transferFunction · 0.85
warn_link_failuresFunction · 0.85
progress_iterFunction · 0.85
_addFunction · 0.85
itemsMethod · 0.80
appendMethod · 0.80
statusMethod · 0.45
check_graphMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected