Skip to content

Commit

Permalink
add/commit: figure out whether to link or not
Browse files Browse the repository at this point in the history
  • Loading branch information
skshetry committed Aug 12, 2024
1 parent 43e6229 commit d704a19
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
11 changes: 6 additions & 5 deletions dvc/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,8 @@ def _build(
desc=f"Collecting files and computing hashes in {self}",
disable=no_progress_bar,
) as pb:
return build(*args, callback=pb.as_callback(), **kwargs)
kwargs["callback"] = pb.as_callback()
return build(*args, **kwargs)

def _get_hash_meta(self):
if self.use_cache:
Expand Down Expand Up @@ -751,9 +752,8 @@ def commit(self, filter_info=None, relink=True) -> None:
)
# NOTE: trying to use hardlink during transfer only if we will be
# relinking later
hardlink = relink
if granular:
obj = self._commit_granular_dir(filter_info, hardlink)
obj = self._commit_granular_dir(filter_info, hardlink=False)
else:
staging, _, obj = self._build(
self.cache,
Expand All @@ -771,7 +771,7 @@ def commit(self, filter_info=None, relink=True) -> None:
self.cache,
{obj.hash_info},
shallow=False,
hardlink=hardlink,
hardlink=False,
callback=cb,
)
if relink:
Expand Down Expand Up @@ -1403,7 +1403,7 @@ def add( # noqa: C901
staging,
self.cache,
{obj.hash_info},
hardlink=relink,
hardlink=False,
shallow=False,
callback=cb,
)
Expand All @@ -1421,6 +1421,7 @@ def add( # noqa: C901
state=self.repo.state,
prompt=prompt.confirm,
progress_callback=callback,
old=obj,
)
self.set_exec()
return obj
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ dependencies = [
"distro>=1.3",
"dpath<3,>=2.1.0",
"dulwich",
"dvc-data>=3.15,<3.16",
"dvc-data @ git+https://github.com/iterative/dvc-data.git@relinking-diff",
"dvc-http>=2.29.0",
"dvc-objects",
"dvc-render>=1.0.1,<2",
Expand Down
15 changes: 8 additions & 7 deletions tests/func/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,20 +305,20 @@ def test_should_update_state_entry_for_directory_after_add(mocker, dvc, tmp_dir)

ret = main(["add", "data"])
assert ret == 0
assert file_md5_counter.mock.call_count == 4
assert file_md5_counter.mock.call_count == 3

ret = main(["status"])
assert ret == 0
assert file_md5_counter.mock.call_count == 5
assert file_md5_counter.mock.call_count == 4

os.rename("data", "data.back")
ret = main(["checkout"])
assert ret == 0
assert file_md5_counter.mock.call_count == 6
assert file_md5_counter.mock.call_count == 5

ret = main(["status"])
assert ret == 0
assert file_md5_counter.mock.call_count == 7
assert file_md5_counter.mock.call_count == 6


def test_add_commit(tmp_dir, dvc):
Expand All @@ -339,15 +339,15 @@ def test_should_collect_dir_cache_only_once(mocker, tmp_dir, dvc):
counter = mocker.spy(dvc_data.hashfile.build, "_build_tree")
ret = main(["add", "data"])
assert ret == 0
assert counter.mock.call_count == 2
assert counter.mock.call_count == 1

ret = main(["status"])
assert ret == 0
assert counter.mock.call_count == 3
assert counter.mock.call_count == 2

ret = main(["status"])
assert ret == 0
assert counter.mock.call_count == 4
assert counter.mock.call_count == 3


def test_should_place_stage_in_data_dir_if_repository_below_symlink(
Expand Down Expand Up @@ -754,6 +754,7 @@ def test_add_file_in_symlink_dir(make_tmp_dir, tmp_dir, dvc):
def test_add_with_cache_link_error(tmp_dir, dvc, mocker, capsys):
tmp_dir.gen("foo", "foo")

dvc.cache.local.cache_types = ["symlink", "hardlink"]
mocker.patch("dvc_data.hashfile.checkout.test_links", return_value=[])
dvc.add("foo")
err = capsys.readouterr()[1]
Expand Down

0 comments on commit d704a19

Please sign in to comment.