Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stage.save: Remove merge_versioned option. #8873

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dvc/repo/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def add( # noqa: C901
stage.transfer(source, to_remote=to_remote, odb=odb, **kwargs)
else:
try:
stage.save(merge_versioned=True)
stage.save()
if not no_commit:
stage.commit()
except CacheLinkError:
Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/worktree.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def outs_filter(out: "Output") -> bool:
)
continue
_fetch_out_changes(out, local_index, remote_index, remote)
stage.save(merge_versioned=True)
stage.save()
for out in stage.outs:
_update_out_meta(out, remote_index)
stage.dump(with_files=True, update_pipeline=False)
Expand Down
43 changes: 17 additions & 26 deletions dvc/stage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,17 +486,11 @@ def compute_md5(self) -> Optional[str]:
logger.debug("Computed %s md5: '%s'", self, m)
return m

def save(
self,
allow_missing: bool = False,
merge_versioned: bool = False,
run_cache: bool = True,
):
def save(self, allow_missing: bool = False, run_cache: bool = True):
self.save_deps(allow_missing=allow_missing)

self.save_outs(
allow_missing=allow_missing, merge_versioned=merge_versioned
)
self.save_outs(allow_missing=allow_missing)

self.md5 = self.compute_md5()

if run_cache:
Expand All @@ -512,29 +506,26 @@ def save_deps(self, allow_missing=False):
if not allow_missing:
raise

def save_outs(
self, allow_missing: bool = False, merge_versioned: bool = False
):
def save_outs(self, allow_missing: bool = False):
from dvc.output import OutputDoesNotExistError

from .exceptions import StageFileDoesNotExistError, StageNotFound

if merge_versioned:
try:
old = self.reload()
old_outs = {out.def_path: out for out in old.outs}
merge_versioned = any(
(
out.files is not None
or (
out.meta is not None
and out.meta.version_id is not None
)
try:
old = self.reload()
old_outs = {out.def_path: out for out in old.outs}
merge_versioned = any(
(
out.files is not None
or (
out.meta is not None
and out.meta.version_id is not None
)
for out in old_outs.values()
)
except (StageFileDoesNotExistError, StageNotFound):
merge_versioned = False
for out in old_outs.values()
)
except (StageFileDoesNotExistError, StageNotFound):
merge_versioned = False

for out in self.outs:
try:
Expand Down
58 changes: 58 additions & 0 deletions tests/func/test_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,61 @@ def test_imported_entries_unchanged(tmp_dir, dvc, erepo_dir):
stage = dvc.imp(os.fspath(erepo_dir), "file")

assert stage.changed_entries() == ([], [], None)


def test_commit_updates_to_cloud_versioning_dir(tmp_dir, dvc):
data_dvc = tmp_dir / "data.dvc"
data_dvc.dump(
{
"outs": [
{
"path": "data",
"files": [
{
"size": 3,
"version_id": "WYRG4BglP7pD.gEoJP6a4AqOhl.FRA.h",
"etag": "acbd18db4cc2f85cedef654fccc4a4d8",
"md5": "acbd18db4cc2f85cedef654fccc4a4d8",
"relpath": "bar",
},
{
"size": 3,
"version_id": "0vL53tFVY5vVAoJ4HG2jCS1mEcohDPE0",
"etag": "acbd18db4cc2f85cedef654fccc4a4d8",
"md5": "acbd18db4cc2f85cedef654fccc4a4d8",
"relpath": "foo",
},
],
}
]
}
)

data = tmp_dir / "data"
data.mkdir()
(data / "foo").write_text("foo")
(data / "bar").write_text("bar2")

dvc.commit("data", force=True)

assert (tmp_dir / "data.dvc").parse() == {
"outs": [
{
"path": "data",
"files": [
{
"size": 4,
"md5": "224e2539f52203eb33728acd228b4432",
"relpath": "bar",
},
{
"size": 3,
"version_id": "0vL53tFVY5vVAoJ4HG2jCS1mEcohDPE0",
"etag": "acbd18db4cc2f85cedef654fccc4a4d8",
"md5": "acbd18db4cc2f85cedef654fccc4a4d8",
"relpath": "foo",
},
],
}
]
}