Remove Input::direct

This commit is contained in:
Eelco Dolstra 2022-08-10 16:39:25 +02:00
parent dd1dac0f78
commit 4f8b253ea7
3 changed files with 13 additions and 4 deletions

View file

@ -88,6 +88,12 @@ Attrs Input::toAttrs() const
return attrs; return attrs;
} }
bool Input::isDirect() const
{
assert(scheme);
return !scheme || scheme->isDirect(*this);
}
std::optional<CanonPath> Input::isRelative() const std::optional<CanonPath> Input::isRelative() const
{ {
assert(scheme); assert(scheme);

View file

@ -28,7 +28,6 @@ struct Input
std::shared_ptr<InputScheme> scheme; // note: can be null std::shared_ptr<InputScheme> scheme; // note: can be null
Attrs attrs; Attrs attrs;
bool locked = false; bool locked = false;
bool direct = true;
public: public:
static Input fromURL(const std::string & url); static Input fromURL(const std::string & url);
@ -47,7 +46,7 @@ public:
/* Check whether this is a "direct" input, that is, not /* Check whether this is a "direct" input, that is, not
one that goes through a registry. */ one that goes through a registry. */
bool isDirect() const { return direct; } bool isDirect() const;
/* Check whether this is a "locked" input, that is, /* Check whether this is a "locked" input, that is,
one that contains a commit hash or content hash. */ one that contains a commit hash or content hash. */
@ -138,6 +137,9 @@ struct InputScheme
virtual std::pair<ref<InputAccessor>, Input> getAccessor(ref<Store> store, const Input & input) const = 0; virtual std::pair<ref<InputAccessor>, Input> getAccessor(ref<Store> store, const Input & input) const = 0;
virtual bool isDirect(const Input & input) const
{ return true; }
virtual std::optional<CanonPath> isRelative(const Input & input) const virtual std::optional<CanonPath> isRelative(const Input & input) const
{ return std::nullopt; } { return std::nullopt; }

View file

@ -41,7 +41,6 @@ struct IndirectInputScheme : InputScheme
// FIXME: forbid query params? // FIXME: forbid query params?
Input input; Input input;
input.direct = false;
input.attrs.insert_or_assign("type", "indirect"); input.attrs.insert_or_assign("type", "indirect");
input.attrs.insert_or_assign("id", id); input.attrs.insert_or_assign("id", id);
if (rev) input.attrs.insert_or_assign("rev", rev->gitRev()); if (rev) input.attrs.insert_or_assign("rev", rev->gitRev());
@ -63,7 +62,6 @@ struct IndirectInputScheme : InputScheme
throw BadURL("'%s' is not a valid flake ID", id); throw BadURL("'%s' is not a valid flake ID", id);
Input input; Input input;
input.direct = false;
input.attrs = attrs; input.attrs = attrs;
return input; return input;
} }
@ -98,6 +96,9 @@ struct IndirectInputScheme : InputScheme
{ {
throw Error("indirect input '%s' cannot be fetched directly", input.to_string()); throw Error("indirect input '%s' cannot be fetched directly", input.to_string());
} }
bool isDirect(const Input & input) const override
{ return false; }
}; };
static auto rIndirectInputScheme = OnStartup([] { registerInputScheme(std::make_unique<IndirectInputScheme>()); }); static auto rIndirectInputScheme = OnStartup([] { registerInputScheme(std::make_unique<IndirectInputScheme>()); });