From 8a27454a9738f077309104fde02d589d052e9f11 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 8 Aug 2024 17:03:28 +0200 Subject: [PATCH 1/2] feat: `remote::Name::to_owned()` to get a static version of it. Also, add optional `serde` support. --- gix/src/remote/mod.rs | 1 + gix/src/remote/name.rs | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/gix/src/remote/mod.rs b/gix/src/remote/mod.rs index a4167ca8588..1a545475479 100644 --- a/gix/src/remote/mod.rs +++ b/gix/src/remote/mod.rs @@ -23,6 +23,7 @@ impl Direction { /// The name of a remote, either interpreted as symbol like `origin` or as url as returned by [`Remote::name()`][crate::Remote::name()]. #[derive(Debug, PartialEq, Eq, Clone, Ord, PartialOrd, Hash)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum Name<'repo> { /// A symbolic name, like `origin`. /// Note that it has not necessarily been validated yet. diff --git a/gix/src/remote/name.rs b/gix/src/remote/name.rs index f0081cc30df..67af8e19ca6 100644 --- a/gix/src/remote/name.rs +++ b/gix/src/remote/name.rs @@ -50,6 +50,14 @@ impl Name<'_> { Name::Symbol(_) => None, } } + + /// Return a fully-owned copy of this instance. + pub fn to_owned(&self) -> Name<'static> { + match self { + Name::Symbol(s) => Name::Symbol(s.clone().into_owned().into()), + Name::Url(s) => Name::Url(s.clone().into_owned().into()), + } + } } impl<'a> TryFrom> for Name<'a> { From 70d835b85ba22669bf9a30b209263181b35b9b40 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 8 Aug 2024 20:23:40 +0200 Subject: [PATCH 2/2] fix: add `serde` support for varous reference name types. --- gix-ref/src/lib.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gix-ref/src/lib.rs b/gix-ref/src/lib.rs index 6059fd2d675..8c35ed35c57 100644 --- a/gix-ref/src/lib.rs +++ b/gix-ref/src/lib.rs @@ -121,12 +121,12 @@ pub(crate) struct Store { inner: store::State, } -/// A validated complete and fully qualified referenced reference name, safe to use for all operations. +/// A validated complete and fully qualified reference name, safe to use for all operations. #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct FullName(pub(crate) BString); -/// A validated complete and fully qualified referenced reference name, safe to use for all operations. +/// A validated complete and fully qualified reference name, safe to use for all operations. #[derive(Hash, Debug, PartialEq, Eq, Ord, PartialOrd)] #[repr(transparent)] pub struct FullNameRef(BStr); @@ -138,10 +138,12 @@ pub struct PartialNameRef(BStr); /// A validated and potentially partial reference name, safe to use for common operations. #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct PartialName(BString); /// A _validated_ prefix for references to act as a namespace. #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Namespace(BString); /// Denotes the kind of reference. @@ -160,6 +162,7 @@ pub enum Kind { /// /// This translates into a prefix containing all references of a given category. #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum Category<'a> { /// A tag in `refs/tags` Tag, @@ -179,6 +182,7 @@ pub enum Category<'a> { /// A `PseudoRef` in another _linked_ worktree, never in the main one, like `worktrees//HEAD`. LinkedPseudoRef { /// The name of the worktree. + #[cfg_attr(feature = "serde", serde(borrow))] name: &'a BStr, }, /// Any reference that is prefixed with `worktrees//refs/`.