Skip to content

Commit

Permalink
Rename argument "final" to "result" to avoid ambiguity
Browse files Browse the repository at this point in the history
  • Loading branch information
edolstra committed Nov 6, 2024
1 parent 0401e27 commit b7882d5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
60 changes: 30 additions & 30 deletions src/libfetchers/fetchers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -178,24 +178,24 @@ std::pair<StorePath, Input> Input::fetchToStore(ref<Store> store) const

auto [storePath, input] = [&]() -> std::pair<StorePath, Input> {
try {
auto [accessor, final] = getAccessorUnchecked(store);
auto [accessor, result] = getAccessorUnchecked(store);

auto storePath = nix::fetchToStore(*store, SourcePath(accessor), FetchMode::Copy, final.getName());
auto storePath = nix::fetchToStore(*store, SourcePath(accessor), FetchMode::Copy, result.getName());

auto narHash = store->queryPathInfo(storePath)->narHash;
final.attrs.insert_or_assign("narHash", narHash.to_string(HashFormat::SRI, true));
result.attrs.insert_or_assign("narHash", narHash.to_string(HashFormat::SRI, true));

// FIXME: we would like to mark inputs as final in
// getAccessorUnchecked(), but then we can't add
// narHash. Or maybe narHash should be excluded from the
// concept of "final" inputs?
final.attrs.insert_or_assign("__final", Explicit<bool>(true));
result.attrs.insert_or_assign("__final", Explicit<bool>(true));

assert(final.isFinal());
assert(result.isFinal());

checkLocks(*this, final);
checkLocks(*this, result);

return {storePath, final};
return {storePath, result};
} catch (Error & e) {
e.addTrace({}, "while fetching the input '%s'", to_string());
throw;
Expand All @@ -205,12 +205,12 @@ std::pair<StorePath, Input> Input::fetchToStore(ref<Store> store) const
return {std::move(storePath), input};
}

void Input::checkLocks(Input specified, Input & final)
void Input::checkLocks(Input specified, Input & result)
{
/* If the original input is final, then we just return the
original attributes, dropping any new fields returned by the
fetcher. However, any fields that are in both the original and
final input must be identical. */
fetcher. However, any fields that are in both the specified and
result input must be identical. */
if (specified.isFinal()) {

/* Backwards compatibility hack: we had some lock files in the
Expand All @@ -221,57 +221,57 @@ void Input::checkLocks(Input specified, Input & final)
specified.attrs.insert_or_assign("narHash", prevNarHash->to_string(HashFormat::SRI, true));

for (auto & field : specified.attrs) {
auto field2 = final.attrs.find(field.first);
if (field2 != final.attrs.end() && field.second != field2->second)
throw Error("mismatch in field '%s' of final input '%s', got '%s'",
auto field2 = result.attrs.find(field.first);
if (field2 != result.attrs.end() && field.second != field2->second)
throw Error("mismatch in field '%s' of input '%s', got '%s'",
field.first,
attrsToJSON(specified.attrs),
attrsToJSON(final.attrs));
attrsToJSON(result.attrs));
}

final.attrs = specified.attrs;
result.attrs = specified.attrs;

return;
}

if (auto prevNarHash = specified.getNarHash()) {
if (final.getNarHash() != prevNarHash) {
if (final.getNarHash())
if (result.getNarHash() != prevNarHash) {
if (result.getNarHash())
throw Error((unsigned int) 102, "NAR hash mismatch in input '%s', expected '%s' but got '%s'",
specified.to_string(), prevNarHash->to_string(HashFormat::SRI, true), final.getNarHash()->to_string(HashFormat::SRI, true));
specified.to_string(), prevNarHash->to_string(HashFormat::SRI, true), result.getNarHash()->to_string(HashFormat::SRI, true));
else
throw Error((unsigned int) 102, "NAR hash mismatch in input '%s', expected '%s' but got none",
specified.to_string(), prevNarHash->to_string(HashFormat::SRI, true));
}
}

if (auto prevLastModified = specified.getLastModified()) {
if (final.getLastModified() != prevLastModified)
if (result.getLastModified() != prevLastModified)
throw Error("'lastModified' attribute mismatch in input '%s', expected %d, got %d",
final.to_string(), *prevLastModified, final.getLastModified().value_or(-1));
result.to_string(), *prevLastModified, result.getLastModified().value_or(-1));
}

if (auto prevRev = specified.getRev()) {
if (final.getRev() != prevRev)
if (result.getRev() != prevRev)
throw Error("'rev' attribute mismatch in input '%s', expected %s",
final.to_string(), prevRev->gitRev());
result.to_string(), prevRev->gitRev());
}

if (auto prevRevCount = specified.getRevCount()) {
if (final.getRevCount() != prevRevCount)
if (result.getRevCount() != prevRevCount)
throw Error("'revCount' attribute mismatch in input '%s', expected %d",
final.to_string(), *prevRevCount);
result.to_string(), *prevRevCount);
}
}

std::pair<ref<SourceAccessor>, Input> Input::getAccessor(ref<Store> store) const
{
try {
auto [accessor, final] = getAccessorUnchecked(store);
auto [accessor, result] = getAccessorUnchecked(store);

checkLocks(*this, final);
checkLocks(*this, result);

return {accessor, std::move(final)};
return {accessor, std::move(result)};
} catch (Error & e) {
e.addTrace({}, "while fetching the input '%s'", to_string());
throw;
Expand Down Expand Up @@ -315,12 +315,12 @@ std::pair<ref<SourceAccessor>, Input> Input::getAccessorUnchecked(ref<Store> sto
}
}

auto [accessor, final] = scheme->getAccessor(store, *this);
auto [accessor, result] = scheme->getAccessor(store, *this);

assert(!accessor->fingerprint);
accessor->fingerprint = scheme->getFingerprint(store, final);
accessor->fingerprint = scheme->getFingerprint(store, result);

return {accessor, std::move(final)};
return {accessor, std::move(result)};
}

Input Input::applyOverrides(
Expand Down
8 changes: 4 additions & 4 deletions src/libfetchers/fetchers.hh
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,17 @@ public:
std::pair<StorePath, Input> fetchToStore(ref<Store> store) const;

/**
* Check the locking attributes in `final` against
* Check the locking attributes in `result` against
* `specified`. E.g. if `specified` has a `rev` attribute, then
* `final` must have the same `rev` attribute. Throw an exception
* `result` must have the same `rev` attribute. Throw an exception
* if there is a mismatch.
*
* If `specified` is marked final (i.e. has the `__final`
* attribute), then the intersection of attributes in `specified`
* and `final` must be equal, and `final.attrs` is set to
* and `result` must be equal, and `final.attrs` is set to
* `specified.attrs` (i.e. we discard any new attributes).
*/
static void checkLocks(Input specified, Input & final);
static void checkLocks(Input specified, Input & result);

/**
* Return a `SourceAccessor` that allows access to files in the
Expand Down

0 comments on commit b7882d5

Please sign in to comment.