Skip to content

Commit

Permalink
adjust to changes in gix-validate
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Aug 4, 2023
1 parent a9da3f8 commit a8bc0de
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 33 deletions.
22 changes: 12 additions & 10 deletions gix-ref/src/fullname.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self, Self::Error> {
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<String> for FullName {
type Error = gix_validate::refname::Error;
type Error = gix_validate::reference::name::Error;

fn try_from(value: String) -> Result<Self, Self::Error> {
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<Self, Self::Error> {
Ok(FullName(gix_validate::refname(value)?.into()))
Ok(FullName(gix_validate::reference::name(value)?.into()))
}
}

impl TryFrom<BString> for FullName {
type Error = gix_validate::refname::Error;
type Error = gix_validate::reference::name::Error;

fn try_from(value: BString) -> Result<Self, Self::Error> {
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<Self, Self::Error> {
gix_validate::refname(value.as_ref())?;
gix_validate::reference::name(value.as_ref())?;
Ok(FullName(value.clone()))
}
}
Expand Down
4 changes: 2 additions & 2 deletions gix-ref/src/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Namespace, gix_validate::refname::Error>
pub fn expand<'a, Name, E>(namespace: Name) -> Result<Namespace, gix_validate::reference::name::Error>
where
Name: TryInto<&'a PartialNameRef, Error = E>,
gix_validate::refname::Error: From<E>,
gix_validate::reference::name::Error: From<E>,
{
let namespace = &namespace.try_into()?.0;
let mut out = BString::default();
Expand Down
20 changes: 11 additions & 9 deletions gix-ref/src/store/file/loose/reference/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,17 @@ impl TryFrom<MaybeUnsafeState> for Target {
fn try_from(v: MaybeUnsafeState) -> Result<Self, Self::Error> {
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,
})
}
})
}
})
}
}
Expand Down
10 changes: 5 additions & 5 deletions gix-ref/tests/namespace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "\\"
));
Expand All @@ -41,29 +41,29 @@ 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)
));
}

#[test]
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
));
}
}
2 changes: 1 addition & 1 deletion gix-refspec/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down
2 changes: 1 addition & 1 deletion gix-refspec/tests/parse/invalid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
));
}

Expand Down
2 changes: 1 addition & 1 deletion gix/src/clone/fetch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
2 changes: 1 addition & 1 deletion gix/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion gix/src/remote/connection/fetch/update_refs/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
4 changes: 2 additions & 2 deletions gix/src/repository/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ impl crate::Repository {
pub fn set_namespace<'a, Name, E>(
&mut self,
namespace: Name,
) -> Result<Option<gix_ref::Namespace>, gix_validate::refname::Error>
) -> Result<Option<gix_ref::Namespace>, gix_validate::reference::name::Error>
where
Name: TryInto<&'a PartialNameRef, Error = E>,
gix_validate::refname::Error: From<E>,
gix_validate::reference::name::Error: From<E>,
{
let namespace = gix_ref::namespace::expand(namespace)?;
Ok(self.refs.namespace.replace(namespace))
Expand Down

0 comments on commit a8bc0de

Please sign in to comment.