Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cob: Use `radicle_oid`
Lorenz Leutgeb committed 7 months ago
commit 853be107bf45d77139d7f20c198c6be231203b4c
parent 58cccd47b823d33fea94bc08682c296e90b30afb
19 files changed +44 -48
modified Cargo.lock
@@ -2881,6 +2881,7 @@ dependencies = [
 "radicle-crypto",
 "radicle-dag",
 "radicle-git-ext",
+
 "radicle-oid",
 "serde",
 "serde_json",
 "signature 2.2.0",
modified crates/radicle-cob/Cargo.toml
@@ -25,6 +25,7 @@ log = { workspace = true }
nonempty = { workspace = true, features = ["serialize"] }
radicle-crypto = { workspace = true, features = ["ssh"] }
radicle-dag = { workspace = true }
+
radicle-oid = { workspace = true, features = ["git2", "serde", "std"] }
radicle-git-ext = { workspace = true, features = ["serde"] }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
@@ -36,4 +37,5 @@ fastrand = { workspace = true }
qcheck = { workspace = true }
qcheck-macros = { workspace = true }
radicle-crypto = { workspace = true, features = ["test", "radicle-git-ext"] }
+
radicle-oid = { workspace = true, features = ["qcheck"] }
tempfile = { workspace = true }

\ No newline at end of file
modified crates/radicle-cob/src/backend/git/change.rs
@@ -7,9 +7,9 @@ use std::sync::LazyLock;

use git_ext::author::Author;
use git_ext::commit::{headers::Headers, Commit};
-
use git_ext::Oid;
use nonempty::NonEmpty;
use radicle_git_ext::commit::trailers::OwnedTrailer;
+
use radicle_oid::Oid;

use crate::change::store::Version;
use crate::signatures;
@@ -31,7 +31,7 @@ pub mod error {
    use std::string::FromUtf8Error;

    use git_ext::commit;
-
    use git_ext::Oid;
+
    use radicle_oid::Oid;
    use thiserror::Error;

    use crate::signatures::error::Signatures;
@@ -123,7 +123,7 @@ impl change::Storage for git2::Repository {

        let (id, timestamp) = write_commit(
            self,
-
            resource.map(|o| *o),
+
            resource.map(|o| o.into()),
            // Commit to tips, extra parents and resource.
            tips.iter()
                .cloned()
@@ -134,7 +134,7 @@ impl change::Storage for git2::Repository {
            signature.clone(),
            related
                .iter()
-
                .map(|p| trailers::CommitTrailer::Related(**p).into()),
+
                .map(|p| trailers::CommitTrailer::Related(*p).into()),
            tree,
        )?;

@@ -153,14 +153,14 @@ impl change::Storage for git2::Repository {

    fn parents_of(&self, id: &Oid) -> Result<Vec<Oid>, Self::LoadError> {
        Ok(self
-
            .find_commit(**id)?
+
            .find_commit(id.into())?
            .parent_ids()
            .map(Oid::from)
            .collect::<Vec<_>>())
    }

    fn manifest_of(&self, id: &Oid) -> Result<crate::Manifest, Self::LoadError> {
-
        let commit = self.find_commit(**id)?;
+
        let commit = self.find_commit(id.into())?;
        let tree = commit.tree()?;
        load_manifest(self, &tree)
    }
@@ -173,14 +173,8 @@ impl change::Storage for git2::Repository {
            CommitTrailer::Resource(_) => true,
            CommitTrailer::Related(_) => false,
        });
-
        let mut resources = resources
-
            .into_iter()
-
            .map(|r| r.oid().into())
-
            .collect::<Vec<_>>();
-
        let related = related
-
            .into_iter()
-
            .map(|r| r.oid().into())
-
            .collect::<Vec<_>>();
+
        let mut resources = resources.into_iter().map(|r| r.oid()).collect::<Vec<_>>();
+
        let related = related.into_iter().map(|r| r.oid()).collect::<Vec<_>>();
        let parents = commit
            .parents()
            .map(Oid::from)
@@ -285,7 +279,7 @@ fn write_commit(
) -> Result<(Oid, Timestamp), error::Create> {
    let trailers: Vec<OwnedTrailer> = trailers
        .into_iter()
-
        .chain(resource.map(|r| trailers::CommitTrailer::Resource(r).into()))
+
        .chain(resource.map(|r| trailers::CommitTrailer::Resource(r.into()).into()))
        .collect();
    let author = repo.signature()?;
    #[allow(unused_variables)]
@@ -380,7 +374,7 @@ fn write_manifest(
            let oid = embed.content;
            let path = PathBuf::from(embed.name);

-
            embeds_tree.insert(path, *oid, git2::FileMode::Blob.into())?;
+
            embeds_tree.insert(path, oid.into(), git2::FileMode::Blob.into())?;
        }
        let oid = embeds_tree.write()?;

modified crates/radicle-cob/src/change.rs
@@ -1,6 +1,6 @@
// Copyright © 2021 The Radicle Link Contributors

-
use git_ext::Oid;
+
use oid::Oid;

pub mod store;
pub use store::{Contents, EntryId, Storage, Template, Timestamp};
modified crates/radicle-cob/src/change/store.rs
@@ -3,7 +3,7 @@
use std::{error::Error, fmt, num::NonZeroUsize};

use nonempty::NonEmpty;
-
use radicle_git_ext::Oid;
+
use oid::Oid;
use serde::{Deserialize, Serialize};

use crate::{signatures, TypeName};
modified crates/radicle-cob/src/change_graph.rs
@@ -3,8 +3,8 @@
use std::ops::ControlFlow;
use std::{cmp::Ordering, collections::BTreeSet};

-
use git_ext::Oid;
use radicle_dag::Dag;
+
use radicle_oid::Oid;

use crate::{
    change, object, object::collaboration::Evaluate, signatures::ExtendedSignature,
modified crates/radicle-cob/src/history.rs
@@ -2,8 +2,8 @@
#![allow(clippy::too_many_arguments)]
use std::{cmp::Ordering, collections::BTreeSet, ops::ControlFlow};

-
use git_ext::Oid;
use radicle_dag::Dag;
+
use radicle_oid::Oid;

pub use crate::change::{Contents, Entry, EntryId, Timestamp};

@@ -77,7 +77,7 @@ impl History {
        self.graph.node(id, change);

        for tip in tips {
-
            self.graph.dependency(id, (*tip).into());
+
            self.graph.dependency(id, tip);
        }
    }

modified crates/radicle-cob/src/lib.rs
@@ -61,6 +61,7 @@ extern crate qcheck_macros;

extern crate radicle_crypto as crypto;
extern crate radicle_git_ext as git_ext;
+
extern crate radicle_oid as oid;

mod backend;
pub use backend::git;
@@ -115,8 +116,8 @@ where
        + change::Storage<
            StoreError = git::change::error::Create,
            LoadError = git::change::error::Load,
-
            ObjectId = git_ext::Oid,
-
            Parent = git_ext::Oid,
+
            ObjectId = oid::Oid,
+
            Parent = oid::Oid,
            Signatures = ExtendedSignature,
        >,
{
modified crates/radicle-cob/src/object.rs
@@ -3,7 +3,7 @@
use std::{convert::TryFrom as _, fmt, ops::Deref, str::FromStr};

use git_ext::ref_format::{Component, RefString};
-
use git_ext::Oid;
+
use radicle_oid::Oid;
use serde::{Deserialize, Serialize};
use thiserror::Error;

@@ -19,7 +19,7 @@ pub use storage::{Commit, Objects, Reference, Storage};
#[derive(Debug, Error)]
pub enum ParseObjectId {
    #[error(transparent)]
-
    Git(#[from] git2::Error),
+
    Git(#[from] oid::str::ParseOidError),
}

/// The id of an object
modified crates/radicle-cob/src/object/collaboration.rs
@@ -2,8 +2,8 @@
use std::convert::Infallible;
use std::fmt::Debug;

-
use git_ext::Oid;
use nonempty::NonEmpty;
+
use oid::Oid;

use crate::change::store::{Manifest, Version};
use crate::{change, Entry, History, ObjectId, TypeName};
modified crates/radicle-cob/src/object/collaboration/create.rs
@@ -23,7 +23,7 @@ pub struct Create {
}

impl Create {
-
    fn template(self) -> change::Template<git_ext::Oid> {
+
    fn template(self) -> change::Template<oid::Oid> {
        change::Template {
            type_name: self.type_name,
            tips: Vec::new(),
modified crates/radicle-cob/src/object/collaboration/info.rs
@@ -6,7 +6,7 @@

use std::collections::BTreeSet;

-
use git_ext::Oid;
+
use oid::Oid;

use crate::{change_graph::ChangeGraph, ObjectId, Store, TypeName};

modified crates/radicle-cob/src/object/collaboration/update.rs
@@ -1,8 +1,8 @@
// Copyright © 2022 The Radicle Link Contributors
use std::iter;

-
use git_ext::Oid;
use nonempty::NonEmpty;
+
use oid::Oid;

use crate::{
    change, change_graph::ChangeGraph, history::EntryId, CollaborativeObject, Embed, Evaluate,
modified crates/radicle-cob/src/object/storage.rs
@@ -3,7 +3,7 @@
use std::{collections::BTreeMap, error::Error};

use git_ext::ref_format::RefString;
-
use git_ext::Oid;
+
use radicle_oid::Oid;

use crate::change::EntryId;
use crate::{ObjectId, TypeName};
modified crates/radicle-cob/src/test/arbitrary.rs
@@ -26,11 +26,7 @@ impl Arbitrary for TypeName {

impl Arbitrary for ObjectId {
    fn arbitrary(g: &mut qcheck::Gen) -> Self {
-
        let mut rng = fastrand::Rng::with_seed(u64::arbitrary(g));
-
        let bytes = iter::repeat_with(|| rng.u8(..))
-
            .take(20)
-
            .collect::<Vec<_>>();
-
        Self::from(git_ext::Oid::try_from(bytes.as_slice()).unwrap())
+
        Self::from(oid::Oid::arbitrary(g))
    }
}

modified crates/radicle-cob/src/test/identity/person.rs
@@ -1,4 +1,4 @@
-
use git_ext::Oid;
+
use oid::Oid;
use serde::{Deserialize, Serialize};

use crate::test::storage::{self, Storage};
modified crates/radicle-cob/src/test/identity/project.rs
@@ -1,6 +1,6 @@
use std::collections::BTreeSet;

-
use git_ext::Oid;
+
use oid::Oid;
use serde::{Deserialize, Serialize};

use crate::test;
modified crates/radicle-cob/src/test/storage.rs
@@ -93,16 +93,16 @@ impl change::Storage for Storage {
        self.as_raw().load(id)
    }

-
    fn parents_of(&self, id: &git_ext::Oid) -> Result<Vec<git_ext::Oid>, Self::LoadError> {
+
    fn parents_of(&self, id: &oid::Oid) -> Result<Vec<radicle_oid::Oid>, Self::LoadError> {
        Ok(self
            .as_raw()
-
            .find_commit(**id)?
+
            .find_commit(id.into())?
            .parent_ids()
-
            .map(git_ext::Oid::from)
+
            .map(oid::Oid::from)
            .collect::<Vec<_>>())
    }

-
    fn manifest_of(&self, id: &git_ext::Oid) -> Result<crate::Manifest, Self::LoadError> {
+
    fn manifest_of(&self, id: &oid::Oid) -> Result<crate::Manifest, Self::LoadError> {
        self.as_raw().manifest_of(id)
    }
}
modified crates/radicle-cob/src/trailers.rs
@@ -20,13 +20,13 @@ pub mod error {
/// Commit trailer for COB commits.
pub enum CommitTrailer {
    /// Points to the owning resource.
-
    Resource(git2::Oid),
+
    Resource(oid::Oid),
    /// Points to a related change.
-
    Related(git2::Oid),
+
    Related(oid::Oid),
}

impl CommitTrailer {
-
    pub fn oid(&self) -> git2::Oid {
+
    pub fn oid(&self) -> oid::Oid {
        match self {
            Self::Resource(oid) => *oid,
            Self::Related(oid) => *oid,
@@ -38,12 +38,14 @@ impl TryFrom<&Trailer<'_>> for CommitTrailer {
    type Error = error::InvalidResourceTrailer;

    fn try_from(Trailer { value, token }: &Trailer<'_>) -> Result<Self, Self::Error> {
-
        let ext_oid =
-
            git_ext::Oid::try_from(value.as_ref()).map_err(|_| Self::Error::InvalidOid)?;
+
        let value: &str = value.as_ref();
+
        let ext_oid = value
+
            .parse::<oid::Oid>()
+
            .map_err(|_| Self::Error::InvalidOid)?;
        if token.deref() == "Rad-Resource" {
-
            Ok(CommitTrailer::Resource(ext_oid.into()))
+
            Ok(CommitTrailer::Resource(ext_oid))
        } else if token.deref() == "Rad-Related" {
-
            Ok(CommitTrailer::Related(ext_oid.into()))
+
            Ok(CommitTrailer::Related(ext_oid))
        } else {
            Err(Self::Error::WrongToken)
        }