Small refactor to avoid optional values

This commit is contained in:
Andrea Bedini 2023-07-14 12:34:20 +08:00 committed by mergify[bot]
parent cc9fa47406
commit ab07651f74

View file

@ -154,12 +154,6 @@ static Value *releaseExprTopLevelValue(EvalState &state, Bindings &autoArgs) {
return vRoot; return vRoot;
} }
Value *topLevelValue(EvalState &state, Bindings &autoArgs,
std::optional<InstallableFlake> flake) {
return flake.has_value() ? flake.value().toValue(state).first
: releaseExprTopLevelValue(state, autoArgs);
}
bool queryIsCached(Store &store, std::map<std::string, std::string> &outputs) { bool queryIsCached(Store &store, std::map<std::string, std::string> &outputs) {
uint64_t downloadSize, narSize; uint64_t downloadSize, narSize;
StorePathSet willBuild, willSubstitute, unknown; StorePathSet willBuild, willSubstitute, unknown;
@ -264,22 +258,25 @@ std::string attrPathJoin(json input) {
static void worker(ref<EvalState> state, Bindings &autoArgs, AutoCloseFD &to, static void worker(ref<EvalState> state, Bindings &autoArgs, AutoCloseFD &to,
AutoCloseFD &from) { AutoCloseFD &from) {
std::optional<InstallableFlake> flake; nix::Value *vRoot = [&]() {
if (myArgs.flake) { if (myArgs.flake) {
auto [flakeRef, fragment, outputSpec] = auto [flakeRef, fragment, outputSpec] =
parseFlakeRefWithFragmentAndExtendedOutputsSpec(myArgs.releaseExpr, parseFlakeRefWithFragmentAndExtendedOutputsSpec(myArgs.releaseExpr,
absPath(".")); absPath("."));
InstallableFlake flake {
flake.emplace(InstallableFlake({}, state, std::move(flakeRef), fragment, {}, state, std::move(flakeRef), fragment,
outputSpec, {}, {}, outputSpec, {}, {},
flake::LockFlags{ flake::LockFlags{
.updateLockFile = false, .updateLockFile = false,
.useRegistries = false, .useRegistries = false,
.allowUnlocked = false, .allowUnlocked = false,
})); }};
};
auto vRoot = topLevelValue(*state, autoArgs, flake); return flake.toValue(*state).first;
} else {
return releaseExprTopLevelValue(*state, autoArgs);
}
}();
while (true) { while (true) {
/* Wait for the collector to send us a job name. */ /* Wait for the collector to send us a job name. */