diff --git a/radicle/src/git.rs b/radicle/src/git.rs index 06f2721e..f56c8a60 100644 --- a/radicle/src/git.rs +++ b/radicle/src/git.rs @@ -185,6 +185,40 @@ pub mod refs { Qualified::from_components(name::component!("rad"), name::component!("sigrefs"), None) }); + /// The set of special references used in the Heartwood protocol. + #[derive(Clone, Copy, Debug)] + pub enum Special { + /// `rad/id` + Id, + /// `rad/sigrefs` + SignedRefs, + } + + impl From for Qualified<'_> { + fn from(s: Special) -> Self { + match s { + Special::Id => (*IDENTITY_BRANCH).clone(), + Special::SignedRefs => (*SIGREFS_BRANCH).clone(), + } + } + } + + impl Special { + pub fn namespaced<'a>(&self, remote: &PublicKey) -> Namespaced<'a> { + Qualified::from(*self).with_namespace(Component::from(remote)) + } + + pub fn from_qualified(refname: &Qualified) -> Option { + if refname == &*IDENTITY_BRANCH { + Some(Special::Id) + } else if refname == &*SIGREFS_BRANCH { + Some(Special::SignedRefs) + } else { + None + } + } + } + /// Create the [`Namespaced`] `branch` under the `remote` namespace, i.e. /// /// `refs/namespaces//refs/heads/`