1use std::path::{Path, PathBuf};
2
3use gix_object::bstr::{BStr, BString, ByteSlice, ByteVec};
4
5use crate::{FullName, FullNameRef, Namespace, PartialNameRef};
6
7impl Namespace {
8 pub fn into_bstring(self) -> BString {
10 self.0
11 }
12 pub fn as_bstr(&self) -> &BStr {
14 self.0.as_ref()
15 }
16 pub fn to_path(&self) -> &Path {
18 gix_path::from_byte_slice(&self.0)
19 }
20 pub fn into_namespaced_prefix(mut self, prefix: &Path) -> PathBuf {
22 let prefix = gix_path::into_bstr(prefix);
23 self.0.push_str(prefix.as_ref());
24 gix_path::to_native_path_on_windows(self.0).into_owned()
25 }
26 pub(crate) fn into_namespaced_name(mut self, name: &FullNameRef) -> FullName {
27 self.0.push_str(name.as_bstr());
28 FullName(self.0)
29 }
30}
31
32pub fn expand<'a, Name, E>(namespace: Name) -> Result<Namespace, gix_validate::reference::name::Error>
36where
37 Name: TryInto<&'a PartialNameRef, Error = E>,
38 gix_validate::reference::name::Error: From<E>,
39{
40 let namespace = &namespace.try_into()?.0;
41 let mut out = BString::default();
42 for component in namespace.split_str(b"/") {
43 out.push_str("refs/namespaces/");
44 out.push_str(component);
45 out.push_str(b"/");
46 }
47 Ok(Namespace(out))
48}