-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
worktree add: preserve version metadata for unmodified files on dvc add
#8595
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,12 +113,11 @@ def restore_fields(stage): | |
stage.meta = old.meta | ||
stage.desc = old.desc | ||
|
||
old_fields = { | ||
out.def_path: (out.annot, out.remote, out.can_push) for out in old.outs | ||
} | ||
old_outs = {out.def_path: out for out in old.outs} | ||
for out in stage.outs: | ||
if out_fields := old_fields.get(out.def_path, None): | ||
out.annot, out.remote, out.can_push = out_fields | ||
old_out = old_outs.get(out.def_path, None) | ||
if old_out is not None: | ||
out.restore_fields(old_out) | ||
|
||
|
||
class Stage(params.StageParams): | ||
|
@@ -464,10 +463,12 @@ def compute_md5(self): | |
logger.debug("Computed %s md5: '%s'", self, m) | ||
return m | ||
|
||
def save(self, allow_missing=False): | ||
def save(self, allow_missing: bool = False, merge_versioned: bool = False): | ||
self.save_deps(allow_missing=allow_missing) | ||
|
||
self.save_outs(allow_missing=allow_missing) | ||
self.save_outs( | ||
allow_missing=allow_missing, merge_versioned=merge_versioned | ||
) | ||
self.md5 = self.compute_md5() | ||
|
||
self.repo.stage_cache.save(self) | ||
|
@@ -482,15 +483,40 @@ def save_deps(self, allow_missing=False): | |
if not allow_missing: | ||
raise | ||
|
||
def save_outs(self, allow_missing=False): | ||
def save_outs( | ||
self, allow_missing: bool = False, merge_versioned: bool = False | ||
): | ||
from dvc.output import OutputDoesNotExistError | ||
|
||
from .exceptions import StageFileDoesNotExistError, StageNotFound | ||
|
||
if merge_versioned: | ||
try: | ||
old = self.reload() | ||
Comment on lines
+493
to
+495
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This extra The problem is that we can't do this in the same place we are doing But for the version metadata merge, we cannot do it until after the new outs have been |
||
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 self.outs: | ||
try: | ||
out.save() | ||
except OutputDoesNotExistError: | ||
if not (allow_missing or out.checkpoint): | ||
raise | ||
if merge_versioned: | ||
old_out = old_outs.get(out.def_path) | ||
if old_out is not None: | ||
out.merge_version_meta(old_out) | ||
|
||
def ignore_outs(self): | ||
for out in self.outs: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Continually adding fields to these tuples was not ideal as far as maintaining it goes, is clearer/easier to update in the future by just keeping these assignments in Output