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

Method add

dvc/output.py:1362–1449  ·  view source on GitHub ↗
(  # noqa: C901
        self, path: Optional[str] = None, no_commit: bool = False, relink: bool = True
    )

Source from the content-addressed store, hash-verified

1360 return meta, new
1361
1362 def add( # noqa: C901
1363 self, path: Optional[str] = None, no_commit: bool = False, relink: bool = True
1364 ) -> Optional["HashFile"]:
1365 path = path or self.fs_path
1366 if self.hash_info and not self.is_dir_checksum and self.fs_path != path:
1367 raise DvcException(
1368 f"Cannot modify '{self}' which is being tracked as a file"
1369 )
1370
1371 assert self.repo
1372 self.update_legacy_hash_name()
1373 cache = self.cache if self.use_cache else self.local_cache
1374 assert isinstance(cache, HashFileDB)
1375
1376 new: HashFile
1377 try:
1378 assert self.hash_name
1379 staging, meta, obj = self._build(
1380 cache,
1381 path,
1382 self.fs,
1383 self.hash_name,
1384 ignore=self.dvcignore,
1385 dry_run=not self.use_cache,
1386 )
1387 except FileNotFoundError as exc:
1388 if not self.exists:
1389 raise self.DoesNotExistError(self) from exc
1390 if not self.is_dir_checksum:
1391 raise
1392
1393 meta, new = self.unstage(path)
1394 staging, obj = None, None
1395 else:
1396 assert obj
1397 assert staging
1398 if self.fs_path != path:
1399 meta, new = self.apply(path, obj, meta)
1400 add_update_tree(staging, new)
1401 else:
1402 new = obj
1403
1404 self.obj = new
1405 self.hash_info = self.obj.hash_info
1406 self.meta = meta
1407 self.files = None
1408 self.ignore()
1409
1410 if no_commit or not self.use_cache:
1411 return obj
1412
1413 if isinstance(new, Tree):
1414 add_update_tree(cache, new)
1415
1416 if not obj:
1417 return obj
1418
1419 assert staging

Callers 15

_check_blockersFunction · 0.45
add_no_submodulesFunction · 0.45
_named_obj_idsMethod · 0.45
mergeMethod · 0.45
_split_legacy_hash_infosFunction · 0.45
dropnaMethod · 0.45
pytest_configureFunction · 0.45
runFunction · 0.45
makeFunction · 0.45
test_commit_recursiveFunction · 0.45

Calls 10

_buildMethod · 0.95
unstageMethod · 0.95
applyMethod · 0.95
ignoreMethod · 0.95
_checkoutMethod · 0.95
set_execMethod · 0.95
DvcExceptionClass · 0.90
TqdmCallbackClass · 0.85
CheckoutCallbackClass · 0.85

Tested by 15

pytest_configureFunction · 0.36
runFunction · 0.36
makeFunction · 0.36
test_commit_recursiveFunction · 0.36
test_commit_forceFunction · 0.36
test_commit_with_depsFunction · 0.36
test_commit_changed_md5Function · 0.36
test_commit_granular_dirFunction · 0.36