Use named field initialization for references

This commit is contained in:
John Ericson 2023-01-06 12:24:20 -05:00
parent 8623143921
commit 6a168254ce
15 changed files with 34 additions and 26 deletions

View file

@ -299,7 +299,7 @@ SV * makeFixedOutputPath(int recursive, char * algo, char * hash, char * name)
.method = method, .method = method,
.hash = h, .hash = h,
}, },
{}, .references = {},
}); });
XPUSHs(sv_2mortal(newSVpv(store()->printStorePath(path).c_str(), 0))); XPUSHs(sv_2mortal(newSVpv(store()->printStorePath(path).c_str(), 0)));
} catch (Error & e) { } catch (Error & e) {

View file

@ -1249,7 +1249,7 @@ static void prim_derivationStrict(EvalState & state, const PosIdx pos, Value * *
.method = method, .method = method,
.hash = h, .hash = h,
}, },
{}, .references = {},
}); });
drv.env["out"] = state.store->printStorePath(outPath); drv.env["out"] = state.store->printStorePath(outPath);
drv.outputs.insert_or_assign("out", drv.outputs.insert_or_assign("out",

View file

@ -235,7 +235,7 @@ static void fetch(EvalState & state, const PosIdx pos, Value * * args, Value & v
.method = unpack ? FileIngestionMethod::Recursive : FileIngestionMethod::Flat, .method = unpack ? FileIngestionMethod::Recursive : FileIngestionMethod::Flat,
.hash = *expectedHash, .hash = *expectedHash,
}, },
{} .references = {}
}); });
if (state.store->isValidPath(expectedPath)) { if (state.store->isValidPath(expectedPath)) {

View file

@ -215,7 +215,7 @@ StorePath Input::computeStorePath(Store & store) const
.method = FileIngestionMethod::Recursive, .method = FileIngestionMethod::Recursive,
.hash = *narHash, .hash = *narHash,
}, },
{}, .references = {},
}); });
} }

View file

@ -79,7 +79,7 @@ DownloadFileResult downloadFile(
.method = FileIngestionMethod::Flat, .method = FileIngestionMethod::Flat,
.hash = hash, .hash = hash,
}, },
{}, .references = {},
}, },
}, },
hashString(htSHA256, sink.s), hashString(htSHA256, sink.s),

View file

@ -313,7 +313,7 @@ StorePath BinaryCacheStore::addToStoreFromDump(Source & dump, std::string_view n
.method = method, .method = method,
.hash = nar.first, .hash = nar.first,
}, },
{ .references = {
.references = references, .references = references,
.hasSelfReference = false, .hasSelfReference = false,
}, },
@ -433,7 +433,7 @@ StorePath BinaryCacheStore::addToStore(
.method = method, .method = method,
.hash = h, .hash = h,
}, },
{ .references = {
.references = references, .references = references,
.hasSelfReference = false, .hasSelfReference = false,
}, },

View file

@ -2482,7 +2482,7 @@ DrvOutputs LocalDerivationGoal::registerOutputs()
.method = outputHash.method, .method = outputHash.method,
.hash = got, .hash = got,
}, },
rewriteRefs(), .references = rewriteRefs(),
}, },
}, },
Hash::dummy, Hash::dummy,

View file

@ -154,10 +154,16 @@ Hash getContentAddressHash(const ContentAddress & ca)
ContentAddressWithReferences caWithoutRefs(const ContentAddress & ca) { ContentAddressWithReferences caWithoutRefs(const ContentAddress & ca) {
return std::visit(overloaded { return std::visit(overloaded {
[&](const TextHash & h) -> ContentAddressWithReferences { [&](const TextHash & h) -> ContentAddressWithReferences {
return TextInfo { h, {}}; return TextInfo {
h,
.references = {},
};
}, },
[&](const FixedOutputHash & h) -> ContentAddressWithReferences { [&](const FixedOutputHash & h) -> ContentAddressWithReferences {
return FixedOutputInfo { h, {}}; return FixedOutputInfo {
h,
.references = {},
};
}, },
}, ca); }, ca);
} }

