From dbfcf424d6149677524a06330981aba80dd2eb24 Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Thu, 23 Jan 2025 10:14:54 +0000 Subject: [PATCH] radicle: add Op::manifest_of Add a helper method `Op::manifest_of`, to allow the caller to inspect the `Manifest` of the entry. This can be used to avoid attempting to call `Op:load` with a manifest that would not match the expected `Action`s of the `Op`. --- crates/radicle/src/cob/op.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/crates/radicle/src/cob/op.rs b/crates/radicle/src/cob/op.rs index db34e53b..80804f52 100644 --- a/crates/radicle/src/cob/op.rs +++ b/crates/radicle/src/cob/op.rs @@ -3,10 +3,10 @@ use radicle_cob::Manifest; use serde::Serialize; use thiserror::Error; -use radicle_cob as cob; use radicle_cob::history::{Entry, EntryId}; use radicle_crypto::PublicKey; +use crate::cob; use crate::cob::Timestamp; use crate::identity::DocAt; use crate::storage::ReadRepository; @@ -24,6 +24,14 @@ pub enum OpEncodingError { Git(#[from] git2::Error), } +#[derive(Error, Debug)] +#[error("failed to load manifest of '{object}': {err}")] +pub struct ManifestError { + object: git::Oid, + #[source] + err: Box, +} + /// Error loading an `Op` from storage. #[derive(Error, Debug)] pub enum LoadError { @@ -112,6 +120,20 @@ impl Op { } } + pub fn manifest_of(store: &S, id: &git::Oid) -> Result + where + S: cob::change::Storage< + ObjectId = git::Oid, + Parent = git::Oid, + Signatures = crypto::ssh::ExtendedSignature, + >, + { + store.manifest_of(id).map_err(|err| ManifestError { + object: *id, + err: Box::new(err), + }) + } + /// Get the `Op` identified by the `id` in the provided `store`. pub fn load(store: &S, id: git::Oid) -> Result where