From e8a2432f9dd41b4f56fdabdfbff57d8d45e33500 Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Thu, 1 Dec 2022 15:17:03 +0100 Subject: [PATCH] Move `Change` from `radicle-crdt` to `radicle` Where it belongs. Signed-off-by: Alexis Sellier --- Cargo.lock | 2 -- radicle-crdt/Cargo.toml | 2 -- radicle-crdt/src/lib.rs | 2 -- radicle-crdt/src/ord.rs | 1 + radicle/src/cob.rs | 2 ++ .../src => radicle/src/cob}/change.rs | 18 ++---------------- radicle/src/cob/issue.rs | 11 ++++++----- radicle/src/cob/patch.rs | 14 +++++++------- radicle/src/cob/thread.rs | 13 +++++++------ 9 files changed, 25 insertions(+), 40 deletions(-) rename {radicle-crdt/src => radicle/src/cob}/change.rs (86%) diff --git a/Cargo.lock b/Cargo.lock index cac8e2ac..5a0a26d9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2249,12 +2249,10 @@ version = "0.1.0" dependencies = [ "fastrand", "num-traits", - "olpc-cjson", "quickcheck", "quickcheck_macros", "radicle-crypto", "serde", - "serde_json", "tempfile", ] diff --git a/radicle-crdt/Cargo.toml b/radicle-crdt/Cargo.toml index 991391c4..60b2a974 100644 --- a/radicle-crdt/Cargo.toml +++ b/radicle-crdt/Cargo.toml @@ -9,10 +9,8 @@ test = ["fastrand", "quickcheck"] [dependencies] fastrand = { version = "1.8.0", optional = true } num-traits = { version = "0.2.15", default-features = false, features = ["std"] } -olpc-cjson = { version = "0.1.1" } quickcheck = { version = "1", optional = true } serde = { version = "1" } -serde_json = { version = "1" } [dependencies.radicle-crypto] path = "../radicle-crypto" diff --git a/radicle-crdt/src/lib.rs b/radicle-crdt/src/lib.rs index fe80343f..f3faa939 100644 --- a/radicle-crdt/src/lib.rs +++ b/radicle-crdt/src/lib.rs @@ -2,7 +2,6 @@ #![allow(clippy::bool_assert_comparison)] #![allow(clippy::collapsible_else_if)] #![allow(clippy::type_complexity)] -pub mod change; pub mod clock; pub mod gmap; pub mod lwwmap; @@ -16,7 +15,6 @@ pub mod test; //////////////////////////////////////////////////////////////////////////////// -pub use change::*; pub use clock::Lamport; pub use gmap::GMap; pub use lwwmap::LWWMap; diff --git a/radicle-crdt/src/ord.rs b/radicle-crdt/src/ord.rs index fa3fb2f9..231cade0 100644 --- a/radicle-crdt/src/ord.rs +++ b/radicle-crdt/src/ord.rs @@ -68,6 +68,7 @@ impl Bounded for Max { #[allow(clippy::derive_ord_xor_partial_ord)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Ord, Serialize, Deserialize)] +#[serde(transparent)] pub struct Min(pub T); impl Default for Min diff --git a/radicle/src/cob.rs b/radicle/src/cob.rs index 64d3cd3a..5bd96bc1 100644 --- a/radicle/src/cob.rs +++ b/radicle/src/cob.rs @@ -1,9 +1,11 @@ +pub mod change; pub mod common; pub mod issue; pub mod patch; pub mod store; pub mod thread; +pub use change::{Actor, ActorId, Change, ChangeId}; pub use cob::{ identity, object::collaboration::error, CollaborativeObject, Contents, Create, Entry, History, ObjectId, TypeName, Update, diff --git a/radicle-crdt/src/change.rs b/radicle/src/cob/change.rs similarity index 86% rename from radicle-crdt/src/change.rs rename to radicle/src/cob/change.rs index 44c01a1d..61a51847 100644 --- a/radicle-crdt/src/change.rs +++ b/radicle/src/cob/change.rs @@ -1,11 +1,10 @@ use std::collections::BTreeMap; +use radicle_crdt::clock; +use radicle_crdt::clock::Lamport; use radicle_crypto::{PublicKey, Signer}; use serde::{Deserialize, Serialize}; -use crate::clock; -use crate::clock::Lamport; - /// Identifies a change. pub type ChangeId = (Lamport, ActorId); /// The author of a change. @@ -33,19 +32,6 @@ impl Change { } } -impl Change { - /// Serialize the change into a byte string. - pub fn encode(&self) -> Vec { - let mut buf = Vec::new(); - let mut serializer = - serde_json::Serializer::with_formatter(&mut buf, olpc_cjson::CanonicalFormatter::new()); - - self.serialize(&mut serializer).unwrap(); - - buf - } -} - impl<'de, A: Deserialize<'de>> Change { /// Deserialize a change from a byte string. pub fn decode(bytes: &'de [u8]) -> Result { diff --git a/radicle/src/cob/issue.rs b/radicle/src/cob/issue.rs index 9e130ad0..71a8e82a 100644 --- a/radicle/src/cob/issue.rs +++ b/radicle/src/cob/issue.rs @@ -2,20 +2,21 @@ use std::ops::{ControlFlow, Deref}; use std::str::FromStr; use once_cell::sync::Lazy; -use radicle_crdt as crdt; use radicle_crdt::clock; -use radicle_crdt::{ChangeId, LWWReg, LWWSet, Max, Semilattice}; +use radicle_crdt::{LWWReg, LWWSet, Max, Semilattice}; use serde::{Deserialize, Serialize}; use thiserror::Error; +use crate::cob; use crate::cob::common::{Author, Reaction, Tag}; use crate::cob::thread; use crate::cob::thread::{CommentId, Thread}; -use crate::cob::{store, ObjectId, TypeName}; +use crate::cob::{store, ChangeId, ObjectId, TypeName}; use crate::crypto::{PublicKey, Signer}; use crate::storage::git as storage; -pub type Change = crdt::Change; +/// Issue change. +pub type Change = crate::cob::Change; /// Type name of an issue. pub static TYPENAME: Lazy = @@ -175,7 +176,7 @@ impl Issue { } } Action::Thread { action } => { - self.thread.apply([crdt::Change { + self.thread.apply([cob::Change { action, author: change.author, clock: change.clock, diff --git a/radicle/src/cob/patch.rs b/radicle/src/cob/patch.rs index 3895ef75..c21e7214 100644 --- a/radicle/src/cob/patch.rs +++ b/radicle/src/cob/patch.rs @@ -6,17 +6,17 @@ use std::ops::Range; use std::str::FromStr; use once_cell::sync::Lazy; -use radicle_crdt as crdt; use radicle_crdt::clock; -use radicle_crdt::{ActorId, ChangeId, GMap, LWWReg, LWWSet, Max, Redactable, Semilattice}; +use radicle_crdt::{GMap, LWWReg, LWWSet, Max, Redactable, Semilattice}; use serde::{Deserialize, Serialize}; use thiserror::Error; +use crate::cob; use crate::cob::common::{Author, Tag, Timestamp}; use crate::cob::thread; use crate::cob::thread::CommentId; use crate::cob::thread::Thread; -use crate::cob::{store, ObjectId, TypeName}; +use crate::cob::{store, ActorId, ChangeId, ObjectId, TypeName}; use crate::crypto::{PublicKey, Signer}; use crate::git; use crate::prelude::*; @@ -30,7 +30,7 @@ pub static TYPENAME: Lazy = Lazy::new(|| FromStr::from_str("xyz.radicle.patch").expect("type name is valid")); /// Patch change. -pub type Change = crdt::Change; +pub type Change = crate::cob::Change; /// Identifier for a patch. pub type PatchId = ObjectId; @@ -306,7 +306,7 @@ impl Patch { // TODO(cloudhead): Make sure we can deal with redacted revisions which are added // to out of order, like in the `Merge` case. if let Some(Redactable::Present(revision)) = self.revisions.get_mut(&revision) { - revision.discussion.apply([crdt::Change { + revision.discussion.apply([cob::Change { action, author: change.author, clock: change.clock, @@ -786,13 +786,13 @@ mod test { use std::str::FromStr; use std::{array, iter}; - use crdt::test::{assert_laws, WeightedGenerator}; - use crdt::{Actor, ActorId}; + use radicle_crdt::test::{assert_laws, WeightedGenerator}; use pretty_assertions::assert_eq; use quickcheck::{Arbitrary, TestResult}; use super::*; + use crate::cob::change::{Actor, ActorId}; use crate::crypto::test::signer::MockSigner; use crate::test; diff --git a/radicle/src/cob/thread.rs b/radicle/src/cob/thread.rs index 0b3d915c..b833fde2 100644 --- a/radicle/src/cob/thread.rs +++ b/radicle/src/cob/thread.rs @@ -8,15 +8,16 @@ use once_cell::sync::Lazy; use radicle_crdt as crdt; use serde::{Deserialize, Serialize}; +use crate::cob; use crate::cob::common::{Reaction, Timestamp}; use crate::cob::store; -use crate::cob::{History, TypeName}; +use crate::cob::{ActorId, Change, ChangeId, History, TypeName}; use crate::crypto::Signer; use crdt::clock::Lamport; use crdt::lwwset::LWWSet; use crdt::redactable::Redactable; -use crdt::{ActorId, Change, ChangeId, Semilattice}; +use crdt::Semilattice; /// Type name of a thread. pub static TYPENAME: Lazy = @@ -244,13 +245,13 @@ impl Thread { /// An object that can be used to create and sign changes. pub struct Actor { - inner: crdt::Actor, + inner: cob::Actor, } impl Default for Actor { fn default() -> Self { Self { - inner: crdt::Actor::new(G::default()), + inner: cob::Actor::new(G::default()), } } } @@ -258,7 +259,7 @@ impl Default for Actor { impl Actor { pub fn new(signer: G) -> Self { Self { - inner: crdt::Actor::new(signer), + inner: cob::Actor::new(signer), } } @@ -282,7 +283,7 @@ impl Actor { } impl Deref for Actor { - type Target = crdt::Actor; + type Target = cob::Actor; fn deref(&self) -> &Self::Target { &self.inner