Skip to content

Commit 2319ff3

Browse files
committed
Add a new flag to spfs clean to prune all tag namespaces
Now that the behavior is to only prune tags in the active tag namespace, this provides a way to prune all the tags in the repo regardless of what tag namespace they are in. Signed-off-by: J Robert Ray <[email protected]>
1 parent 2f675e4 commit 2319ff3

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

crates/spfs-cli/cmd-clean/src/cmd_clean.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ pub struct CmdClean {
5050
#[clap(long)]
5151
dry_run: bool,
5252

53+
/// Prune all tag namespaces. The default is to only prune tags in the
54+
/// active tag namespace.
55+
#[clap(long)]
56+
prune_all_tag_namespaces: bool,
57+
5358
/// Prune old tags that have the same target as a more recent version
5459
#[clap(long = "prune-repeated", group = "repo_data")]
5560
prune_repeated: bool,
@@ -165,6 +170,7 @@ impl CmdClean {
165170
.with_reporter(spfs::clean::ConsoleCleanReporter::default())
166171
.with_dry_run(self.dry_run)
167172
.with_required_age(chrono::Duration::minutes(15))
173+
.with_prune_all_tag_namespaces(self.prune_all_tag_namespaces)
168174
.with_prune_repeated_tags(prune_repeated_tags)
169175
.with_prune_tags_older_than(self.prune_if_older_than)
170176
.with_keep_tags_newer_than(self.keep_if_newer_than)

crates/spfs/src/clean.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ where
4646
attached: DashSet<encoding::Digest>,
4747
dry_run: bool,
4848
must_be_older_than: DateTime<Utc>,
49+
prune_all_tag_namespaces: bool,
4950
prune_repeated_tags: Option<NonZero<u64>>,
5051
prune_params: PruneParameters,
5152
remove_proxies_with_no_links: bool,
@@ -69,6 +70,7 @@ impl<'repo> Cleaner<'repo, SilentCleanReporter> {
6970
attached: Default::default(),
7071
dry_run: false,
7172
must_be_older_than: Utc::now(),
73+
prune_all_tag_namespaces: false,
7274
prune_repeated_tags: None,
7375
prune_params: Default::default(),
7476
remove_proxies_with_no_links: true,
@@ -89,6 +91,7 @@ where
8991
attached: self.attached,
9092
dry_run: self.dry_run,
9193
must_be_older_than: self.must_be_older_than,
94+
prune_all_tag_namespaces: self.prune_all_tag_namespaces,
9295
prune_repeated_tags: self.prune_repeated_tags,
9396
prune_params: self.prune_params,
9497
removal_concurrency: self.removal_concurrency,
@@ -155,6 +158,13 @@ where
155158
self
156159
}
157160

161+
/// When walking tags, whether to prune tags in all tag namespaces or only
162+
/// the tag namespace configured on the repository.
163+
pub fn with_prune_all_tag_namespaces(mut self, prune_all_tag_namespaces: bool) -> Self {
164+
self.prune_all_tag_namespaces = prune_all_tag_namespaces;
165+
self
166+
}
167+
158168
/// When walking the history of a tag, delete older entries
159169
/// that have the same target as a more recent one.
160170
pub fn with_prune_repeated_tags(mut self, prune_repeated_tags: Option<NonZero<u64>>) -> Self {
@@ -428,14 +438,15 @@ where
428438
// still alive, but if the repo passed to the Cleaner has a namespace
429439
// set on it then one would expect that only tags in that namespace are
430440
// pruned.
431-
let should_prune_this_namespace = match (
432-
tag_namespace_to_prune.as_ref(),
433-
tag_namespace_to_visit.as_deref(),
434-
) {
435-
(Some(prune), Some(visit)) if prune.as_ref() == visit => true,
436-
(None, None) => true,
437-
_ => false,
438-
};
441+
let should_prune_this_namespace = self.prune_all_tag_namespaces
442+
|| match (
443+
tag_namespace_to_prune.as_ref(),
444+
tag_namespace_to_visit.as_deref(),
445+
) {
446+
(Some(prune), Some(visit)) if prune.as_ref() == visit => true,
447+
(None, None) => true,
448+
_ => false,
449+
};
439450

440451
let history = self
441452
.repo

0 commit comments

Comments
 (0)