Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
chore: Remove dependency `once_cell`
Merged lorenz opened 10 months ago

Rust 1.80 introduced std::sync::LazyLock which achieves the same, so cut down on dependencies a bit.

See: https://doc.rust-lang.org/1.80.0/std/sync/struct.LazyLock.html

23 files changed +50 -60 3bc0db68 d50df68b
modified CONTRIBUTING.md
@@ -100,7 +100,7 @@ Imports are organized in groups, from least specific to more specific:
    use std::time;

    use git_ref_format as format;    // Then, external dependencies.
-
    use once_cell::sync::Lazy;
+
    use serde_json::Value;

    use crate::crypto::PublicKey;    // Finally, local crate imports.
    use crate::storage::refs::Refs;
modified Cargo.lock
@@ -2598,7 +2598,6 @@ dependencies = [
 "log",
 "multibase",
 "nonempty 0.9.0",
-
 "once_cell",
 "pretty_assertions",
 "qcheck",
 "qcheck-macros",
@@ -2681,7 +2680,6 @@ dependencies = [
 "git2",
 "log",
 "nonempty 0.9.0",
-
 "once_cell",
 "qcheck",
 "qcheck-macros",
 "radicle-crypto",
@@ -2790,7 +2788,6 @@ dependencies = [
 "log",
 "netservices",
 "nonempty 0.9.0",
-
 "once_cell",
 "qcheck",
 "qcheck-macros",
 "radicle",
@@ -2825,7 +2822,6 @@ dependencies = [
name = "radicle-schemars"
version = "0.1.0"
dependencies = [
-
 "once_cell",
 "radicle",
 "schemars",
 "serde",
@@ -2890,7 +2886,6 @@ dependencies = [
 "git2",
 "inquire",
 "libc",
-
 "once_cell",
 "pretty_assertions",
 "radicle-signals",
 "shlex",
modified radicle-cob/Cargo.toml
@@ -22,7 +22,6 @@ stable-commit-ids = []
fastrand = { version = "2.0.0" }
log = { version = "0.4.17" }
nonempty = { version = "0.9.0", features = ["serialize"] }
-
once_cell = { version = "1.13" }
radicle-git-ext = { version = "0.8.0", features = ["serde"] }
serde_json = { version = "1.0" }
signature = { version = "2.2" }
modified radicle-cob/src/backend/git/change.rs
@@ -3,12 +3,12 @@
use std::collections::BTreeMap;
use std::convert::TryFrom;
use std::path::PathBuf;
+
use std::sync::LazyLock;

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

use crate::change::store::Version;
@@ -24,7 +24,7 @@ use crate::{
/// Name of the COB manifest file.
pub const MANIFEST_BLOB_NAME: &str = "manifest";
/// Path under which COB embeds are kept.
-
pub static EMBEDS_PATH: Lazy<PathBuf> = Lazy::new(|| PathBuf::from("embeds"));
+
pub static EMBEDS_PATH: LazyLock<PathBuf> = LazyLock::new(|| PathBuf::from("embeds"));

pub mod error {
    use std::str::Utf8Error;
modified radicle-node/Cargo.toml
@@ -31,7 +31,6 @@ log = { version = "0.4.17", features = ["std"] }
localtime = { version = "1.2.0" }
netservices = { version = "0.8.0", features = ["io-reactor", "socket2"] }
nonempty = { version = "0.9.0", features = ["serialize"] }
-
once_cell = { version = "1.13" }
qcheck = { version = "1", default-features = false, optional = true }
# N.b. this is required to use macros, even though it's re-exported
# through radicle
modified radicle-node/src/service/gossip.rs
@@ -1,16 +1,16 @@
pub mod store;

use std::str::FromStr;
+
use std::sync::LazyLock;

use super::*;
use crate::{PROTOCOL_VERSION, VERSION};
-
use once_cell::sync::Lazy;
use radicle::node::UserAgent;

pub use store::{AnnouncementId, Error, RelayStatus, Store};

/// This node's user agent string.
-
pub static USER_AGENT: Lazy<UserAgent> = Lazy::new(|| {
+
pub static USER_AGENT: LazyLock<UserAgent> = LazyLock::new(|| {
    FromStr::from_str(format!("/radicle:{}/", VERSION.version).as_str())
        .expect("user agent is valid")
});
modified radicle-node/src/tests.rs
@@ -5,11 +5,11 @@ use std::default::*;
use std::env;
use std::io;
use std::sync::Arc;
+
use std::sync::LazyLock;
use std::time;

use crossbeam_channel as chan;
use netservices::Direction as Link;
-
use once_cell::sync::Lazy;
use radicle::identity::Visibility;
use radicle::node::address::Store as _;
use radicle::node::device::Device;
@@ -57,7 +57,7 @@ use crate::{git, identity, rad, runtime, service, test};
/// Default number of tests to run when testing things with high variance.
pub const DEFAULT_TEST_CASES: usize = 10;
/// Test cases to run when testing things with high variance.
-
pub static TEST_CASES: Lazy<usize> = Lazy::new(|| {
+
pub static TEST_CASES: LazyLock<usize> = LazyLock::new(|| {
    env::var("RAD_TEST_CASES")
        .ok()
        .and_then(|s| s.parse::<usize>().ok())
modified radicle-schemars/Cargo.toml
@@ -13,7 +13,6 @@ name = "radicle-schemars"
path = "src/main.rs"

[dependencies]
-
once_cell = { version = "1.13" }
schemars = { workspace = true }
serde = { version = "1.0" }
serde_json = { version = "1" }
modified radicle-schemars/src/main.rs
@@ -1,7 +1,7 @@
use std::io;
use std::net;
+
use std::sync::LazyLock;

-
use once_cell::sync::Lazy;
use schemars::{generate::*, *};

const SCHEMA_COMMAND: &str = "radicle::node::Command";
@@ -10,7 +10,7 @@ const SCHEMA_PROFILE_CONFIG: &str = "radicle::profile::Config";

const SCHEMAS: &[&str] = &[SCHEMA_COMMAND, SCHEMA_COMMAND_RESULT, SCHEMA_PROFILE_CONFIG];

-
pub static ERROR_MSG: Lazy<String> = Lazy::new(|| {
+
pub static ERROR_MSG: LazyLock<String> = LazyLock::new(|| {
    let schemas = SCHEMAS.to_vec().join("\", \"");
    format!("Expected exactly one of the following schema names: [\"{schemas}\"].")
});
modified radicle-term/Cargo.toml
@@ -18,7 +18,6 @@ anstyle-query = { version = "1.0.0" }
crossbeam-channel = { version = "0.5.6" }
inquire = { version = "0.7.4", default-features = false, features = ["termion", "editor"] }
libc = { version = "0.2" }
-
once_cell = { version = "1.13" }
shlex = { version = "1.1" }
termion = { version = "3" }
thiserror = { version = "1" }
modified radicle-term/src/ansi/paint.rs
@@ -1,10 +1,9 @@
use std::io::IsTerminal as _;
use std::os::fd::{AsRawFd, BorrowedFd};
use std::sync::atomic::{AtomicBool, AtomicI32};
+
use std::sync::LazyLock;
use std::{fmt, sync};

-
use once_cell::sync::Lazy;
-

use super::color::Color;
use super::style::{Property, Style};

@@ -277,7 +276,7 @@ impl Paint<()> {

    /// Check 24-bit RGB color support.
    pub fn truecolor() -> bool {
-
        static TRUECOLOR: Lazy<bool> = Lazy::new(anstyle_query::term_supports_color);
+
        static TRUECOLOR: LazyLock<bool> = LazyLock::new(anstyle_query::term_supports_color);
        *TRUECOLOR
    }

modified radicle-term/src/io.rs
@@ -1,13 +1,13 @@
use std::ffi::OsStr;
use std::fmt::Write;
use std::process::Stdio;
+
use std::sync::LazyLock;
use std::{env, fmt, io, process};

use inquire::ui::{ErrorMessageRenderConfig, StyleSheet, Styled};
use inquire::validator;
use inquire::InquireError;
use inquire::{ui::Color, ui::RenderConfig, Confirm, CustomType, Password};
-
use once_cell::sync::Lazy;
use zeroize::Zeroizing;

use crate::command;
@@ -26,7 +26,7 @@ pub const TAB: &str = " ";
pub type Passphrase = Zeroizing<String>;

/// Render configuration.
-
pub static CONFIG: Lazy<RenderConfig> = Lazy::new(|| RenderConfig {
+
pub static CONFIG: LazyLock<RenderConfig> = LazyLock::new(|| RenderConfig {
    prompt: StyleSheet::new().with_fg(Color::LightCyan),
    prompt_prefix: Styled::new("?").with_fg(Color::LightBlue),
    answered_prompt_prefix: Styled::new("✓").with_fg(Color::LightGreen),
modified radicle/Cargo.toml
@@ -26,7 +26,6 @@ localtime = { version = "1.2.0", features = ["serde"] }
libc = { version = "0.2" }
log = { version = "0.4.17", features = ["std"] }
nonempty = { version = "0.9.0", features = ["serialize"] }
-
once_cell = { version = "1.13" }
serde = { version = "1", features = ["derive"] }
serde_json = { version = "1", features = ["preserve_order"] }
siphasher = { version = "1.0.0" }
modified radicle/src/cob/identity.rs
@@ -1,8 +1,8 @@
use std::collections::BTreeMap;
+
use std::sync::LazyLock;
use std::{fmt, ops::Deref, str::FromStr};

use crypto::{PublicKey, Signature};
-
use once_cell::sync::Lazy;
use radicle_cob::{Embed, ObjectId, TypeName};
use radicle_git_ext as git_ext;
use radicle_git_ext::Oid;
@@ -29,8 +29,8 @@ use crate::{
use super::{Author, EntryId};

/// Type name of an identity proposal.
-
pub static TYPENAME: Lazy<TypeName> =
-
    Lazy::new(|| FromStr::from_str("xyz.radicle.id").expect("type name is valid"));
+
pub static TYPENAME: LazyLock<TypeName> =
+
    LazyLock::new(|| FromStr::from_str("xyz.radicle.id").expect("type name is valid"));

/// Identity operation.
pub type Op = cob::Op<Action>;
modified radicle/src/cob/issue.rs
@@ -3,8 +3,8 @@ pub mod cache;
use std::collections::BTreeSet;
use std::ops::Deref;
use std::str::FromStr;
+
use std::sync::LazyLock;

-
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
use thiserror::Error;

@@ -27,8 +27,8 @@ pub use cache::Cache;
pub type Op = cob::Op<Action>;

/// Type name of an issue.
-
pub static TYPENAME: Lazy<TypeName> =
-
    Lazy::new(|| FromStr::from_str("xyz.radicle.issue").expect("type name is valid"));
+
pub static TYPENAME: LazyLock<TypeName> =
+
    LazyLock::new(|| FromStr::from_str("xyz.radicle.issue").expect("type name is valid"));

/// Identifier for an issue.
pub type IssueId = ObjectId;
modified radicle/src/cob/patch.rs
@@ -5,10 +5,10 @@ use std::collections::{BTreeMap, BTreeSet, HashMap};
use std::fmt;
use std::ops::Deref;
use std::str::FromStr;
+
use std::sync::LazyLock;

use amplify::Wrapper;
use nonempty::NonEmpty;
-
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
use storage::{HasRepoId, RepositoryError};
use thiserror::Error;
@@ -32,8 +32,8 @@ use crate::storage;
pub use cache::Cache;

/// Type name of a patch.
-
pub static TYPENAME: Lazy<TypeName> =
-
    Lazy::new(|| FromStr::from_str("xyz.radicle.patch").expect("type name is valid"));
+
pub static TYPENAME: LazyLock<TypeName> =
+
    LazyLock::new(|| FromStr::from_str("xyz.radicle.patch").expect("type name is valid"));

/// Patch operation.
pub type Op = cob::Op<Action>;
modified radicle/src/cob/thread.rs
@@ -1,8 +1,8 @@
use std::cmp::Ordering;
use std::collections::{BTreeMap, BTreeSet};
use std::str::FromStr;
+
use std::sync::LazyLock;

-
use once_cell::sync::Lazy;
use serde::{ser::SerializeStruct, Deserialize, Serialize};
use thiserror::Error;

@@ -15,8 +15,8 @@ use crate::prelude::ReadRepository;

/// Type name of a thread, as well as the domain for all thread operations.
/// Note that threads are not usually used standalone. They are embeded into other COBs.
-
pub static TYPENAME: Lazy<cob::TypeName> =
-
    Lazy::new(|| FromStr::from_str("xyz.radicle.thread").expect("type name is valid"));
+
pub static TYPENAME: LazyLock<cob::TypeName> =
+
    LazyLock::new(|| FromStr::from_str("xyz.radicle.thread").expect("type name is valid"));

/// Error applying an operation onto a state.
#[derive(Error, Debug)]
modified radicle/src/git.rs
@@ -4,9 +4,9 @@ use std::io;
use std::path::Path;
use std::process::Command;
use std::str::FromStr;
+
use std::sync::LazyLock;

use git_ext::ref_format as format;
-
use once_cell::sync::Lazy;

use crate::collections::RandomMap;
use crate::crypto::PublicKey;
@@ -188,7 +188,7 @@ pub mod refs {
        ///
        /// `refs/rad/id`
        ///
-
        pub static IDENTITY_BRANCH: Lazy<Qualified> = Lazy::new(|| {
+
        pub static IDENTITY_BRANCH: LazyLock<Qualified> = LazyLock::new(|| {
            Qualified::from_components(name::component!("rad"), name::component!("id"), None)
        });

@@ -196,7 +196,7 @@ pub mod refs {
        ///
        /// `refs/rad/root`
        ///
-
        pub static IDENTITY_ROOT: Lazy<Qualified> = Lazy::new(|| {
+
        pub static IDENTITY_ROOT: LazyLock<Qualified> = LazyLock::new(|| {
            Qualified::from_components(name::component!("rad"), name::component!("root"), None)
        });

@@ -204,7 +204,7 @@ pub mod refs {
        ///
        /// `refs/rad/sigrefs`
        ///
-
        pub static SIGREFS_BRANCH: Lazy<Qualified> = Lazy::new(|| {
+
        pub static SIGREFS_BRANCH: LazyLock<Qualified> = LazyLock::new(|| {
            Qualified::from_components(name::component!("rad"), name::component!("sigrefs"), None)
        });

modified radicle/src/identity/doc.rs
@@ -6,9 +6,9 @@ use std::num::{NonZeroU32, NonZeroUsize};
use std::ops::{Deref, Not};
use std::path::Path;
use std::str::FromStr;
+
use std::sync::LazyLock;

use nonempty::NonEmpty;
-
use once_cell::sync::Lazy;
use radicle_cob::type_name::{TypeName, TypeNameParse};
use radicle_git_ext::Oid;
use serde::{de, Deserialize, Serialize};
@@ -28,7 +28,7 @@ pub use crypto::PublicKey;
pub use id::*;

/// Path to the identity document in the identity branch.
-
pub static PATH: Lazy<&Path> = Lazy::new(|| Path::new("radicle.json"));
+
pub static PATH: LazyLock<&Path> = LazyLock::new(|| Path::new("radicle.json"));
/// Maximum length of a string in the identity document.
pub const MAX_STRING_LENGTH: usize = 255;
/// Maximum number of a delegates in the identity document.
modified radicle/src/node/config.rs
@@ -23,10 +23,10 @@ pub mod seeds {
    use std::str::FromStr;

    use super::{ConnectAddress, PeerAddr};
-
    use once_cell::sync::Lazy;
+
    use std::sync::LazyLock;

    /// A public Radicle seed node for the community.
-
    pub static RADICLE_NODE_BOOTSTRAP_IRIS: Lazy<ConnectAddress> = Lazy::new(|| {
+
    pub static RADICLE_NODE_BOOTSTRAP_IRIS: LazyLock<ConnectAddress> = LazyLock::new(|| {
        // SAFETY: `ConnectAddress` is known at compile time.
        #[allow(clippy::unwrap_used)]
        PeerAddr::from_str("z6MkrLMMsiPWUcNPHcRajuMi9mDfYckSoJyPwwnknocNYPm7@iris.radicle.xyz:8776")
@@ -35,7 +35,7 @@ pub mod seeds {
    });

    /// A public Radicle seed node for the community.
-
    pub static RADICLE_NODE_BOOTSTRAP_ROSA: Lazy<ConnectAddress> = Lazy::new(|| {
+
    pub static RADICLE_NODE_BOOTSTRAP_ROSA: LazyLock<ConnectAddress> = LazyLock::new(|| {
        // SAFETY: `ConnectAddress` is known at compile time.
        #[allow(clippy::unwrap_used)]
        PeerAddr::from_str("z6Mkmqogy2qEM2ummccUthFEaaHvyYmYBYh3dbe9W4ebScxo@rosa.radicle.xyz:8776")
@@ -44,7 +44,7 @@ pub mod seeds {
    });

    /// The Radicle seed node that the Radicle team uses.
-
    pub static RADICLE_NODE_TEAM: Lazy<ConnectAddress> = Lazy::new(|| {
+
    pub static RADICLE_NODE_TEAM: LazyLock<ConnectAddress> = LazyLock::new(|| {
        // SAFETY: `ConnectAddress` is known at compile time.
        #[allow(clippy::unwrap_used)]
        PeerAddr::from_str("z6MksmpU5b1dS7oaqF2bHXhQi1DWy2hB7Mh9CuN7y1DN6QSz@seed.radicle.xyz:8776")
modified radicle/src/rad.rs
@@ -2,8 +2,8 @@
use std::io;
use std::path::{Path, PathBuf};
use std::str::FromStr;
+
use std::sync::LazyLock;

-
use once_cell::sync::Lazy;
use thiserror::Error;

use crate::cob::ObjectId;
@@ -22,11 +22,13 @@ use crate::storage::{WriteRepository, WriteStorage};
use crate::{identity, storage};

/// Name of the radicle storage remote.
-
pub static REMOTE_NAME: Lazy<git::RefString> = Lazy::new(|| git::refname!("rad"));
+
pub static REMOTE_NAME: LazyLock<git::RefString> = LazyLock::new(|| git::refname!("rad"));
/// Name of the radicle storage remote.
-
pub static REMOTE_COMPONENT: Lazy<git::Component> = Lazy::new(|| git::fmt::name::component!("rad"));
+
pub static REMOTE_COMPONENT: LazyLock<git::Component> =
+
    LazyLock::new(|| git::fmt::name::component!("rad"));
/// Refname used for pushing patches.
-
pub static PATCHES_REFNAME: Lazy<git::RefString> = Lazy::new(|| git::refname!("refs/patches"));
+
pub static PATCHES_REFNAME: LazyLock<git::RefString> =
+
    LazyLock::new(|| git::refname!("refs/patches"));

#[derive(Error, Debug)]
pub enum InitError {
modified radicle/src/storage/git.rs
@@ -5,10 +5,10 @@ pub mod transport;
use std::collections::{BTreeMap, BTreeSet, HashMap};
use std::ops::{Deref, DerefMut};
use std::path::{Path, PathBuf};
+
use std::sync::LazyLock;
use std::{fs, io};

use crypto::Verified;
-
use once_cell::sync::Lazy;
use tempfile::TempDir;

use crate::git::canonical::Canonical;
@@ -33,11 +33,11 @@ pub use crate::storage::{Error, RepositoryError};
use super::refs::RefsAt;
use super::{RemoteId, RemoteRepository, ValidateRepository};

-
pub static NAMESPACES_GLOB: Lazy<git::refspec::PatternString> =
-
    Lazy::new(|| git::refspec::pattern!("refs/namespaces/*"));
-
pub static SIGREFS_GLOB: Lazy<refspec::PatternString> =
-
    Lazy::new(|| git::refspec::pattern!("refs/namespaces/*/rad/sigrefs"));
-
pub static CANONICAL_IDENTITY: Lazy<git::Qualified> = Lazy::new(|| {
+
pub static NAMESPACES_GLOB: LazyLock<git::refspec::PatternString> =
+
    LazyLock::new(|| git::refspec::pattern!("refs/namespaces/*"));
+
pub static SIGREFS_GLOB: LazyLock<refspec::PatternString> =
+
    LazyLock::new(|| git::refspec::pattern!("refs/namespaces/*/rad/sigrefs"));
+
pub static CANONICAL_IDENTITY: LazyLock<git::Qualified> = LazyLock::new(|| {
    git::Qualified::from_components(
        git::name::component!("rad"),
        git::name::component!("id"),
modified radicle/src/storage/git/transport/remote/mock.rs
@@ -2,19 +2,18 @@
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::str::FromStr;
+
use std::sync::LazyLock;
use std::sync::{Mutex, Once};
use std::thread::ThreadId;
use std::{process, thread};

-
use once_cell::sync::Lazy;
-

use super::Url;
use crate::storage::git::transport::ChildStream;
use crate::storage::RemoteId;

/// Nodes registered with the mock transport.
-
static NODES: Lazy<Mutex<HashMap<(ThreadId, RemoteId), PathBuf>>> =
-
    Lazy::new(|| Mutex::new(HashMap::new()));
+
static NODES: LazyLock<Mutex<HashMap<(ThreadId, RemoteId), PathBuf>>> =
+
    LazyLock::new(|| Mutex::new(HashMap::new()));

/// The mock transport.
#[derive(Default)]