cob: add method for loading entry manifest

Adds a helper for only loading the manifest of a COB entry. This allows callers
to inspect the manifest without loading the whole entry.
This commit is contained in:
Fintan Halpenny 2025-01-23 12:01:33 +00:00
parent 86119473b7
commit bfe8c5234f
5 changed files with 25 additions and 0 deletions

View File

@ -159,6 +159,12 @@ impl change::Storage for git2::Repository {
.collect::<Vec<_>>())
}
fn manifest_of(&self, id: &Oid) -> Result<crate::Manifest, Self::LoadError> {
let commit = self.find_commit(**id)?;
let tree = commit.tree()?;
load_manifest(self, &tree)
}
fn load(&self, id: Self::ObjectId) -> Result<Entry, Self::LoadError> {
let commit = Commit::read(self, id.into())?;
let timestamp = git2::Time::from(commit.committer().time).seconds() as u64;

View File

@ -38,6 +38,9 @@ pub trait Storage {
/// Returns the parents of the object with the specified ID.
fn parents_of(&self, id: &Oid) -> Result<Vec<Oid>, Self::LoadError>;
/// Load only the manifest of the change entry.
fn manifest_of(&self, id: &Oid) -> Result<Manifest, Self::LoadError>;
}
/// Change template, used to create a new change.

View File

@ -101,6 +101,10 @@ impl change::Storage for Storage {
.map(git_ext::Oid::from)
.collect::<Vec<_>>())
}
fn manifest_of(&self, id: &git_ext::Oid) -> Result<crate::Manifest, Self::LoadError> {
self.as_raw().manifest_of(id)
}
}
impl object::Storage for Storage {

View File

@ -82,6 +82,10 @@ impl change::Storage for Repository {
fn parents_of(&self, id: &Oid) -> Result<Vec<Oid>, Self::LoadError> {
self.backend.parents_of(id)
}
fn manifest_of(&self, id: &Oid) -> Result<cob::Manifest, Self::LoadError> {
self.backend.manifest_of(id)
}
}
impl cob::object::Storage for Repository {
@ -223,6 +227,10 @@ impl<R: storage::WriteRepository> change::Storage for DraftStore<'_, R> {
fn parents_of(&self, id: &Oid) -> Result<Vec<Oid>, Self::LoadError> {
self.repo.raw().parents_of(id)
}
fn manifest_of(&self, id: &Oid) -> Result<cob::Manifest, Self::LoadError> {
self.repo.raw().manifest_of(id)
}
}
impl<R> SignRepository for DraftStore<'_, R>

View File

@ -440,4 +440,8 @@ impl radicle_cob::change::Storage for MockRepository {
fn parents_of(&self, _id: &Oid) -> Result<Vec<Oid>, Self::LoadError> {
todo!()
}
fn manifest_of(&self, _id: &Oid) -> Result<radicle_cob::Manifest, Self::LoadError> {
todo!()
}
}