Skip to content

Commit 77982c5

Browse files
authored
Merge pull request NixOS#14582 from NixOS/ref-to-reference
libfetchers: Convert ref<Store> -> Store &
2 parents acacdf8 + cd5cac0 commit 77982c5

File tree

27 files changed

+119
-119
lines changed

27 files changed

+119
-119
lines changed

src/libcmd/common-eval-args.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ EvalSettings evalSettings{
3434
auto flakeRef = parseFlakeRef(fetchSettings, std::string{rest}, {}, true, false);
3535
debug("fetching flake search path element '%s''", rest);
3636
auto [accessor, lockedRef] =
37-
flakeRef.resolve(fetchSettings, state.store).lazyFetch(fetchSettings, state.store);
37+
flakeRef.resolve(fetchSettings, *state.store).lazyFetch(fetchSettings, *state.store);
3838
auto storePath = nix::fetchToStore(
3939
state.fetchSettings,
4040
*state.store,
@@ -180,15 +180,16 @@ Bindings * MixEvalArgs::getAutoArgs(EvalState & state)
180180
SourcePath lookupFileArg(EvalState & state, std::string_view s, const Path * baseDir)
181181
{
182182
if (EvalSettings::isPseudoUrl(s)) {
183-
auto accessor = fetchers::downloadTarball(state.store, state.fetchSettings, EvalSettings::resolvePseudoUrl(s));
183+
auto accessor = fetchers::downloadTarball(*state.store, state.fetchSettings, EvalSettings::resolvePseudoUrl(s));
184184
auto storePath = fetchToStore(state.fetchSettings, *state.store, SourcePath(accessor), FetchMode::Copy);
185185
return state.storePath(storePath);
186186
}
187187

188188
else if (hasPrefix(s, "flake:")) {
189189
experimentalFeatureSettings.require(Xp::Flakes);
190190
auto flakeRef = parseFlakeRef(fetchSettings, std::string(s.substr(6)), {}, true, false);
191-
auto [accessor, lockedRef] = flakeRef.resolve(fetchSettings, state.store).lazyFetch(fetchSettings, state.store);
191+
auto [accessor, lockedRef] =
192+
flakeRef.resolve(fetchSettings, *state.store).lazyFetch(fetchSettings, *state.store);
192193
auto storePath = nix::fetchToStore(
193194
state.fetchSettings, *state.store, SourcePath(accessor), FetchMode::Copy, lockedRef.input.getName());
194195
state.allowPath(storePath);

src/libcmd/installables.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ void completeFlakeRef(AddCompletions & completions, ref<Store> store, std::strin
410410
Args::completeDir(completions, 0, prefix);
411411

412412
/* Look for registry entries that match the prefix. */
413-
for (auto & registry : fetchers::getRegistries(fetchSettings, store)) {
413+
for (auto & registry : fetchers::getRegistries(fetchSettings, *store)) {
414414
for (auto & entry : registry->entries) {
415415
auto from = entry.from.to_string();
416416
if (!hasPrefix(prefix, "flake:") && hasPrefix(from, "flake:")) {

src/libexpr/eval.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3190,7 +3190,7 @@ std::optional<SourcePath> EvalState::resolveLookupPathPath(const LookupPath::Pat
31903190

31913191
if (EvalSettings::isPseudoUrl(value)) {
31923192
try {
3193-
auto accessor = fetchers::downloadTarball(store, fetchSettings, EvalSettings::resolvePseudoUrl(value));
3193+
auto accessor = fetchers::downloadTarball(*store, fetchSettings, EvalSettings::resolvePseudoUrl(value));
31943194
auto storePath = fetchToStore(fetchSettings, *store, SourcePath(accessor), FetchMode::Copy);
31953195
return finish(this->storePath(storePath));
31963196
} catch (Error & e) {

src/libexpr/primops/fetchMercurial.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static void prim_fetchMercurial(EvalState & state, const PosIdx pos, Value ** ar
8181
attrs.insert_or_assign("rev", rev->gitRev());
8282
auto input = fetchers::Input::fromAttrs(state.fetchSettings, std::move(attrs));
8383

84-
auto [storePath, input2] = input.fetchToStore(state.fetchSettings, state.store);
84+
auto [storePath, input2] = input.fetchToStore(state.fetchSettings, *state.store);
8585

8686
auto attrs2 = state.buildBindings(8);
8787
state.mkStorePathString(storePath, attrs2.alloc(state.s.outPath));

src/libexpr/primops/fetchTree.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ static void fetchTree(
194194
}
195195

196196
if (!state.settings.pureEval && !input.isDirect() && experimentalFeatureSettings.isEnabled(Xp::Flakes))
197-
input = lookupInRegistries(state.fetchSettings, state.store, input, fetchers::UseRegistries::Limited).first;
197+
input = lookupInRegistries(state.fetchSettings, *state.store, input, fetchers::UseRegistries::Limited).first;
198198

199199
if (state.settings.pureEval && !input.isLocked(state.fetchSettings)) {
200200
if (input.getNarHash())
@@ -220,7 +220,7 @@ static void fetchTree(
220220
}
221221

222222
auto cachedInput =
223-
state.inputCache->getAccessor(state.fetchSettings, state.store, input, fetchers::UseRegistries::No);
223+
state.inputCache->getAccessor(state.fetchSettings, *state.store, input, fetchers::UseRegistries::No);
224224

225225
auto storePath = state.mountInput(cachedInput.lockedInput, input, cachedInput.accessor);
226226

@@ -480,10 +480,10 @@ static void fetch(
480480
auto storePath = unpack ? fetchToStore(
481481
state.fetchSettings,
482482
*state.store,
483-
fetchers::downloadTarball(state.store, state.fetchSettings, *url),
483+
fetchers::downloadTarball(*state.store, state.fetchSettings, *url),
484484
FetchMode::Copy,
485485
name)
486-
: fetchers::downloadFile(state.store, state.fetchSettings, *url, name).storePath;
486+
: fetchers::downloadFile(*state.store, state.fetchSettings, *url, name).storePath;
487487

488488
if (expectedHash) {
489489
auto hash = unpack ? state.store->queryPathInfo(storePath)->narHash

src/libfetchers-tests/git.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ TEST_F(GitTest, submodulePeriodSupport)
196196
{"ref", "main"},
197197
});
198198

199-
auto [accessor, i] = input.getAccessor(settings, store);
199+
auto [accessor, i] = input.getAccessor(settings, *store);
200200

201201
ASSERT_EQ(accessor->readFile(CanonPath("deps/sub/lib.txt")), "hello from submodule\n");
202202
}

src/libfetchers/fetchers.cc

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ Input Input::fromAttrs(const Settings & settings, Attrs && attrs)
111111
return std::move(*res);
112112
}
113113

114-
std::optional<std::string> Input::getFingerprint(ref<Store> store) const
114+
std::optional<std::string> Input::getFingerprint(Store & store) const
115115
{
116116
if (!scheme)
117117
return std::nullopt;
@@ -190,7 +190,7 @@ bool Input::contains(const Input & other) const
190190
}
191191

192192
// FIXME: remove
193-
std::pair<StorePath, Input> Input::fetchToStore(const Settings & settings, ref<Store> store) const
193+
std::pair<StorePath, Input> Input::fetchToStore(const Settings & settings, Store & store) const
194194
{
195195
if (!scheme)
196196
throw Error("cannot fetch unsupported input '%s'", attrsToJSON(toAttrs()));
@@ -200,9 +200,9 @@ std::pair<StorePath, Input> Input::fetchToStore(const Settings & settings, ref<S
200200
auto [accessor, result] = getAccessorUnchecked(settings, store);
201201

202202
auto storePath =
203-
nix::fetchToStore(settings, *store, SourcePath(accessor), FetchMode::Copy, result.getName());
203+
nix::fetchToStore(settings, store, SourcePath(accessor), FetchMode::Copy, result.getName());
204204

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

208208
result.attrs.insert_or_assign("__final", Explicit<bool>(true));
@@ -289,7 +289,7 @@ void Input::checkLocks(Input specified, Input & result)
289289
}
290290
}
291291

292-
std::pair<ref<SourceAccessor>, Input> Input::getAccessor(const Settings & settings, ref<Store> store) const
292+
std::pair<ref<SourceAccessor>, Input> Input::getAccessor(const Settings & settings, Store & store) const
293293
{
294294
try {
295295
auto [accessor, result] = getAccessorUnchecked(settings, store);
@@ -305,7 +305,7 @@ std::pair<ref<SourceAccessor>, Input> Input::getAccessor(const Settings & settin
305305
}
306306
}
307307

308-
std::pair<ref<SourceAccessor>, Input> Input::getAccessorUnchecked(const Settings & settings, ref<Store> store) const
308+
std::pair<ref<SourceAccessor>, Input> Input::getAccessorUnchecked(const Settings & settings, Store & store) const
309309
{
310310
// FIXME: cache the accessor
311311

@@ -325,13 +325,13 @@ std::pair<ref<SourceAccessor>, Input> Input::getAccessorUnchecked(const Settings
325325
*/
326326
if (isFinal() && getNarHash()) {
327327
try {
328-
auto storePath = computeStorePath(*store);
328+
auto storePath = computeStorePath(store);
329329

330-
store->ensurePath(storePath);
330+
store.ensurePath(storePath);
331331

332-
debug("using substituted/cached input '%s' in '%s'", to_string(), store->printStorePath(storePath));
332+
debug("using substituted/cached input '%s' in '%s'", to_string(), store.printStorePath(storePath));
333333

334-
auto accessor = store->requireStoreObjectAccessor(storePath);
334+
auto accessor = store.requireStoreObjectAccessor(storePath);
335335

336336
accessor->fingerprint = getFingerprint(store);
337337

@@ -341,7 +341,7 @@ std::pair<ref<SourceAccessor>, Input> Input::getAccessorUnchecked(const Settings
341341
if (accessor->fingerprint) {
342342
ContentAddressMethod method = ContentAddressMethod::Raw::NixArchive;
343343
auto cacheKey = makeFetchToStoreCacheKey(getName(), *accessor->fingerprint, method, "/");
344-
settings.getCache()->upsert(cacheKey, *store, {}, storePath);
344+
settings.getCache()->upsert(cacheKey, store, {}, storePath);
345345
}
346346

347347
accessor->setPathDisplay("«" + to_string() + "»");
@@ -369,7 +369,7 @@ Input Input::applyOverrides(std::optional<std::string> ref, std::optional<Hash>
369369
return scheme->applyOverrides(*this, ref, rev);
370370
}
371371

372-
void Input::clone(const Settings & settings, ref<Store> store, const std::filesystem::path & destDir) const
372+
void Input::clone(const Settings & settings, Store & store, const std::filesystem::path & destDir) const
373373
{
374374
assert(scheme);
375375
scheme->clone(settings, store, *this, destDir);
@@ -486,7 +486,7 @@ void InputScheme::putFile(
486486
}
487487

488488
void InputScheme::clone(
489-
const Settings & settings, ref<Store> store, const Input & input, const std::filesystem::path & destDir) const
489+
const Settings & settings, Store & store, const Input & input, const std::filesystem::path & destDir) const
490490
{
491491
if (std::filesystem::exists(destDir))
492492
throw Error("cannot clone into existing path %s", destDir);

src/libfetchers/git.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ struct GitInputScheme : InputScheme
433433
return res;
434434
}
435435

436-
void clone(const Settings & settings, ref<Store> store, const Input & input, const std::filesystem::path & destDir)
436+
void clone(const Settings & settings, Store & store, const Input & input, const std::filesystem::path & destDir)
437437
const override
438438
{
439439
auto repoInfo = getRepoInfo(input);
@@ -779,7 +779,7 @@ struct GitInputScheme : InputScheme
779779
}
780780

781781
std::pair<ref<SourceAccessor>, Input>
782-
getAccessorFromCommit(const Settings & settings, ref<Store> store, RepoInfo & repoInfo, Input && input) const
782+
getAccessorFromCommit(const Settings & settings, Store & store, RepoInfo & repoInfo, Input && input) const
783783
{
784784
assert(!repoInfo.workdirInfo.isDirty);
785785

@@ -953,7 +953,7 @@ struct GitInputScheme : InputScheme
953953
}
954954

955955
std::pair<ref<SourceAccessor>, Input>
956-
getAccessorFromWorkdir(const Settings & settings, ref<Store> store, RepoInfo & repoInfo, Input && input) const
956+
getAccessorFromWorkdir(const Settings & settings, Store & store, RepoInfo & repoInfo, Input && input) const
957957
{
958958
auto repoPath = repoInfo.getPath().value();
959959

@@ -1037,7 +1037,7 @@ struct GitInputScheme : InputScheme
10371037
}
10381038

10391039
std::pair<ref<SourceAccessor>, Input>
1040-
getAccessor(const Settings & settings, ref<Store> store, const Input & _input) const override
1040+
getAccessor(const Settings & settings, Store & store, const Input & _input) const override
10411041
{
10421042
Input input(_input);
10431043

@@ -1059,7 +1059,7 @@ struct GitInputScheme : InputScheme
10591059
return {accessor, std::move(final)};
10601060
}
10611061

1062-
std::optional<std::string> getFingerprint(ref<Store> store, const Input & input) const override
1062+
std::optional<std::string> getFingerprint(Store & store, const Input & input) const override
10631063
{
10641064
auto makeFingerprint = [&](const Hash & rev) {
10651065
return rev.gitRev() + (getSubmodulesAttr(input) ? ";s" : "") + (getExportIgnoreAttr(input) ? ";e" : "")

src/libfetchers/github.cc

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ struct GitArchiveInputScheme : InputScheme
258258
std::optional<Hash> treeHash;
259259
};
260260

261-
virtual RefInfo getRevFromRef(const Settings & settings, nix::ref<Store> store, const Input & input) const = 0;
261+
virtual RefInfo getRevFromRef(const Settings & settings, nix::Store & store, const Input & input) const = 0;
262262

263263
virtual DownloadUrl getDownloadUrl(const Settings & settings, const Input & input) const = 0;
264264

@@ -268,7 +268,7 @@ struct GitArchiveInputScheme : InputScheme
268268
time_t lastModified;
269269
};
270270

271-
std::pair<Input, TarballInfo> downloadArchive(const Settings & settings, ref<Store> store, Input input) const
271+
std::pair<Input, TarballInfo> downloadArchive(const Settings & settings, Store & store, Input input) const
272272
{
273273
if (!maybeGetStrAttr(input.attrs, "ref"))
274274
input.attrs.insert_or_assign("ref", "HEAD");
@@ -341,7 +341,7 @@ struct GitArchiveInputScheme : InputScheme
341341
}
342342

343343
std::pair<ref<SourceAccessor>, Input>
344-
getAccessor(const Settings & settings, ref<Store> store, const Input & _input) const override
344+
getAccessor(const Settings & settings, Store & store, const Input & _input) const override
345345
{
346346
auto [input, tarballInfo] = downloadArchive(settings, store, _input);
347347

@@ -370,7 +370,7 @@ struct GitArchiveInputScheme : InputScheme
370370
return Xp::Flakes;
371371
}
372372

373-
std::optional<std::string> getFingerprint(ref<Store> store, const Input & input) const override
373+
std::optional<std::string> getFingerprint(Store & store, const Input & input) const override
374374
{
375375
if (auto rev = input.getRev())
376376
return rev->gitRev();
@@ -418,7 +418,7 @@ struct GitHubInputScheme : GitArchiveInputScheme
418418
return getStrAttr(input.attrs, "repo");
419419
}
420420

421-
RefInfo getRevFromRef(const Settings & settings, nix::ref<Store> store, const Input & input) const override
421+
RefInfo getRevFromRef(const Settings & settings, nix::Store & store, const Input & input) const override
422422
{
423423
auto host = getHost(input);
424424
auto url = fmt(
@@ -432,7 +432,7 @@ struct GitHubInputScheme : GitArchiveInputScheme
432432

433433
auto downloadResult = downloadFile(store, settings, url, "source", headers);
434434
auto json = nlohmann::json::parse(
435-
store->requireStoreObjectAccessor(downloadResult.storePath)->readFile(CanonPath::root));
435+
store.requireStoreObjectAccessor(downloadResult.storePath)->readFile(CanonPath::root));
436436

437437
return RefInfo{
438438
.rev = Hash::parseAny(std::string{json["sha"]}, HashAlgorithm::SHA1),
@@ -457,7 +457,7 @@ struct GitHubInputScheme : GitArchiveInputScheme
457457
return DownloadUrl{parseURL(url), headers};
458458
}
459459

460-
void clone(const Settings & settings, ref<Store> store, const Input & input, const std::filesystem::path & destDir)
460+
void clone(const Settings & settings, Store & store, const Input & input, const std::filesystem::path & destDir)
461461
const override
462462
{
463463
auto host = getHost(input);
@@ -499,7 +499,7 @@ struct GitLabInputScheme : GitArchiveInputScheme
499499
return std::make_pair(token.substr(0, fldsplit), token.substr(fldsplit + 1));
500500
}
501501

502-
RefInfo getRevFromRef(const Settings & settings, nix::ref<Store> store, const Input & input) const override
502+
RefInfo getRevFromRef(const Settings & settings, nix::Store & store, const Input & input) const override
503503
{
504504
auto host = maybeGetStrAttr(input.attrs, "host").value_or("gitlab.com");
505505
// See rate limiting note below
@@ -514,7 +514,7 @@ struct GitLabInputScheme : GitArchiveInputScheme
514514

515515
auto downloadResult = downloadFile(store, settings, url, "source", headers);
516516
auto json = nlohmann::json::parse(
517-
store->requireStoreObjectAccessor(downloadResult.storePath)->readFile(CanonPath::root));
517+
store.requireStoreObjectAccessor(downloadResult.storePath)->readFile(CanonPath::root));
518518

519519
if (json.is_array() && json.size() >= 1 && json[0]["id"] != nullptr) {
520520
return RefInfo{.rev = Hash::parseAny(std::string(json[0]["id"]), HashAlgorithm::SHA1)};
@@ -545,7 +545,7 @@ struct GitLabInputScheme : GitArchiveInputScheme
545545
return DownloadUrl{parseURL(url), headers};
546546
}
547547

548-
void clone(const Settings & settings, ref<Store> store, const Input & input, const std::filesystem::path & destDir)
548+
void clone(const Settings & settings, Store & store, const Input & input, const std::filesystem::path & destDir)
549549
const override
550550
{
551551
auto host = maybeGetStrAttr(input.attrs, "host").value_or("gitlab.com");
@@ -581,7 +581,7 @@ struct SourceHutInputScheme : GitArchiveInputScheme
581581
// Once it is implemented, however, should work as expected.
582582
}
583583

584-
RefInfo getRevFromRef(const Settings & settings, nix::ref<Store> store, const Input & input) const override
584+
RefInfo getRevFromRef(const Settings & settings, nix::Store & store, const Input & input) const override
585585
{
586586
// TODO: In the future, when the sourcehut graphql API is implemented for mercurial
587587
// and with anonymous access, this method should use it instead.
@@ -597,7 +597,7 @@ struct SourceHutInputScheme : GitArchiveInputScheme
597597
std::string refUri;
598598
if (ref == "HEAD") {
599599
auto downloadFileResult = downloadFile(store, settings, fmt("%s/HEAD", base_url), "source", headers);
600-
auto contents = store->requireStoreObjectAccessor(downloadFileResult.storePath)->readFile(CanonPath::root);
600+
auto contents = store.requireStoreObjectAccessor(downloadFileResult.storePath)->readFile(CanonPath::root);
601601

602602
auto remoteLine = git::parseLsRemoteLine(getLine(contents).first);
603603
if (!remoteLine) {
@@ -610,7 +610,7 @@ struct SourceHutInputScheme : GitArchiveInputScheme
610610
std::regex refRegex(refUri);
611611

612612
auto downloadFileResult = downloadFile(store, settings, fmt("%s/info/refs", base_url), "source", headers);
613-
auto contents = store->requireStoreObjectAccessor(downloadFileResult.storePath)->readFile(CanonPath::root);
613+
auto contents = store.requireStoreObjectAccessor(downloadFileResult.storePath)->readFile(CanonPath::root);
614614
std::istringstream is(contents);
615615

616616
std::string line;
@@ -641,7 +641,7 @@ struct SourceHutInputScheme : GitArchiveInputScheme
641641
return DownloadUrl{parseURL(url), headers};
642642
}
643643

644-
void clone(const Settings & settings, ref<Store> store, const Input & input, const std::filesystem::path & destDir)
644+
void clone(const Settings & settings, Store & store, const Input & input, const std::filesystem::path & destDir)
645645
const override
646646
{
647647
auto host = maybeGetStrAttr(input.attrs, "host").value_or("git.sr.ht");

0 commit comments

Comments
 (0)