fetch: Make `RemoteRefs` an alias

This commit is contained in:
Lorenz Leutgeb 2026-03-17 16:15:04 +01:00
parent 35d71f5909
commit 748ddade2f
No known key found for this signature in database
3 changed files with 16 additions and 70 deletions

View File

@ -1,13 +1,10 @@
use std::collections::{BTreeMap, BTreeSet}; use std::collections::BTreeMap;
use std::ops::Not as _; use std::ops::Not as _;
use radicle::storage::git::Repository;
pub use radicle::storage::refs::SignedRefsAt; pub use radicle::storage::refs::SignedRefsAt;
pub use radicle::storage::{git::Validation, Validations}; pub use radicle::storage::{git::Validation, Validations};
use radicle::{crypto::PublicKey, storage::ValidateRepository}; use radicle::{crypto::PublicKey, storage::ValidateRepository};
use crate::state::Cached;
pub mod error { pub mod error {
use radicle::crypto::PublicKey; use radicle::crypto::PublicKey;
use thiserror::Error; use thiserror::Error;
@ -34,57 +31,7 @@ pub(crate) fn validate(
} }
/// The sigrefs found for each remote. /// The sigrefs found for each remote.
/// pub(crate) type RemoteRefs = BTreeMap<
/// Construct using [`RemoteRefs::load`]. PublicKey,
#[derive(Debug, Default)] Result<Option<SignedRefsAt>, radicle::storage::refs::sigrefs::read::error::Read>,
pub struct RemoteRefs( >;
pub(super) BTreeMap<
PublicKey,
Result<Option<SignedRefsAt>, 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<R, S>,
remotes: impl Iterator<Item = &'a PublicKey>,
) -> Self
where
R: AsRef<Repository>,
{
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<Option<SignedRefsAt>, radicle::storage::refs::sigrefs::read::error::Read>,
> {
self.0
}
}
impl<'a> IntoIterator for &'a RemoteRefs {
type Item = <&'a BTreeMap<
PublicKey,
Result<Option<SignedRefsAt>, radicle::storage::refs::sigrefs::read::error::Read>,
> as IntoIterator>::Item;
type IntoIter = <&'a BTreeMap<
PublicKey,
Result<Option<SignedRefsAt>, radicle::storage::refs::sigrefs::read::error::Read>,
> as IntoIterator>::IntoIter;
fn into_iter(self) -> Self::IntoIter {
self.0.iter()
}
}

View File

@ -518,7 +518,7 @@ impl ProtocolStage for DataRefs {
) -> Result<WantsHaves, error::WantsHaves> { ) -> Result<WantsHaves, error::WantsHaves> {
let mut wants_haves = WantsHaves::default(); 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 { let Ok(Some(refs)) = result else {
continue; continue;
}; };

View File

@ -300,7 +300,7 @@ impl FetchState {
R: AsRef<Repository>, R: AsRef<Repository>,
S: transport::ConnectionStream, S: transport::ConnectionStream,
{ {
match refs_at { let remotes: Vec<_> = match refs_at {
Some(refs_at) => { Some(refs_at) => {
let sigrefs_at = stage::SigrefsAt { let sigrefs_at = stage::SigrefsAt {
remote, remote,
@ -311,10 +311,8 @@ impl FetchState {
}; };
log::trace!("{sigrefs_at:?}"); log::trace!("{sigrefs_at:?}");
self.run_stage(handle, handshake, &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); refs_at.iter().map(|r| &r.remote).cloned().collect()
Ok(signed_refs)
} }
None => { None => {
let followed = handle.allowed(); let followed = handle.allowed();
@ -330,13 +328,14 @@ impl FetchState {
log::trace!("{special_refs:?}"); log::trace!("{special_refs:?}");
let fetched = self.run_stage(handle, handshake, &special_refs)?; let fetched = self.run_stage(handle, handshake, &special_refs)?;
let signed_refs = sigrefs::RemoteRefs::load( fetched.iter().chain(delegates.iter()).cloned().collect()
&self.as_cached(handle),
fetched.iter().chain(delegates.iter()),
);
Ok(signed_refs)
} }
} };
Ok(remotes
.into_iter()
.map(|remote| (remote, self.as_cached(handle).load(&remote)))
.collect())
} }
/// The finalization of the protocol exchange is as follows: /// 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 // TODO(finto): this might read better if it got its own
// private function. // private function.
for (remote, refs) in signed_refs.into_inner() { for (remote, refs) in signed_refs {
if handle.is_blocked(&remote) { if handle.is_blocked(&remote) {
log::trace!("Skipping blocked remote {remote}"); log::trace!("Skipping blocked remote {remote}");
continue; continue;