Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove HashType::htUnknown #3650

Merged
merged 16 commits into from Jun 19, 2020
Merged

Conversation

Ericson2314
Copy link
Member

@Ericson2314 Ericson2314 commented Jun 2, 2020

Instead, Hash uses std::optional<HashType>. In the future, we may
also make Hash itself require a known hash type, encouraging people to
use std::optional<Hash> instead.

#3453 makes most of the noise.

Ericson2314 and others added 6 commits March 29, 2020 11:23
This does a few enums; the rest will be gotten in subsequent commits.
Instead, `Hash` uses `std::optional<HashType>`. In the future, we may
also make `Hash` itself require a known hash type, encoraging people to
use `std::optional<Hash>` instead.
A valid hash type must be provided now. The hash itself can still be
invalid, but that doesn't cause an `abort()`.
@Ericson2314 Ericson2314 changed the title Remove HashType::Unknown -- contains #3453 WIP: Remove HashType::Unknown -- contains #3453 Jun 2, 2020
@Ericson2314 Ericson2314 changed the title WIP: Remove HashType::Unknown -- contains #3453 Remove HashType::Unknown -- contains #3453 Jun 2, 2020
@Ericson2314
Copy link
Member Author

Whew! got it working.

@Ericson2314 Ericson2314 changed the title Remove HashType::Unknown -- contains #3453 Remove HashType::Unknown Jun 18, 2020
Hash h(ht);
warn("found empty hash, assuming '%s'", h.to_string(SRI, true));
if (!ht)
throw BadHash("empty hash requires explicit hash type");
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a new validation, actually. I think we want it.

CC @matthewbauer

Copy link
Member

Choose a reason for hiding this comment

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

it's okay if hash type is unset - you just have to have sri in your string

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah this is just in the empty string case, when the SRI or legacy prefix can't help.

@Ericson2314
Copy link
Member Author

@edolstra OK this not longer contains the enum struct change, and so much more value per diff.

CC @zimbatm

@matthewbauer
Copy link
Member

How is std::optional better than HashType::Unknown? They seem like two ways to represent the same thing to me.

@Ericson2314
Copy link
Member Author

@matthewbauer Well the std::optional isn't used on every hash type. I am purposefully being cautious in this PR, but with the idea that if this is OK it becomes much easier and more incremental to start chipping away at the rest of the std::optional. In particular I mention in the OP about removing it from the definition of Hash and using std::optional<Hash> instead.

@Ericson2314 Ericson2314 changed the title Remove HashType::Unknown Remove HashType::htUnknown Jun 19, 2020
@edolstra edolstra merged commit 984e521 into NixOS:master Jun 19, 2020
@Ericson2314 Ericson2314 deleted the no-hash-type-unknown branch June 19, 2020 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants