From 027de89cdb93f9f08e46ab76ab38c62c4005724a Mon Sep 17 00:00:00 2001 From: Lorenz Leutgeb Date: Thu, 16 Jul 2026 19:15:08 +0200 Subject: [PATCH] node/worker/garbage: Clean up Clippy reports dead code on all variants except `Hours` on `Expiry`, since the type is defined in a binary crate. Allow dead code here, just in case we want to use the other variants in the future. They are not a maintenance burden, as the implementation is simple and does not see much change. Slightly refactor: - `impl std::fmt::Display for Expiry` to look cleaner. - `fn collect` to borrow `RepoId`, since it only needs a borrow, and a a borrow of `Expiry` to spare a copy at the only call site. - The constant for the default value of `Expiry` to be associated with the type `Expiry`. Remove a remark about the default value of `Expiry` from `FetchConfig`, as the default value is not a concern there, but rather wherever `Expiry` is initialized. --- crates/radicle-node/src/worker.rs | 5 ++- crates/radicle-node/src/worker/garbage.rs | 39 +++++++++++++++-------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/crates/radicle-node/src/worker.rs b/crates/radicle-node/src/worker.rs index 5b578f01c..aa77be5d5 100644 --- a/crates/radicle-node/src/worker.rs +++ b/crates/radicle-node/src/worker.rs @@ -61,8 +61,7 @@ pub struct TaskResult { pub struct FetchConfig { /// Public key of the local peer. pub local: crypto::PublicKey, - /// Configuration for `git gc` garbage collection. Defaults to `1 - /// hour ago`. + /// Configuration for `git gc` garbage collection. pub expiry: garbage::Expiry, } @@ -267,7 +266,7 @@ impl Worker { refs_at, )?; - if let Err(e) = garbage::collect(&self.storage, rid, *expiry) { + if let Err(e) = garbage::collect(&self.storage, &rid, expiry) { // N.b. ensure that `git gc` works in debug mode. debug_assert!(false, "`git gc` failed: {e}"); diff --git a/crates/radicle-node/src/worker/garbage.rs b/crates/radicle-node/src/worker/garbage.rs index d8e3ea018..43929b59d 100644 --- a/crates/radicle-node/src/worker/garbage.rs +++ b/crates/radicle-node/src/worker/garbage.rs @@ -4,40 +4,53 @@ use std::{fmt, io}; use radicle::prelude::RepoId; use radicle::storage::ReadStorage; -/// Default expiry time for objects. -pub const EXPIRY_DEFAULT: Expiry = Expiry::Hours(1); - /// Expiry of objects for garbage collector. #[derive(Copy, Clone, Debug, PartialEq, Eq)] pub enum Expiry { + #[allow(dead_code)] Now, + #[allow(dead_code)] Seconds(usize), Hours(usize), + #[allow(dead_code)] Days(usize), + #[allow(dead_code)] Weeks(usize), } +impl Expiry { + const DEFAULT: Self = Expiry::Hours(1); +} + impl Default for Expiry { fn default() -> Self { - EXPIRY_DEFAULT + Self::DEFAULT } } impl fmt::Display for Expiry { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Self::Now => f.write_str("now"), - Self::Seconds(s) => write!(f, "{s}.seconds.ago"), - Self::Hours(s) => write!(f, "{s}.hours.ago"), - Self::Days(s) => write!(f, "{s}.days.ago"), - Self::Weeks(s) => write!(f, "{s}.weeks.ago"), - } + #[rustfmt::skip] + let (quantity, unit) = match self { + Self::Now => return f.write_str("now"), + + Self::Seconds(quantity) => (quantity, "seconds"), + Self::Hours (quantity) => (quantity, "hours" ), + Self::Days (quantity) => (quantity, "days" ), + Self::Weeks (quantity) => (quantity, "weeks" ), + }; + + write!(f, "{quantity}.{unit}.ago") } } /// Run Git garbage collector. -pub fn collect(storage: &impl ReadStorage, rid: RepoId, expiry: Expiry) -> io::Result { - let git_dir = storage.path_of(&rid); +pub fn collect( + storage: &impl ReadStorage, + rid: &RepoId, + expiry: &Expiry, +) -> io::Result { + let git_dir = storage.path_of(rid); let mut gc = Command::new("git"); gc.current_dir(git_dir) .env_clear()