radicle: Make `DraftStore` generic over the repo

This will allow using it inside of COBs.
This commit is contained in:
cloudhead 2023-09-04 17:19:46 +02:00
parent 6695074479
commit 65fa3cbb1b
No known key found for this signature in database
1 changed files with 14 additions and 14 deletions

View File

@ -173,20 +173,20 @@ impl cob::object::Storage for Repository {
// This storage backend for COBs stores changes in a `draft/cobs/*` namespace, // This storage backend for COBs stores changes in a `draft/cobs/*` namespace,
// which allows for some of the features needed for code review. For // which allows for some of the features needed for code review. For
// example, users can draft comments and later decide to publish them. // example, users can draft comments and later decide to publish them.
pub struct DraftStore<'a> { pub struct DraftStore<'a, R> {
remote: RemoteId, remote: RemoteId,
repo: &'a Repository, repo: &'a R,
} }
impl<'a> DraftStore<'a> { impl<'a, R> DraftStore<'a, R> {
pub fn new(remote: RemoteId, repo: &'a Repository) -> Self { pub fn new(remote: RemoteId, repo: &'a R) -> Self {
Self { remote, repo } Self { remote, repo }
} }
} }
impl<'a> cob::Store for DraftStore<'a> {} impl<'a, R: storage::WriteRepository> cob::Store for DraftStore<'a, R> {}
impl<'a> change::Storage for DraftStore<'a> { impl<'a, R: storage::WriteRepository> change::Storage for DraftStore<'a, R> {
type StoreError = <git2::Repository as change::Storage>::StoreError; type StoreError = <git2::Repository as change::Storage>::StoreError;
type LoadError = <git2::Repository as change::Storage>::LoadError; type LoadError = <git2::Repository as change::Storage>::LoadError;
@ -204,15 +204,15 @@ impl<'a> change::Storage for DraftStore<'a> {
where where
Signer: crypto::Signer, Signer: crypto::Signer,
{ {
self.repo.backend.store(authority, parents, signer, spec) self.repo.raw().store(authority, parents, signer, spec)
} }
fn load(&self, id: Self::ObjectId) -> Result<cob::Entry, Self::LoadError> { fn load(&self, id: Self::ObjectId) -> Result<cob::Entry, Self::LoadError> {
self.repo.backend.load(id) self.repo.raw().load(id)
} }
fn parents_of(&self, id: &Oid) -> Result<Vec<Oid>, Self::LoadError> { fn parents_of(&self, id: &Oid) -> Result<Vec<Oid>, Self::LoadError> {
self.repo.backend.parents_of(id) self.repo.raw().parents_of(id)
} }
} }
@ -225,7 +225,7 @@ impl<'a> SignRepository for DraftStore<'a> {
} }
} }
impl<'a> ReadRepository for DraftStore<'a> { impl<'a, R: storage::ReadRepository> ReadRepository for DraftStore<'a, R> {
fn id(&self) -> identity::Id { fn id(&self) -> identity::Id {
self.repo.id() self.repo.id()
} }
@ -338,7 +338,7 @@ impl<'a> ReadRepository for DraftStore<'a> {
} }
} }
impl<'a> cob::object::Storage for DraftStore<'a> { impl<'a, R: storage::WriteRepository> cob::object::Storage for DraftStore<'a, R> {
type ObjectsError = ObjectsError; type ObjectsError = ObjectsError;
type TypesError = git::ext::Error; type TypesError = git::ext::Error;
type UpdateError = git2::Error; type UpdateError = git2::Error;
@ -352,7 +352,7 @@ impl<'a> cob::object::Storage for DraftStore<'a> {
object_id: &cob::ObjectId, object_id: &cob::ObjectId,
) -> Result<cob::object::Objects, Self::ObjectsError> { ) -> Result<cob::object::Objects, Self::ObjectsError> {
// Nb. There can only be one draft per COB, per remote. // Nb. There can only be one draft per COB, per remote.
let Ok(r) = self.repo.backend.find_reference( let Ok(r) = self.repo.raw().find_reference(
git::refs::storage::draft::cob(&self.remote, typename, object_id).as_str(), git::refs::storage::draft::cob(&self.remote, typename, object_id).as_str(),
) else { ) else {
return Ok(Objects::default()); return Ok(Objects::default());
@ -387,7 +387,7 @@ impl<'a> cob::object::Storage for DraftStore<'a> {
object_id: &cob::ObjectId, object_id: &cob::ObjectId,
entry: &cob::history::EntryId, entry: &cob::history::EntryId,
) -> Result<(), Self::UpdateError> { ) -> Result<(), Self::UpdateError> {
self.repo.backend.reference( self.repo.raw().reference(
git::refs::storage::draft::cob(identifier, typename, object_id).as_str(), git::refs::storage::draft::cob(identifier, typename, object_id).as_str(),
(*entry).into(), (*entry).into(),
true, true,
@ -406,7 +406,7 @@ impl<'a> cob::object::Storage for DraftStore<'a> {
typename: &cob::TypeName, typename: &cob::TypeName,
object_id: &cob::ObjectId, object_id: &cob::ObjectId,
) -> Result<(), Self::RemoveError> { ) -> Result<(), Self::RemoveError> {
let mut reference = self.repo.backend.find_reference( let mut reference = self.repo.raw().find_reference(
git::refs::storage::draft::cob(identifier, typename, object_id).as_str(), git::refs::storage::draft::cob(identifier, typename, object_id).as_str(),
)?; )?;