Skip to content

Conversation

@alilleybrinker
Copy link
Member

This commit adds the ability to try to construct a GitOid from a url::Url by parsing the parts of the Url to ensure they contain all the required data, and then constructing a GitOid if they do.

This includes additions to enable parsing ObjectType and HashAlgorithm from a string slice, plus new error variants (with either String or Box<Url> fields) to represent different modes of failure for parsing.

This commit also renames GitOid::uri to GitOid::url.

The new name is a more-specific explanation of what we're dealing with, and matches the type returned (url::Url). This change also makes GitOid::url consistent with GitOid::new_from_url. I also added new tests to validate that the correct errors are produced for different types of invalid Urls.

Signed-off-by: Andrew Lilley Brinker alilleybrinker@gmail.com

This commit adds the ability to try to construct a `GitOid` from
a `url::Url` by parsing the parts of the `Url` to ensure they
contain all the required data, and then constructing a `GitOid`
if they do.

This includes additions to enable parsing `ObjectType` and
`HashAlgorithm` from a string slice, plus new error variants
(with either `String` or `Box<Url>` fields) to represent different
modes of failure for parsing.

This commit also renames `GitOid::uri` to `GitOid::url`.

The new name is a more-specific explanation of what we're dealing
with, and matches the type returned (`url::Url`). This change
also makes `GitOid::url` consistent with `GitOid::new_from_url`.
I also added new tests to validate that the correct errors are
produced for different types of invalid `Url`s.

Signed-off-by: Andrew Lilley Brinker <alilleybrinker@gmail.com>
@alilleybrinker alilleybrinker added type: feature New feature or request crate: gitoid Relating to the gitoid crate labels Sep 23, 2022
This commit removes the boxing around `Url` in some error
variants. I'd added that when I was expecting the error variants
might be much larger than the others, but I don't really think
it's an issue now, so removing the boxing is preferable.

Signed-off-by: Andrew Lilley Brinker <alilleybrinker@gmail.com>
Copy link
Collaborator

@nellshamrell nellshamrell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! I always love getting a code contribution that I learn new things from (I may have been aware of the eprintln macro to io::stderr at some point, but it had escaped my memory and I'm glad to have it there again!) I also appreciate how you thought through the various potential error situation and created custom error text for them. There will likely be more that we discover, and this sets up a great foundation for adding them.

/// The expected and actual length of the data being read didn't
/// match, indicating something has likely gone wrong.
BadLength { expected: usize, actual: usize },
/// Tried to construct a `GitOid` from a `Url` with a scheme besides `gitoid`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate all these error variations!

@nellshamrell
Copy link
Collaborator

Merging and cutting a release :)

@nellshamrell nellshamrell merged commit bb6ac79 into omnibor:main Sep 29, 2022
@alilleybrinker alilleybrinker deleted the feat/gitoid_from_url branch December 6, 2022 02:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

crate: gitoid Relating to the gitoid crate type: feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants