nix flake info --json: Get rid of duplicate getFlake() call

Also fix some gcc warnings.
This commit is contained in:
Eelco Dolstra 2019-09-22 21:53:01 +02:00
parent 893be6f5e3
commit 382aa05ff7
2 changed files with 14 additions and 12 deletions

View file

@ -174,11 +174,12 @@ static void enumerateOutputs(EvalState & state, Value & vFlake,
{ {
state.forceAttrs(vFlake); state.forceAttrs(vFlake);
auto vOutputs = (*vFlake.attrs->get(state.symbols.create("outputs")))->value; auto aOutputs = vFlake.attrs->get(state.symbols.create("outputs"));
assert(aOutputs);
state.forceAttrs(*vOutputs); state.forceAttrs(*(*aOutputs)->value);
for (auto & attr : *vOutputs->attrs) for (auto & attr : *((*aOutputs)->value->attrs))
callback(attr.name, *attr.value, *attr.pos); callback(attr.name, *attr.value, *attr.pos);
} }
@ -191,15 +192,12 @@ struct CmdFlakeInfo : FlakeCommand, MixJSON
void run(nix::ref<nix::Store> store) override void run(nix::ref<nix::Store> store) override
{ {
auto flake = getFlake();
stopProgressBar();
if (json) { if (json) {
auto json = flakeToJson(flake);
auto state = getEvalState(); auto state = getEvalState();
auto flake = resolveFlake(); auto flake = resolveFlake();
auto json = flakeToJson(flake.flake);
auto vFlake = state->allocValue(); auto vFlake = state->allocValue();
flake::callFlake(*state, flake, *vFlake); flake::callFlake(*state, flake, *vFlake);
@ -222,8 +220,11 @@ struct CmdFlakeInfo : FlakeCommand, MixJSON
json["outputs"] = std::move(outputs); json["outputs"] = std::move(outputs);
std::cout << json.dump() << std::endl; std::cout << json.dump() << std::endl;
} else } else {
auto flake = getFlake();
stopProgressBar();
printFlakeInfo(flake); printFlakeInfo(flake);
}
} }
}; };

View file

@ -291,11 +291,12 @@ struct InstallableFlake : InstallableValue
makeFlakeClosureGCRoot(*state.store, flakeRef, resFlake); makeFlakeClosureGCRoot(*state.store, flakeRef, resFlake);
auto vOutputs = (*vFlake->attrs->get(state.symbols.create("outputs")))->value; auto aOutputs = vFlake->attrs->get(state.symbols.create("outputs"));
assert(aOutputs);
state.forceValue(*vOutputs); state.forceValue(*(*aOutputs)->value);
return vOutputs; return (*aOutputs)->value;
} }
std::vector<flake::EvalCache::Derivation> toDerivations() override std::vector<flake::EvalCache::Derivation> toDerivations() override