From 748ddade2feb6f00245c2ba878bd54842dc57506 Mon Sep 17 00:00:00 2001 From: Lorenz Leutgeb Date: Tue, 17 Mar 2026 16:15:04 +0100 Subject: [PATCH] fetch: Make `RemoteRefs` an alias --- crates/radicle-fetch/src/sigrefs.rs | 63 +++-------------------------- crates/radicle-fetch/src/stage.rs | 2 +- crates/radicle-fetch/src/state.rs | 21 +++++----- 3 files changed, 16 insertions(+), 70 deletions(-) diff --git a/crates/radicle-fetch/src/sigrefs.rs b/crates/radicle-fetch/src/sigrefs.rs index 3ce121c1..71af28de 100644 --- a/crates/radicle-fetch/src/sigrefs.rs +++ b/crates/radicle-fetch/src/sigrefs.rs @@ -1,13 +1,10 @@ -use std::collections::{BTreeMap, BTreeSet}; +use std::collections::BTreeMap; use std::ops::Not as _; -use radicle::storage::git::Repository; pub use radicle::storage::refs::SignedRefsAt; pub use radicle::storage::{git::Validation, Validations}; use radicle::{crypto::PublicKey, storage::ValidateRepository}; -use crate::state::Cached; - pub mod error { use radicle::crypto::PublicKey; use thiserror::Error; @@ -34,57 +31,7 @@ pub(crate) fn validate( } /// The sigrefs found for each remote. -/// -/// Construct using [`RemoteRefs::load`]. -#[derive(Debug, Default)] -pub struct RemoteRefs( - pub(super) BTreeMap< - PublicKey, - Result, radicle::storage::refs::sigrefs::read::error::Read>, - >, -); - -impl RemoteRefs { - /// Load the sigrefs for each remote in `remotes`. - pub(crate) fn load<'a, R, S>( - cached: &Cached, - remotes: impl Iterator, - ) -> Self - where - R: AsRef, - { - Self( - remotes - .map(|remote| (*remote, cached.load(remote))) - .collect(), - ) - } - - pub(crate) fn len(&self) -> usize { - self.0.len() - } - - pub(crate) fn into_inner( - self, - ) -> BTreeMap< - PublicKey, - Result, radicle::storage::refs::sigrefs::read::error::Read>, - > { - self.0 - } -} - -impl<'a> IntoIterator for &'a RemoteRefs { - type Item = <&'a BTreeMap< - PublicKey, - Result, radicle::storage::refs::sigrefs::read::error::Read>, - > as IntoIterator>::Item; - type IntoIter = <&'a BTreeMap< - PublicKey, - Result, radicle::storage::refs::sigrefs::read::error::Read>, - > as IntoIterator>::IntoIter; - - fn into_iter(self) -> Self::IntoIter { - self.0.iter() - } -} +pub(crate) type RemoteRefs = BTreeMap< + PublicKey, + Result, radicle::storage::refs::sigrefs::read::error::Read>, +>; diff --git a/crates/radicle-fetch/src/stage.rs b/crates/radicle-fetch/src/stage.rs index 183ed609..53a93c6e 100644 --- a/crates/radicle-fetch/src/stage.rs +++ b/crates/radicle-fetch/src/stage.rs @@ -518,7 +518,7 @@ impl ProtocolStage for DataRefs { ) -> Result { let mut wants_haves = WantsHaves::default(); - for (remote, result) in self.remotes.into_iter() { + for (remote, result) in self.remotes.iter() { let Ok(Some(refs)) = result else { continue; }; diff --git a/crates/radicle-fetch/src/state.rs b/crates/radicle-fetch/src/state.rs index d540812c..209de59b 100644 --- a/crates/radicle-fetch/src/state.rs +++ b/crates/radicle-fetch/src/state.rs @@ -300,7 +300,7 @@ impl FetchState { R: AsRef, S: transport::ConnectionStream, { - match refs_at { + let remotes: Vec<_> = match refs_at { Some(refs_at) => { let sigrefs_at = stage::SigrefsAt { remote, @@ -311,10 +311,8 @@ impl FetchState { }; log::trace!("{sigrefs_at:?}"); self.run_stage(handle, handshake, &sigrefs_at)?; - let remotes = refs_at.iter().map(|r| &r.remote); - let signed_refs = sigrefs::RemoteRefs::load(&self.as_cached(handle), remotes); - Ok(signed_refs) + refs_at.iter().map(|r| &r.remote).cloned().collect() } None => { let followed = handle.allowed(); @@ -330,13 +328,14 @@ impl FetchState { log::trace!("{special_refs:?}"); let fetched = self.run_stage(handle, handshake, &special_refs)?; - let signed_refs = sigrefs::RemoteRefs::load( - &self.as_cached(handle), - fetched.iter().chain(delegates.iter()), - ); - Ok(signed_refs) + fetched.iter().chain(delegates.iter()).cloned().collect() } - } + }; + + Ok(remotes + .into_iter() + .map(|remote| (remote, self.as_cached(handle).load(&remote))) + .collect()) } /// The finalization of the protocol exchange is as follows: @@ -467,7 +466,7 @@ impl FetchState { // TODO(finto): this might read better if it got its own // private function. - for (remote, refs) in signed_refs.into_inner() { + for (remote, refs) in signed_refs { if handle.is_blocked(&remote) { log::trace!("Skipping blocked remote {remote}"); continue;