cob: Don't require full `Entry` for update

Instead of taking the full entry type, we only need the id.
This commit is contained in:
cloudhead 2023-09-04 18:07:30 +02:00
parent c903a958e7
commit 6695074479
No known key found for this signature in database
6 changed files with 16 additions and 20 deletions

View File

@ -77,7 +77,7 @@ mod change_graph;
mod trailers; mod trailers;
pub mod change; pub mod change;
pub use change::store::{Contents, Embed, Manifest, Version}; pub use change::store::{Contents, Embed, EntryId, Manifest, Version};
pub use change::Entry; pub use change::Entry;
pub mod history; pub mod history;

View File

@ -71,7 +71,7 @@ where
let object_id = init_change.id().into(); let object_id = init_change.id().into();
storage storage
.update(identifier, &type_name, &object_id, &init_change) .update(identifier, &type_name, &object_id, &init_change.id)
.map_err(|err| error::Create::Refs { err: Box::new(err) })?; .map_err(|err| error::Create::Refs { err: Box::new(err) })?;
let history = History::new_from_root(init_change); let history = History::new_from_root(init_change);

View File

@ -96,7 +96,7 @@ where
)?; )?;
storage storage
.update(identifier, typename, &object_id, &change) .update(identifier, typename, &object_id, &change.id)
.map_err(|err| error::Update::Refs { err: Box::new(err) })?; .map_err(|err| error::Update::Refs { err: Box::new(err) })?;
let parents = change.parents.to_vec(); let parents = change.parents.to_vec();

View File

@ -5,7 +5,7 @@ use std::{collections::BTreeMap, error::Error};
use git_ext::ref_format::RefString; use git_ext::ref_format::RefString;
use git_ext::Oid; use git_ext::Oid;
use crate::change::Entry; use crate::change::EntryId;
use crate::{ObjectId, TypeName}; use crate::{ObjectId, TypeName};
/// The [`Reference`]s that refer to the commits that make up a /// The [`Reference`]s that refer to the commits that make up a
@ -78,7 +78,7 @@ pub trait Storage {
identifier: &Self::Identifier, identifier: &Self::Identifier,
typename: &TypeName, typename: &TypeName,
object_id: &ObjectId, object_id: &ObjectId,
change: &Entry, entry: &EntryId,
) -> Result<(), Self::UpdateError>; ) -> Result<(), Self::UpdateError>;
/// Remove a ref to a particular collaborative object /// Remove a ref to a particular collaborative object

View File

@ -154,7 +154,7 @@ impl object::Storage for Storage {
identifier: &Self::Identifier, identifier: &Self::Identifier,
typename: &crate::TypeName, typename: &crate::TypeName,
object_id: &ObjectId, object_id: &ObjectId,
change: &change::Entry, entry: &change::EntryId,
) -> Result<(), Self::UpdateError> { ) -> Result<(), Self::UpdateError> {
let name = format!( let name = format!(
"refs/rad/{}/cobs/{}/{}", "refs/rad/{}/cobs/{}/{}",
@ -162,8 +162,8 @@ impl object::Storage for Storage {
typename, typename,
object_id object_id
); );
let id = *change.id(); self.raw
self.raw.reference(&name, id.into(), true, "new change")?; .reference(&name, (*entry).into(), true, "new change")?;
Ok(()) Ok(())
} }

View File

@ -139,17 +139,15 @@ impl cob::object::Storage for Repository {
identifier: &Self::Identifier, identifier: &Self::Identifier,
typename: &cob::TypeName, typename: &cob::TypeName,
object_id: &cob::ObjectId, object_id: &cob::ObjectId,
change: &cob::Entry, entry: &cob::EntryId,
) -> Result<(), Self::UpdateError> { ) -> Result<(), Self::UpdateError> {
self.backend.reference( self.backend.reference(
git::refs::storage::cob(identifier, typename, object_id).as_str(), git::refs::storage::cob(identifier, typename, object_id).as_str(),
(*change.id()).into(), (*entry).into(),
true, true,
&format!( &format!(
"Updating collaborative object '{}/{}' with new change {}", "Updating collaborative object '{}/{}' with new entry {}",
typename, typename, object_id, entry,
object_id,
change.id()
), ),
)?; )?;
@ -387,17 +385,15 @@ impl<'a> cob::object::Storage for DraftStore<'a> {
identifier: &Self::Identifier, identifier: &Self::Identifier,
typename: &cob::TypeName, typename: &cob::TypeName,
object_id: &cob::ObjectId, object_id: &cob::ObjectId,
change: &cob::Entry, entry: &cob::history::EntryId,
) -> Result<(), Self::UpdateError> { ) -> Result<(), Self::UpdateError> {
self.repo.backend.reference( self.repo.backend.reference(
git::refs::storage::draft::cob(identifier, typename, object_id).as_str(), git::refs::storage::draft::cob(identifier, typename, object_id).as_str(),
(*change.id()).into(), (*entry).into(),
true, true,
&format!( &format!(
"Updating draft collaborative object '{}/{}' with new change {}", "Updating draft collaborative object '{}/{}' with new entry {}",
typename, typename, object_id, entry,
object_id,
change.id()
), ),
)?; )?;