View file

@ -1426,7 +1426,7 @@ StorePath LocalStore::addToStoreFromDump(Source & source0, std::string_view name
.method = method, .method = method,
.hash = hash, .hash = hash,
}, },
{ .references = {
.references = references, .references = references,
.hasSelfReference = false, .hasSelfReference = false,
}, },

View file

@ -55,7 +55,7 @@ std::map<StorePath, StorePath> makeContentAddressed(
.method = FileIngestionMethod::Recursive, .method = FileIngestionMethod::Recursive,
.hash = narModuloHash, .hash = narModuloHash,
}, },
std::move(refs), .references = std::move(refs),
}, },
}, },
Hash::dummy, Hash::dummy,

View file

@ -232,7 +232,7 @@ std::pair<StorePath, Hash> Store::computeStorePathForPath(std::string_view name,
.method = method, .method = method,
.hash = h, .hash = h,
}, },
{}, .references = {},
}; };
return std::make_pair(makeFixedOutputPath(name, caInfo), h); return std::make_pair(makeFixedOutputPath(name, caInfo), h);
} }
@ -442,7 +442,7 @@ ValidPathInfo Store::addToStoreSlow(std::string_view name, const Path & srcPath,
.method = method, .method = method,
.hash = hash, .hash = hash,
}, },
{}, .references = {},
}, },
}, },
narHash, narHash,
@ -1270,16 +1270,18 @@ std::optional<StorePathDescriptor> ValidPathInfo::fullStorePathDescriptorOpt() c
return StorePathDescriptor { return StorePathDescriptor {
.name = std::string { path.name() }, .name = std::string { path.name() },
.info = std::visit(overloaded { .info = std::visit(overloaded {
[&](const TextHash & th) { [&](const TextHash & th) -> ContentAddressWithReferences {
TextInfo info { th };
assert(!hasSelfReference); assert(!hasSelfReference);
info.references = references; return TextInfo {
return ContentAddressWithReferences { info }; th,
.references = references,
};
}, },
[&](const FixedOutputHash & foh) { [&](const FixedOutputHash & foh) -> ContentAddressWithReferences {
FixedOutputInfo info { foh }; return FixedOutputInfo {
info.references = static_cast<PathReferences<StorePath>>(*this); foh,
return ContentAddressWithReferences { info }; .references = static_cast<PathReferences<StorePath>>(*this),
};
}, },
}, *ca), }, *ca),
}; };

View file

@ -220,7 +220,7 @@ static void opPrintFixedPath(Strings opFlags, Strings opArgs)
.method = method, .method = method,
.hash = Hash::parseAny(hash, hashAlgo), .hash = Hash::parseAny(hash, hashAlgo),
}, },
{}, .references = {},
}))); })));
} }

View file

@ -50,7 +50,7 @@ struct CmdAddToStore : MixDryRun, StoreCommand
.method = std::move(ingestionMethod), .method = std::move(ingestionMethod),
.hash = std::move(hash), .hash = std::move(hash),
}, },
{}, .references = {},
}, },
}, },
narHash, narHash,

View file

@ -72,7 +72,7 @@ std::tuple<StorePath, Hash> prefetchFile(
.method = ingestionMethod, .method = ingestionMethod,
.hash = *expectedHash, .hash = *expectedHash,
}, },
{}, .references = {},
}); });
if (store->isValidPath(*storePath)) if (store->isValidPath(*storePath))
hash = expectedHash; hash = expectedHash;

View file

@ -205,7 +205,7 @@ struct ProfileManifest
.method = FileIngestionMethod::Recursive, .method = FileIngestionMethod::Recursive,
.hash = narHash, .hash = narHash,
}, },
{ references }, .references = { references },
}, },
}, },
narHash, narHash,