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:
parent
86119473b7
commit
bfe8c5234f
|
|
@ -159,6 +159,12 @@ impl change::Storage for git2::Repository {
|
||||||
.collect::<Vec<_>>())
|
.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> {
|
fn load(&self, id: Self::ObjectId) -> Result<Entry, Self::LoadError> {
|
||||||
let commit = Commit::read(self, id.into())?;
|
let commit = Commit::read(self, id.into())?;
|
||||||
let timestamp = git2::Time::from(commit.committer().time).seconds() as u64;
|
let timestamp = git2::Time::from(commit.committer().time).seconds() as u64;
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,9 @@ pub trait Storage {
|
||||||
|
|
||||||
/// Returns the parents of the object with the specified ID.
|
/// Returns the parents of the object with the specified ID.
|
||||||
fn parents_of(&self, id: &Oid) -> Result<Vec<Oid>, Self::LoadError>;
|
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.
|
/// Change template, used to create a new change.
|
||||||
|
|
|
||||||
|
|
@ -101,6 +101,10 @@ impl change::Storage for Storage {
|
||||||
.map(git_ext::Oid::from)
|
.map(git_ext::Oid::from)
|
||||||
.collect::<Vec<_>>())
|
.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 {
|
impl object::Storage for Storage {
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,10 @@ impl change::Storage for Repository {
|
||||||
fn parents_of(&self, id: &Oid) -> Result<Vec<Oid>, Self::LoadError> {
|
fn parents_of(&self, id: &Oid) -> Result<Vec<Oid>, Self::LoadError> {
|
||||||
self.backend.parents_of(id)
|
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 {
|
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> {
|
fn parents_of(&self, id: &Oid) -> Result<Vec<Oid>, Self::LoadError> {
|
||||||
self.repo.raw().parents_of(id)
|
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>
|
impl<R> SignRepository for DraftStore<'_, R>
|
||||||
|
|
|
||||||
|
|
@ -440,4 +440,8 @@ impl radicle_cob::change::Storage for MockRepository {
|
||||||
fn parents_of(&self, _id: &Oid) -> Result<Vec<Oid>, Self::LoadError> {
|
fn parents_of(&self, _id: &Oid) -> Result<Vec<Oid>, Self::LoadError> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn manifest_of(&self, _id: &Oid) -> Result<radicle_cob::Manifest, Self::LoadError> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue