Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
git-ref-format: New crate
Lorenz Leutgeb committed 7 months ago
commit 2c09fdc8cd0a064aa4c0848c0b4506bee76e3332
parent 5caa7b302a7d4f247aaa7cc688a692aac4486464
5 files changed +162 -0
modified Cargo.lock
@@ -2951,6 +2951,13 @@ dependencies = [
]

[[package]]
+
name = "radicle-git-ref-format"
+
version = "0.1.0"
+
dependencies = [
+
 "git-ref-format-core",
+
]
+

+
[[package]]
name = "radicle-node"
version = "0.15.0"
dependencies = [
modified Cargo.toml
@@ -48,6 +48,7 @@ radicle-crypto = { version = "0.13", path = "crates/radicle-crypto" }
radicle-dag = { version = "0.10", path = "crates/radicle-dag" }
radicle-fetch = { version = "0.15", path = "crates/radicle-fetch" }
radicle-git-ext = { version = "0.8", default-features = false }
+
radicle-git-ref-format = { version = "0.1.0", path = "crates/radicle-git-ref-format", default-features = false }
radicle-node = { version = "0.15", path = "crates/radicle-node" }
radicle-protocol = { version = "0.3", path = "crates/radicle-protocol" }
radicle-signals = { version = "0.11", path = "crates/radicle-signals" }
added crates/radicle-git-ref-format/Cargo.toml
@@ -0,0 +1,16 @@
+
[package]
+
name = "radicle-git-ref-format"
+
description = "Radicle re-exports and macros for `git-ref-format-core`"
+
homepage.workspace = true
+
repository.workspace = true
+
version = "0.1.0"
+
edition.workspace = true
+
license.workspace = true
+
keywords = ["radicle", "git", "refname", "ref", "references"]
+
rust-version.workspace = true
+

+
[features]
+
macro = []
+

+
[dependencies]
+
git-ref-format-core = { version = "0.3.0", default-features = false }

\ No newline at end of file
added crates/radicle-git-ref-format/src/lib.rs
@@ -0,0 +1,21 @@
+
#[cfg(feature = "macro")]
+
#[macro_use]
+
mod r#macro;
+

+
pub use git_ref_format_core::{lit, Component, Error, Namespaced, Qualified, RefStr, RefString};
+

+
pub mod name {
+
    pub use git_ref_format_core::name::{HEADS, NOTES, TAGS};
+

+
    #[cfg(feature = "macro")]
+
    pub use crate::name__component as component;
+
}
+

+
pub mod refspec {
+
    pub use git_ref_format_core::refspec::{
+
        Component, PatternStr, PatternString, QualifiedPattern, Refspec, STAR,
+
    };
+

+
    #[cfg(feature = "macro")]
+
    pub use crate::{refspec__pattern as pattern, refspec__qualified_pattern as qualified_pattern};
+
}
added crates/radicle-git-ref-format/src/macro.rs
@@ -0,0 +1,117 @@
+
#[doc(hidden)]
+
#[macro_export]
+
macro_rules! refname {
+
    ($arg:literal) => {{
+
        use std::concat;
+
        use std::mem::transmute;
+
        use $crate::RefString;
+

+
        #[cfg(debug_assertions)]
+
        RefString::try_from($arg).expect(concat!(
+
            "literal '",
+
            $arg,
+
            "' is not a valid reference name"
+
        ));
+

+
        unsafe { transmute::<String, RefString>($arg.to_owned()) }
+
    }};
+
}
+

+
#[doc(hidden)]
+
#[macro_export]
+
macro_rules! qualified {
+
    ($arg:literal) => {{
+
        use std::borrow::Cow;
+
        use std::concat;
+
        use std::mem::transmute;
+
        use $crate::{Qualified, RefStr, RefString};
+

+
        #[cfg(debug_assertions)]
+
        Qualified::from_refstr(unsafe {
+
            transmute::<Cow<'_, str>, Cow<'_, RefStr>>(Cow::Borrowed($arg))
+
        })
+
        .expect(concat!(
+
            "literal '",
+
            $arg,
+
            "' is not of the form 'refs/<category>/<name>'"
+
        ));
+

+
        unsafe {
+
            transmute::<Cow<'static, RefStr>, Qualified>(Cow::Owned(
+
                transmute::<String, RefString>($arg.to_owned()),
+
            ))
+
        }
+
    }};
+
}
+

+
#[doc(hidden)]
+
#[macro_export]
+
macro_rules! name__component {
+
    ($arg:literal) => {{
+
        use std::borrow::Cow;
+
        use std::concat;
+
        use std::mem::transmute;
+
        use $crate::{Component, RefStr, RefString};
+

+
        #[cfg(debug_assertions)]
+
        Into::<Option<Component>>::into(RefStr::try_from_str($arg).expect(concat!(
+
            "literal '",
+
            $arg,
+
            "' must be valid component"
+
        )))
+
        .expect(concat!(
+
            "literal '",
+
            $arg,
+
            "' must be a valid component (cannot contain '/')"
+
        ));
+

+
        unsafe {
+
            transmute::<Cow<'static, RefStr>, Component>(Cow::Owned(
+
                transmute::<String, RefString>($arg.to_owned()),
+
            ))
+
        }
+
    }};
+
}
+

+
#[doc(hidden)]
+
#[macro_export]
+
macro_rules! refspec__pattern {
+
    ($arg:literal) => {{
+
        use std::concat;
+
        use std::mem::transmute;
+
        use $crate::refspec::{PatternStr, PatternString};
+

+
        #[cfg(debug_assertions)]
+
        PatternStr::try_from_str($arg).expect(concat!(
+
            "literal '",
+
            $arg,
+
            "' must be valid refspec pattern"
+
        ));
+

+
        unsafe { transmute::<String, PatternString>($arg.to_owned()) }
+
    }};
+
}
+

+
#[doc(hidden)]
+
#[macro_export]
+
macro_rules! refspec__qualified_pattern {
+
    ($arg:literal) => {{
+
        use std::concat;
+
        use std::mem::transmute;
+
        use $crate::refspec::{PatternStr, QualifiedPattern};
+

+
        #[cfg(debug_assertions)]
+
        QualifiedPattern::from_patternstr(PatternStr::try_from_str($arg).expect(concat!(
+
            "literal '",
+
            $arg,
+
            "' must be valid refspec pattern"
+
        )))
+
        .expect(concat!(
+
            "literal '",
+
            $arg,
+
            "' must be a valid qualified refspec pattern"
+
        ));
+

+
        unsafe { transmute::<String, QualifiedPattern>($arg.to_owned()) }
+
    }};
+
}