From a8bc0de6d071be82364434b6e27afecc02f3be51 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Fri, 4 Aug 2023 16:54:11 +0200 Subject: [PATCH] adjust to changes in `gix-validate` --- gix-ref/src/fullname.rs | 22 ++++++++++--------- gix-ref/src/namespace.rs | 4 ++-- .../src/store/file/loose/reference/decode.rs | 20 +++++++++-------- gix-ref/tests/namespace/mod.rs | 10 ++++----- gix-refspec/src/parse.rs | 2 +- gix-refspec/tests/parse/invalid.rs | 2 +- gix/src/clone/fetch/mod.rs | 2 +- gix/src/init.rs | 2 +- .../connection/fetch/update_refs/update.rs | 2 +- gix/src/repository/reference.rs | 4 ++-- 10 files changed, 37 insertions(+), 33 deletions(-) diff --git a/gix-ref/src/fullname.rs b/gix-ref/src/fullname.rs index 257bbe0602b..d1533e1900e 100644 --- a/gix-ref/src/fullname.rs +++ b/gix-ref/src/fullname.rs @@ -5,44 +5,46 @@ use gix_object::bstr::{BStr, BString, ByteSlice}; use crate::{bstr::ByteVec, name::is_pseudo_ref, Category, FullName, FullNameRef, Namespace, PartialNameRef}; impl TryFrom<&str> for FullName { - type Error = gix_validate::refname::Error; + type Error = gix_validate::reference::name::Error; fn try_from(value: &str) -> Result { - Ok(FullName(gix_validate::refname(value.as_bytes().as_bstr())?.into())) + Ok(FullName( + gix_validate::reference::name(value.as_bytes().as_bstr())?.into(), + )) } } impl TryFrom for FullName { - type Error = gix_validate::refname::Error; + type Error = gix_validate::reference::name::Error; fn try_from(value: String) -> Result { - gix_validate::refname(value.as_bytes().as_bstr())?; + gix_validate::reference::name(value.as_bytes().as_bstr())?; Ok(FullName(value.into())) } } impl TryFrom<&BStr> for FullName { - type Error = gix_validate::refname::Error; + type Error = gix_validate::reference::name::Error; fn try_from(value: &BStr) -> Result { - Ok(FullName(gix_validate::refname(value)?.into())) + Ok(FullName(gix_validate::reference::name(value)?.into())) } } impl TryFrom for FullName { - type Error = gix_validate::refname::Error; + type Error = gix_validate::reference::name::Error; fn try_from(value: BString) -> Result { - gix_validate::refname(value.as_ref())?; + gix_validate::reference::name(value.as_ref())?; Ok(FullName(value)) } } impl TryFrom<&BString> for FullName { - type Error = gix_validate::refname::Error; + type Error = gix_validate::reference::name::Error; fn try_from(value: &BString) -> Result { - gix_validate::refname(value.as_ref())?; + gix_validate::reference::name(value.as_ref())?; Ok(FullName(value.clone())) } } diff --git a/gix-ref/src/namespace.rs b/gix-ref/src/namespace.rs index 2723052ec22..ff0e80624c3 100644 --- a/gix-ref/src/namespace.rs +++ b/gix-ref/src/namespace.rs @@ -36,10 +36,10 @@ impl Namespace { /// 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 +pub fn expand<'a, Name, E>(namespace: Name) -> Result where Name: TryInto<&'a PartialNameRef, Error = E>, - gix_validate::refname::Error: From, + gix_validate::reference::name::Error: From, { let namespace = &namespace.try_into()?.0; let mut out = BString::default(); diff --git a/gix-ref/src/store/file/loose/reference/decode.rs b/gix-ref/src/store/file/loose/reference/decode.rs index 9bf2f7c29ef..ece14bb484c 100644 --- a/gix-ref/src/store/file/loose/reference/decode.rs +++ b/gix-ref/src/store/file/loose/reference/decode.rs @@ -39,15 +39,17 @@ impl TryFrom for Target { fn try_from(v: MaybeUnsafeState) -> Result { Ok(match v { MaybeUnsafeState::Id(id) => Target::Peeled(id), - MaybeUnsafeState::UnvalidatedPath(name) => Target::Symbolic(match gix_validate::refname(name.as_ref()) { - Ok(_) => FullName(name), - Err(err) => { - return Err(Error::RefnameValidation { - source: err, - path: name, - }) - } - }), + MaybeUnsafeState::UnvalidatedPath(name) => { + Target::Symbolic(match gix_validate::reference::name(name.as_ref()) { + Ok(_) => FullName(name), + Err(err) => { + return Err(Error::RefnameValidation { + source: err, + path: name, + }) + } + }) + } }) } } diff --git a/gix-ref/tests/namespace/mod.rs b/gix-ref/tests/namespace/mod.rs index 649af64bb27..dde96d08692 100644 --- a/gix-ref/tests/namespace/mod.rs +++ b/gix-ref/tests/namespace/mod.rs @@ -31,7 +31,7 @@ mod expand { fn backslashes_are_no_component_separators_and_invalid() { assert!(matches!( gix_ref::namespace::expand("foo\\bar").expect_err("empty invalid"), - gix_validate::refname::Error::Tag( + gix_validate::reference::name::Error::Tag( gix_validate::tag::name::Error::InvalidByte{byte} ) if byte == "\\" )); @@ -41,7 +41,7 @@ mod expand { fn trailing_slashes_are_not_allowed() { assert!(matches!( gix_ref::namespace::expand("foo/").expect_err("empty invalid"), - gix_validate::refname::Error::Tag(gix_validate::tag::name::Error::EndsWithSlash) + gix_validate::reference::name::Error::Tag(gix_validate::tag::name::Error::EndsWithSlash) )); } @@ -49,21 +49,21 @@ mod expand { fn empty_namespaces_are_not_allowed() { assert!(matches!( gix_ref::namespace::expand("").expect_err("empty invalid"), - gix_validate::refname::Error::Tag(gix_validate::tag::name::Error::Empty) + gix_validate::reference::name::Error::Tag(gix_validate::tag::name::Error::Empty) )); } #[test] fn bare_slashes_are_not_allowed() { assert!(matches!( gix_ref::namespace::expand("/").expect_err("empty invalid"), - gix_validate::refname::Error::Tag(gix_validate::tag::name::Error::EndsWithSlash) + gix_validate::reference::name::Error::Tag(gix_validate::tag::name::Error::EndsWithSlash) )); } #[test] fn repeated_slashes_are_invalid() { assert!(matches!( gix_ref::namespace::expand("foo//bar").expect_err("empty invalid"), - gix_validate::refname::Error::RepeatedSlash + gix_validate::reference::name::Error::RepeatedSlash )); } } diff --git a/gix-refspec/src/parse.rs b/gix-refspec/src/parse.rs index 0e8ca852c2f..bba5c69ad9b 100644 --- a/gix-refspec/src/parse.rs +++ b/gix-refspec/src/parse.rs @@ -25,7 +25,7 @@ pub enum Error { #[error("Both sides of the specification need a pattern, like 'a/*:b/*'")] PatternUnbalanced, #[error(transparent)] - ReferenceName(#[from] gix_validate::refname::Error), + ReferenceName(#[from] gix_validate::reference::name::Error), #[error(transparent)] RevSpec(#[from] gix_revision::spec::parse::Error), } diff --git a/gix-refspec/tests/parse/invalid.rs b/gix-refspec/tests/parse/invalid.rs index 0a7c1ba5aa4..fec09aa96eb 100644 --- a/gix-refspec/tests/parse/invalid.rs +++ b/gix-refspec/tests/parse/invalid.rs @@ -11,7 +11,7 @@ fn empty() { fn empty_component() { assert!(matches!( try_parse("refs/heads/test:refs/remotes//test", Operation::Fetch).unwrap_err(), - Error::ReferenceName(gix_validate::refname::Error::RepeatedSlash) + Error::ReferenceName(gix_validate::reference::name::Error::RepeatedSlash) )); } diff --git a/gix/src/clone/fetch/mod.rs b/gix/src/clone/fetch/mod.rs index e20cc96cb42..227281eb463 100644 --- a/gix/src/clone/fetch/mod.rs +++ b/gix/src/clone/fetch/mod.rs @@ -26,7 +26,7 @@ pub enum Error { SaveConfigIo(#[from] std::io::Error), #[error("The remote HEAD points to a reference named {head_ref_name:?} which is invalid.")] InvalidHeadRef { - source: gix_validate::refname::Error, + source: gix_validate::reference::name::Error, head_ref_name: crate::bstr::BString, }, #[error("Failed to update HEAD with values from remote")] diff --git a/gix/src/init.rs b/gix/src/init.rs index d04de080670..bffd5fc5b8f 100644 --- a/gix/src/init.rs +++ b/gix/src/init.rs @@ -29,7 +29,7 @@ pub enum Error { #[error("Invalid default branch name: {name:?}")] InvalidBranchName { name: BString, - source: gix_validate::refname::Error, + source: gix_validate::reference::name::Error, }, #[error("Could not edit HEAD reference with new default name")] EditHeadForDefaultBranch(#[from] crate::reference::edit::Error), diff --git a/gix/src/remote/connection/fetch/update_refs/update.rs b/gix/src/remote/connection/fetch/update_refs/update.rs index 7e31effab61..41ed3753d68 100644 --- a/gix/src/remote/connection/fetch/update_refs/update.rs +++ b/gix/src/remote/connection/fetch/update_refs/update.rs @@ -10,7 +10,7 @@ mod error { #[error(transparent)] FindReference(#[from] crate::reference::find::Error), #[error("A remote reference had a name that wasn't considered valid. Corrupt remote repo or insufficient checks on remote?")] - InvalidRefName(#[from] gix_validate::refname::Error), + InvalidRefName(#[from] gix_validate::reference::name::Error), #[error("Failed to update references to their new position to match their remote locations")] EditReferences(#[from] crate::reference::edit::Error), #[error("Failed to read or iterate worktree dir")] diff --git a/gix/src/repository/reference.rs b/gix/src/repository/reference.rs index 7d37f4f9c0f..d34c790879f 100644 --- a/gix/src/repository/reference.rs +++ b/gix/src/repository/reference.rs @@ -60,10 +60,10 @@ impl crate::Repository { pub fn set_namespace<'a, Name, E>( &mut self, namespace: Name, - ) -> Result, gix_validate::refname::Error> + ) -> Result, gix_validate::reference::name::Error> where Name: TryInto<&'a PartialNameRef, Error = E>, - gix_validate::refname::Error: From, + gix_validate::reference::name::Error: From, { let namespace = gix_ref::namespace::expand(namespace)?; Ok(self.refs.namespace.replace(namespace))