Merge pull request #9198 from edolstra/remove-direct

Input: Remove 'direct' field
This commit is contained in:
Eelco Dolstra 2023-10-20 19:49:53 +02:00 committed by GitHub
commit 091e5b4513
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 4 deletions

View file

@ -84,6 +84,11 @@ std::string Input::to_string() const
return toURL().to_string(); return toURL().to_string();
} }
bool Input::isDirect() const
{
return !scheme || scheme->isDirect(*this);
}
Attrs Input::toAttrs() const Attrs Input::toAttrs() const
{ {
return attrs; return attrs;

View file

@ -35,7 +35,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;
/** /**
* path of the parent of this input, used for relative path resolution * path of the parent of this input, used for relative path resolution
@ -71,7 +70,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,
@ -152,6 +151,9 @@ struct InputScheme
* Is this `InputScheme` part of an experimental feature? * Is this `InputScheme` part of an experimental feature?
*/ */
virtual std::optional<ExperimentalFeature> experimentalFeature(); virtual std::optional<ExperimentalFeature> experimentalFeature();
virtual bool isDirect(const Input & input) const
{ return true; }
}; };
void registerInputScheme(std::shared_ptr<InputScheme> && fetcher); void registerInputScheme(std::shared_ptr<InputScheme> && fetcher);

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
{ {
return Xp::Flakes; return Xp::Flakes;
} }
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>()); });