Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
fetch: Make `RemoteRefs` an alias
Lorenz Leutgeb committed 1 month ago
commit 748ddade2feb6f00245c2ba878bd54842dc57506
parent 35d71f5
3 files changed +16 -70
modified 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<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()
-
    }
-
}
+
pub(crate) type RemoteRefs = BTreeMap<
+
    PublicKey,
+
    Result<Option<SignedRefsAt>, radicle::storage::refs::sigrefs::read::error::Read>,
+
>;
modified crates/radicle-fetch/src/stage.rs
@@ -518,7 +518,7 @@ impl ProtocolStage for DataRefs {
    ) -> Result<WantsHaves, error::WantsHaves> {
        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;
            };
modified crates/radicle-fetch/src/state.rs
@@ -300,7 +300,7 @@ impl FetchState {
        R: AsRef<Repository>,
        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;