Skip to content

Commit b51e161

Browse files
Ericson2314roberth
andcommitted
Cleanup ContentAddressMethod to match docs
The old `std::variant` is bad because we aren't adding a new case to `FileIngestionMethod` so much as we are defining a separate concept --- store object content addressing rather than file system object content addressing. As such, it is more correct to just create a fresh enumeration. Co-authored-by: Robert Hensing <[email protected]>
1 parent 64e599e commit b51e161

25 files changed

+275
-203
lines changed

src/libexpr/eval.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2303,7 +2303,7 @@ StorePath EvalState::copyPathToStore(NixStringContext & context, const SourcePat
23032303
path.resolveSymlinks(),
23042304
settings.readOnlyMode ? FetchMode::DryRun : FetchMode::Copy,
23052305
path.baseName(),
2306-
FileIngestionMethod::NixArchive,
2306+
ContentAddressMethod::Raw::NixArchive,
23072307
nullptr,
23082308
repair);
23092309
allowPath(dstPath);

src/libexpr/primops.cc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,17 +1209,17 @@ static void derivationStrictInternal(
12091209
auto handleHashMode = [&](const std::string_view s) {
12101210
if (s == "recursive") {
12111211
// back compat, new name is "nar"
1212-
ingestionMethod = FileIngestionMethod::NixArchive;
1212+
ingestionMethod = ContentAddressMethod::Raw::NixArchive;
12131213
} else try {
12141214
ingestionMethod = ContentAddressMethod::parse(s);
12151215
} catch (UsageError &) {
12161216
state.error<EvalError>(
12171217
"invalid value '%s' for 'outputHashMode' attribute", s
12181218
).atPos(v).debugThrow();
12191219
}
1220-
if (ingestionMethod == TextIngestionMethod {})
1220+
if (ingestionMethod == ContentAddressMethod::Raw::Text)
12211221
experimentalFeatureSettings.require(Xp::DynamicDerivations);
1222-
if (ingestionMethod == FileIngestionMethod::Git)
1222+
if (ingestionMethod == ContentAddressMethod::Raw::Git)
12231223
experimentalFeatureSettings.require(Xp::GitHashing);
12241224
};
12251225

@@ -1391,7 +1391,7 @@ static void derivationStrictInternal(
13911391

13921392
/* Check whether the derivation name is valid. */
13931393
if (isDerivation(drvName) &&
1394-
!(ingestionMethod == ContentAddressMethod { TextIngestionMethod { } } &&
1394+
!(ingestionMethod == ContentAddressMethod::Raw::Text &&
13951395
outputs.size() == 1 &&
13961396
*(outputs.begin()) == "out"))
13971397
{
@@ -1413,7 +1413,7 @@ static void derivationStrictInternal(
14131413

14141414
auto h = newHashAllowEmpty(*outputHash, outputHashAlgo);
14151415

1416-
auto method = ingestionMethod.value_or(FileIngestionMethod::Flat);
1416+
auto method = ingestionMethod.value_or(ContentAddressMethod::Raw::Flat);
14171417

14181418
DerivationOutput::CAFixed dof {
14191419
.ca = ContentAddress {
@@ -1432,7 +1432,7 @@ static void derivationStrictInternal(
14321432
.atPos(v).debugThrow();
14331433

14341434
auto ha = outputHashAlgo.value_or(HashAlgorithm::SHA256);
1435-
auto method = ingestionMethod.value_or(FileIngestionMethod::NixArchive);
1435+
auto method = ingestionMethod.value_or(ContentAddressMethod::Raw::NixArchive);
14361436

14371437
for (auto & i : outputs) {
14381438
drv.env[i] = hashPlaceholder(i);
@@ -2208,7 +2208,7 @@ static void prim_toFile(EvalState & state, const PosIdx pos, Value * * args, Val
22082208
})
22092209
: ({
22102210
StringSource s { contents };
2211-
state.store->addToStoreFromDump(s, name, FileSerialisationMethod::Flat, TextIngestionMethod {}, HashAlgorithm::SHA256, refs, state.repair);
2211+
state.store->addToStoreFromDump(s, name, FileSerialisationMethod::Flat, ContentAddressMethod::Raw::Text, HashAlgorithm::SHA256, refs, state.repair);
22122212
});
22132213

22142214
/* Note: we don't need to add `context' to the context of the
@@ -2391,7 +2391,7 @@ static void prim_filterSource(EvalState & state, const PosIdx pos, Value * * arg
23912391
"while evaluating the second argument (the path to filter) passed to 'builtins.filterSource'");
23922392
state.forceFunction(*args[0], pos, "while evaluating the first argument passed to builtins.filterSource");
23932393

2394-
addPath(state, pos, path.baseName(), path, args[0], FileIngestionMethod::NixArchive, std::nullopt, v, context);
2394+
addPath(state, pos, path.baseName(), path, args[0], ContentAddressMethod::Raw::NixArchive, std::nullopt, v, context);
23952395
}
23962396

23972397
static RegisterPrimOp primop_filterSource({
@@ -2454,7 +2454,7 @@ static void prim_path(EvalState & state, const PosIdx pos, Value * * args, Value
24542454
std::optional<SourcePath> path;
24552455
std::string name;
24562456
Value * filterFun = nullptr;
2457-
ContentAddressMethod method = FileIngestionMethod::NixArchive;
2457+
auto method = ContentAddressMethod::Raw::NixArchive;
24582458
std::optional<Hash> expectedHash;
24592459
NixStringContext context;
24602460

@@ -2470,8 +2470,8 @@ static void prim_path(EvalState & state, const PosIdx pos, Value * * args, Value
24702470
state.forceFunction(*(filterFun = attr.value), attr.pos, "while evaluating the `filter` parameter passed to builtins.path");
24712471
else if (n == "recursive")
24722472
method = state.forceBool(*attr.value, attr.pos, "while evaluating the `recursive` attribute passed to builtins.path")
2473-
? FileIngestionMethod::NixArchive
2474-
: FileIngestionMethod::Flat;
2473+
? ContentAddressMethod::Raw::NixArchive
2474+
: ContentAddressMethod::Raw::Flat;
24752475
else if (n == "sha256")
24762476
expectedHash = newHashAllowEmpty(state.forceStringNoCtx(*attr.value, attr.pos, "while evaluating the `sha256` attribute passed to builtins.path"), HashAlgorithm::SHA256);
24772477
else

src/libfetchers/fetch-to-store.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ StorePath fetchToStore(
1818
const SourcePath & path,
1919
FetchMode mode,
2020
std::string_view name = "source",
21-
ContentAddressMethod method = FileIngestionMethod::NixArchive,
21+
ContentAddressMethod method = ContentAddressMethod::Raw::NixArchive,
2222
PathFilter * filter = nullptr,
2323
RepairFlag repair = NoRepair);
2424

src/libfetchers/mercurial.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ struct MercurialInputScheme : InputScheme
213213
auto storePath = store->addToStore(
214214
input.getName(),
215215
{getFSSourceAccessor(), CanonPath(actualPath)},
216-
FileIngestionMethod::NixArchive, HashAlgorithm::SHA256, {},
216+
ContentAddressMethod::Raw::NixArchive, HashAlgorithm::SHA256, {},
217217
filter);
218218

219219
return storePath;

0 commit comments

Comments
 (0)