Skip to content
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
21 changes: 12 additions & 9 deletions crates/core/src/commands/backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ pub struct ParentOptions {
#[cfg_attr(feature = "merge", merge(strategy = conflate::option::overwrite_none))]
pub group_by: Option<SnapshotGroupCriterion>,

/// Snapshot to use as parent
/// Snapshot to use as parent (can be specified multiple times; default: latest)
#[cfg_attr(
feature = "clap",
clap(long, value_name = "SNAPSHOT", conflicts_with = "force",)
clap(long = "parent", value_name = "SNAPSHOT", conflicts_with = "force",)
)]
#[cfg_attr(feature = "merge", merge(strategy = conflate::vec::append))]
pub parent: Vec<String>,
pub parents: Vec<String>,

/// Skip writing of snapshot if nothing changed w.r.t. the parent snapshot.
#[cfg_attr(feature = "clap", clap(long))]
Expand Down Expand Up @@ -99,11 +99,11 @@ impl ParentOptions {
snap: &SnapshotFile,
backup_stdin: bool,
) -> (Vec<SnapshotId>, Parent) {
let group = SnapshotGroup::from_snapshot(snap, self.group_by.unwrap_or_default());
let parent = if backup_stdin || self.force {
Vec::new()
} else if self.parent.is_empty() {
} else if self.parents.is_empty() {
// get suitable snapshot group from snapshot and opts.group_by. This is used to filter snapshots for the parent detection
let group = SnapshotGroup::from_snapshot(snap, self.group_by.unwrap_or_default());
SnapshotFile::latest(
repo.dbe(),
|snap| snap.has_group(&group),
Expand All @@ -113,10 +113,13 @@ impl ParentOptions {
.into_iter()
.collect()
} else {
self.parent
.iter()
.filter_map(|parent| SnapshotFile::from_id(repo.dbe(), parent).ok())
.collect()
SnapshotFile::from_strs(
repo.dbe(),
&self.parents,
|snap| snap.has_group(&group),
&repo.pb.progress_counter(""),
)
.unwrap_or_default()
};

let (parent_trees, parent_ids): (Vec<_>, _) = parent
Expand Down
2 changes: 1 addition & 1 deletion crates/core/tests/integration/backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fn test_backup_with_tar_gz_passes(
.tags([StringList::from_str("a,b")?])
.to_snapshot()?;
let opts =
opts.parent_opts(ParentOptions::default().parent(vec![second_snapshot.id.to_string()]));
opts.parent_opts(ParentOptions::default().parents(vec![second_snapshot.id.to_string()]));
let third_snapshot = repo.backup(&opts, paths, snap)?;

insta_snapshotfile_redaction.bind(|| {
Expand Down
Loading