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.
This commit is contained in:
Lorenz Leutgeb
2026-07-17 11:30:26 +02:00
parent 188f3041d6
commit 027de89cdb
2 changed files with 28 additions and 16 deletions
+2 -3
View File
@@ -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}");
+26 -13
View File
@@ -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<ExitStatus> {
let git_dir = storage.path_of(&rid);
pub fn collect(
storage: &impl ReadStorage,
rid: &RepoId,
expiry: &Expiry,
) -> io::Result<ExitStatus> {
let git_dir = storage.path_of(rid);
let mut gc = Command::new("git");
gc.current_dir(git_dir)
.env_clear()