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`.
This commit is contained in:
parent
bfe8c5234f
commit
dbfcf424d6
|
|
@ -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<dyn std::error::Error + Send + Sync + 'static>,
|
||||
}
|
||||
|
||||
/// Error loading an `Op` from storage.
|
||||
#[derive(Error, Debug)]
|
||||
pub enum LoadError {
|
||||
|
|
@ -112,6 +120,20 @@ impl<A> Op<A> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn manifest_of<S>(store: &S, id: &git::Oid) -> Result<Manifest, ManifestError>
|
||||
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<S>(store: &S, id: git::Oid) -> Result<Self, LoadError>
|
||||
where
|
||||
|
|
|
|||
Loading…
Reference in New Issue