diff --git a/radicle/src/storage/refs.rs b/radicle/src/storage/refs.rs index 47cd600e..7ce78cd0 100644 --- a/radicle/src/storage/refs.rs +++ b/radicle/src/storage/refs.rs @@ -364,6 +364,46 @@ impl Deref for SignedRefs { } } +/// Verified [`SignedRefs`] that keeps track of their content address +/// [`Oid`]. +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct SignedRefsAt { + pub sigrefs: SignedRefs, + pub at: Oid, +} + +impl SignedRefsAt { + /// Load the [`SignedRefs`] found under `remote`'s [`SIGREFS_BRANCH`]. + /// + /// This will return `None` if the branch was not found, all other + /// errors are returned. + pub fn load(remote: RemoteId, repo: &S) -> Result, Error> + where + S: ReadRepository, + { + let at = repo.reference_oid(&remote, &SIGREFS_BRANCH)?; + Self::load_at(at, remote, repo).map(Some) + } + + pub fn load_at(at: Oid, remote: RemoteId, repo: &S) -> Result + where + S: storage::ReadRepository, + { + Ok(Self { + sigrefs: SignedRefs::load_at(at, remote, repo)?, + at, + }) + } +} + +impl Deref for SignedRefsAt { + type Target = SignedRefs; + + fn deref(&self) -> &Self::Target { + &self.sigrefs + } +} + pub mod canonical { use super::*;