From bfe8c5234f79287d23ec1ace72d59dc1dcb54e35 Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Thu, 23 Jan 2025 12:01:33 +0000 Subject: [PATCH] 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. --- crates/radicle-cob/src/backend/git/change.rs | 6 ++++++ crates/radicle-cob/src/change/store.rs | 3 +++ crates/radicle-cob/src/test/storage.rs | 4 ++++ crates/radicle/src/storage/git/cob.rs | 8 ++++++++ crates/radicle/src/test/storage.rs | 4 ++++ 5 files changed, 25 insertions(+) diff --git a/crates/radicle-cob/src/backend/git/change.rs b/crates/radicle-cob/src/backend/git/change.rs index 866e96ad..85fff00c 100644 --- a/crates/radicle-cob/src/backend/git/change.rs +++ b/crates/radicle-cob/src/backend/git/change.rs @@ -159,6 +159,12 @@ impl change::Storage for git2::Repository { .collect::>()) } + fn manifest_of(&self, id: &Oid) -> Result { + let commit = self.find_commit(**id)?; + let tree = commit.tree()?; + load_manifest(self, &tree) + } + fn load(&self, id: Self::ObjectId) -> Result { let commit = Commit::read(self, id.into())?; let timestamp = git2::Time::from(commit.committer().time).seconds() as u64; diff --git a/crates/radicle-cob/src/change/store.rs b/crates/radicle-cob/src/change/store.rs index f5f9100c..7e8f147c 100644 --- a/crates/radicle-cob/src/change/store.rs +++ b/crates/radicle-cob/src/change/store.rs @@ -38,6 +38,9 @@ pub trait Storage { /// Returns the parents of the object with the specified ID. fn parents_of(&self, id: &Oid) -> Result, Self::LoadError>; + + /// Load only the manifest of the change entry. + fn manifest_of(&self, id: &Oid) -> Result; } /// Change template, used to create a new change. diff --git a/crates/radicle-cob/src/test/storage.rs b/crates/radicle-cob/src/test/storage.rs index f0e1a00c..af084c40 100644 --- a/crates/radicle-cob/src/test/storage.rs +++ b/crates/radicle-cob/src/test/storage.rs @@ -101,6 +101,10 @@ impl change::Storage for Storage { .map(git_ext::Oid::from) .collect::>()) } + + fn manifest_of(&self, id: &git_ext::Oid) -> Result { + self.as_raw().manifest_of(id) + } } impl object::Storage for Storage { diff --git a/crates/radicle/src/storage/git/cob.rs b/crates/radicle/src/storage/git/cob.rs index 90a61bae..6f8fee88 100644 --- a/crates/radicle/src/storage/git/cob.rs +++ b/crates/radicle/src/storage/git/cob.rs @@ -82,6 +82,10 @@ impl change::Storage for Repository { fn parents_of(&self, id: &Oid) -> Result, Self::LoadError> { self.backend.parents_of(id) } + + fn manifest_of(&self, id: &Oid) -> Result { + self.backend.manifest_of(id) + } } impl cob::object::Storage for Repository { @@ -223,6 +227,10 @@ impl change::Storage for DraftStore<'_, R> { fn parents_of(&self, id: &Oid) -> Result, Self::LoadError> { self.repo.raw().parents_of(id) } + + fn manifest_of(&self, id: &Oid) -> Result { + self.repo.raw().manifest_of(id) + } } impl SignRepository for DraftStore<'_, R> diff --git a/crates/radicle/src/test/storage.rs b/crates/radicle/src/test/storage.rs index 116d9cc9..a2ea5db6 100644 --- a/crates/radicle/src/test/storage.rs +++ b/crates/radicle/src/test/storage.rs @@ -440,4 +440,8 @@ impl radicle_cob::change::Storage for MockRepository { fn parents_of(&self, _id: &Oid) -> Result, Self::LoadError> { todo!() } + + fn manifest_of(&self, _id: &Oid) -> Result { + todo!() + } }