radicle: Add SignedRefsAt type for signed refs

Introduce a SignedRefsAt type that combines a SignedRefs along with the Oid
it was loaded at.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
Fintan Halpenny 2023-08-31 11:02:42 +01:00 committed by cloudhead
parent d150938b38
commit 030419932e
No known key found for this signature in database
1 changed files with 40 additions and 0 deletions

View File

@ -364,6 +364,46 @@ impl<V> Deref for SignedRefs<V> {
}
}
/// Verified [`SignedRefs`] that keeps track of their content address
/// [`Oid`].
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SignedRefsAt {
pub sigrefs: SignedRefs<Verified>,
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<S>(remote: RemoteId, repo: &S) -> Result<Option<Self>, Error>
where
S: ReadRepository,
{
let at = repo.reference_oid(&remote, &SIGREFS_BRANCH)?;
Self::load_at(at, remote, repo).map(Some)
}
pub fn load_at<S>(at: Oid, remote: RemoteId, repo: &S) -> Result<Self, Error>
where
S: storage::ReadRepository,
{
Ok(Self {
sigrefs: SignedRefs::load_at(at, remote, repo)?,
at,
})
}
}
impl Deref for SignedRefsAt {
type Target = SignedRefs<Verified>;
fn deref(&self) -> &Self::Target {
&self.sigrefs
}
}
pub mod canonical {
use super::*;