Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions gix-ref/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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.
Expand All @@ -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,
Expand All @@ -179,6 +182,7 @@ pub enum Category<'a> {
/// A `PseudoRef` in another _linked_ worktree, never in the main one, like `worktrees/<id>/HEAD`.
LinkedPseudoRef {
/// The name of the worktree.
#[cfg_attr(feature = "serde", serde(borrow))]
name: &'a BStr,
},
/// Any reference that is prefixed with `worktrees/<id>/refs/`.
Expand Down
1 change: 1 addition & 0 deletions gix/src/remote/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions gix/src/remote/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Cow<'a, BStr>> for Name<'a> {
Expand Down