diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:41:41 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:41:41 +0000 |
commit | 10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87 (patch) | |
tree | bdffd5d80c26cf4a7a518281a204be1ace85b4c1 /vendor/gix-ref/src/namespace.rs | |
parent | Releasing progress-linux version 1.70.0+dfsg1-9~progress7.99u1. (diff) | |
download | rustc-10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87.tar.xz rustc-10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87.zip |
Merging upstream version 1.70.0+dfsg2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gix-ref/src/namespace.rs')
-rw-r--r-- | vendor/gix-ref/src/namespace.rs | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/vendor/gix-ref/src/namespace.rs b/vendor/gix-ref/src/namespace.rs new file mode 100644 index 000000000..2723052ec --- /dev/null +++ b/vendor/gix-ref/src/namespace.rs @@ -0,0 +1,52 @@ +use std::{ + convert::TryInto, + path::{Path, PathBuf}, +}; + +use gix_object::bstr::{BStr, BString, ByteSlice, ByteVec}; + +use crate::{FullName, FullNameRef, Namespace, PartialNameRef}; + +impl Namespace { + /// Dissolve ourselves into the interior representation + pub fn into_bstring(self) -> BString { + self.0 + } + /// Return ourselves as + pub fn as_bstr(&self) -> &BStr { + self.0.as_ref() + } + /// Return ourselves as a path for use within the filesystem. + pub fn to_path(&self) -> &Path { + gix_path::from_byte_slice(&self.0) + } + /// Append the given `prefix` to this namespace so it becomes usable for prefixed iteration. + pub fn into_namespaced_prefix(mut self, prefix: impl AsRef<Path>) -> PathBuf { + let path = prefix.as_ref(); + let prefix = gix_path::into_bstr(path); + self.0.push_str(prefix.as_ref()); + gix_path::to_native_path_on_windows(self.0).into_owned() + } + pub(crate) fn into_namespaced_name(mut self, name: &FullNameRef) -> FullName { + self.0.push_str(name.as_bstr()); + FullName(self.0) + } +} + +/// Given a `namespace` 'foo we output 'refs/namespaces/foo', and given 'foo/bar' we output 'refs/namespaces/foo/refs/namespaces/bar'. +/// +/// For more information, consult the [git namespace documentation](https://git-scm.com/docs/gitnamespaces). +pub fn expand<'a, Name, E>(namespace: Name) -> Result<Namespace, gix_validate::refname::Error> +where + Name: TryInto<&'a PartialNameRef, Error = E>, + gix_validate::refname::Error: From<E>, +{ + let namespace = &namespace.try_into()?.0; + let mut out = BString::default(); + for component in namespace.split_str(b"/") { + out.push_str("refs/namespaces/"); + out.push_str(component); + out.push_str(b"/"); + } + Ok(Namespace(out)) +} |