Simplify lockFlake() a bit

This commit is contained in:
Eelco Dolstra 2021-11-15 18:44:27 +01:00
parent d1d223838b
commit 671817a858

View file

@ -446,24 +446,18 @@ LockedFlake lockFlake(
update it. */ update it. */
auto lb = lockFlags.inputUpdates.lower_bound(inputPath); auto lb = lockFlags.inputUpdates.lower_bound(inputPath);
auto hasChildUpdate = auto mustRefetch =
lb != lockFlags.inputUpdates.end() lb != lockFlags.inputUpdates.end()
&& lb->size() > inputPath.size() && lb->size() > inputPath.size()
&& std::equal(inputPath.begin(), inputPath.end(), lb->begin()); && std::equal(inputPath.begin(), inputPath.end(), lb->begin());
if (hasChildUpdate) { FlakeInputs fakeInputs;
auto inputFlake = getFlake(
state, oldLock->lockedRef, false, flakeCache); if (!mustRefetch) {
computeLocks(inputFlake.inputs, childNode, inputPath, oldLock, parent, parentPath);
} else {
/* No need to fetch this flake, we can be /* No need to fetch this flake, we can be
lazy. However there may be new overrides on the lazy. However there may be new overrides on the
inputs of this flake, so we need to check inputs of this flake, so we need to check
those. */ those. */
FlakeInputs fakeInputs;
bool refetch = false;
for (auto & i : oldLock->inputs) { for (auto & i : oldLock->inputs) {
if (auto lockedNode = std::get_if<0>(&i.second)) { if (auto lockedNode = std::get_if<0>(&i.second)) {
fakeInputs.emplace(i.first, FlakeInput { fakeInputs.emplace(i.first, FlakeInput {
@ -475,7 +469,7 @@ LockedFlake lockFlake(
// If the override disappeared, we have to refetch the flake, // If the override disappeared, we have to refetch the flake,
// since some of the inputs may not be present in the lockfile. // since some of the inputs may not be present in the lockfile.
if (o == input.overrides.end()) { if (o == input.overrides.end()) {
refetch = true; mustRefetch = true;
// There's no point populating the rest of the fake inputs, // There's no point populating the rest of the fake inputs,
// since we'll refetch the flake anyways. // since we'll refetch the flake anyways.
break; break;
@ -485,13 +479,14 @@ LockedFlake lockFlake(
}); });
} }
} }
if (refetch)
fakeInputs = getFlake(state, oldLock->lockedRef, false, flakeCache).inputs;
computeLocks(fakeInputs, childNode, inputPath, oldLock, parent, parentPath);
} }
computeLocks(
mustRefetch
? getFlake(state, oldLock->lockedRef, false, flakeCache).inputs
: fakeInputs,
childNode, inputPath, oldLock, parent, parentPath);
} else { } else {
/* We need to create a new lock file entry. So fetch /* We need to create a new lock file entry. So fetch
this input. */ this input. */