Skip to content

Commit cd5cac0

Browse files
committed
libfetchers: Convert ref<Store> -> Store &
1 parent d07c24f commit cd5cac0

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
@@ -3188,7 +3188,7 @@ std::optional<SourcePath> EvalState::resolveLookupPathPath(const LookupPath::Pat
31883188

31893189
if (EvalSettings::isPseudoUrl(value)) {
31903190
try {
3191-
auto accessor = fetchers::downloadTarball(store, fetchSettings, EvalSettings::resolvePseudoUrl(value));
3191+
auto accessor = fetchers::downloadTarball(*store, fetchSettings, EvalSettings::resolvePseudoUrl(value));
31923192
auto storePath = fetchToStore(fetchSettings, *store, SourcePath(accessor), FetchMode::Copy);
31933193
return finish(this->storePath(storePath));
31943194
} 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

@@ -582,10 +582,10 @@ static void fetch(
582582
auto storePath = unpack ? fetchToStore(
583583
state.fetchSettings,
584584
*state.store,
585-
fetchers::downloadTarball(state.store, state.fetchSettings, *url),
585+
fetchers::downloadTarball(*state.store, state.fetchSettings, *url),
586586
FetchMode::Copy,
587587
name)
588-
: fetchers::downloadFile(state.store, state.fetchSettings, *url, name).storePath;
588+
: fetchers::downloadFile(*state.store, state.fetchSettings, *url, name).storePath;
589589

590590
if (expectedHash) {
591591
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
@@ -120,7 +120,7 @@ Input Input::fromAttrs(const Settings & settings, Attrs && attrs)
120120
return std::move(*res);
121121
}
122122

123-
std::optional<std::string> Input::getFingerprint(ref<Store> store) const
123+
std::optional<std::string> Input::getFingerprint(Store & store) const
124124
{
125125
if (!scheme)
126126
return std::nullopt;
@@ -199,7 +199,7 @@ bool Input::contains(const Input & other) const
199199
}
200200

201201
// FIXME: remove
202-
std::pair<StorePath, Input> Input::fetchToStore(const Settings & settings, ref<Store> store) const
202+
std::pair<StorePath, Input> Input::fetchToStore(const Settings & settings, Store & store) const
203203
{
204204
if (!scheme)
205205
throw Error("cannot fetch unsupported input '%s'", attrsToJSON(toAttrs()));
@@ -209,9 +209,9 @@ std::pair<StorePath, Input> Input::fetchToStore(const Settings & settings, ref<S
209209
auto [accessor, result] = getAccessorUnchecked(settings, store);
210210

211211
auto storePath =
212-
nix::fetchToStore(settings, *store, SourcePath(accessor), FetchMode::Copy, result.getName());
212+
nix::fetchToStore(settings, store, SourcePath(accessor), FetchMode::Copy, result.getName());
213213

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

217217
result.attrs.insert_or_assign("__final", Explicit<bool>(true));
@@ -298,7 +298,7 @@ void Input::checkLocks(Input specified, Input & result)
298298
}
299299
}
300300

301-
std::pair<ref<SourceAccessor>, Input> Input::getAccessor(const Settings & settings, ref<Store> store) const
301+
std::pair<ref<SourceAccessor>, Input> Input::getAccessor(const Settings & settings, Store & store) const
302302
{
303303
try {
304304
auto [accessor, result] = getAccessorUnchecked(settings, store);
@@ -314,7 +314,7 @@ std::pair<ref<SourceAccessor>, Input> Input::getAccessor(const Settings & settin
314314
}
315315
}
316316

317-
std::pair<ref<SourceAccessor>, Input> Input::getAccessorUnchecked(const Settings & settings, ref<Store> store) const
317+
std::pair<ref<SourceAccessor>, Input> Input::getAccessorUnchecked(const Settings & settings, Store & store) const
318318
{
319319
// FIXME: cache the accessor
320320

@@ -334,13 +334,13 @@ std::pair<ref<SourceAccessor>, Input> Input::getAccessorUnchecked(const Settings
334334
*/
335335
if (isFinal() && getNarHash()) {
336336
try {
337-
auto storePath = computeStorePath(*store);
337+
auto storePath = computeStorePath(store);
338338

339-
store->ensurePath(storePath);
339+
store.ensurePath(storePath);
340340

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

343-
auto accessor = store->requireStoreObjectAccessor(storePath);
343+
auto accessor = store.requireStoreObjectAccessor(storePath);
344344

345345
accessor->fingerprint = getFingerprint(store);
346346

@@ -350,7 +350,7 @@ std::pair<ref<SourceAccessor>, Input> Input::getAccessorUnchecked(const Settings
350350
if (accessor->fingerprint) {
351351
ContentAddressMethod method = ContentAddressMethod::Raw::NixArchive;
352352
auto cacheKey = makeFetchToStoreCacheKey(getName(), *accessor->fingerprint, method, "/");
353-
settings.getCache()->upsert(cacheKey, *store, {}, storePath);
353+
settings.getCache()->upsert(cacheKey, store, {}, storePath);
354354
}
355355

356356
accessor->setPathDisplay("«" + to_string() + "»");
@@ -378,7 +378,7 @@ Input Input::applyOverrides(std::optional<std::string> ref, std::optional<Hash>
378378
return scheme->applyOverrides(*this, ref, rev);
379379
}
380380

381-
void Input::clone(const Settings & settings, ref<Store> store, const std::filesystem::path & destDir) const
381+
void Input::clone(const Settings & settings, Store & store, const std::filesystem::path & destDir) const
382382
{
383383
assert(scheme);
384384
scheme->clone(settings, store, *this, destDir);
@@ -495,7 +495,7 @@ void InputScheme::putFile(
495495
}
496496

497497
void InputScheme::clone(
498-
const Settings & settings, ref<Store> store, const Input & input, const std::filesystem::path & destDir) const
498+
const Settings & settings, Store & store, const Input & input, const std::filesystem::path & destDir) const
499499
{
500500
if (std::filesystem::exists(destDir))
501501
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
@@ -278,7 +278,7 @@ struct GitInputScheme : InputScheme
278278
return res;
279279
}
280280

281-
void clone(const Settings & settings, ref<Store> store, const Input & input, const std::filesystem::path & destDir)
281+
void clone(const Settings & settings, Store & store, const Input & input, const std::filesystem::path & destDir)
282282
const override
283283
{
284284
auto repoInfo = getRepoInfo(input);
@@ -624,7 +624,7 @@ struct GitInputScheme : InputScheme
624624
}
625625

626626
std::pair<ref<SourceAccessor>, Input>
627-
getAccessorFromCommit(const Settings & settings, ref<Store> store, RepoInfo & repoInfo, Input && input) const
627+
getAccessorFromCommit(const Settings & settings, Store & store, RepoInfo & repoInfo, Input && input) const
628628
{
629629
assert(!repoInfo.workdirInfo.isDirty);
630630

@@ -798,7 +798,7 @@ struct GitInputScheme : InputScheme
798798
}
799799

800800
std::pair<ref<SourceAccessor>, Input>
801-
getAccessorFromWorkdir(const Settings & settings, ref<Store> store, RepoInfo & repoInfo, Input && input) const
801+
getAccessorFromWorkdir(const Settings & settings, Store & store, RepoInfo & repoInfo, Input && input) const
802802
{
803803
auto repoPath = repoInfo.getPath().value();
804804

@@ -882,7 +882,7 @@ struct GitInputScheme : InputScheme
882882
}
883883

884884
std::pair<ref<SourceAccessor>, Input>
885-
getAccessor(const Settings & settings, ref<Store> store, const Input & _input) const override
885+
getAccessor(const Settings & settings, Store & store, const Input & _input) const override
886886
{
887887
Input input(_input);
888888

@@ -904,7 +904,7 @@ struct GitInputScheme : InputScheme
904904
return {accessor, std::move(final)};
905905
}
906906

907-
std::optional<std::string> getFingerprint(ref<Store> store, const Input & input) const override
907+
std::optional<std::string> getFingerprint(Store & store, const Input & input) const override
908908
{
909909
auto makeFingerprint = [&](const Hash & rev) {
910910
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
@@ -233,7 +233,7 @@ struct GitArchiveInputScheme : InputScheme
233233
std::optional<Hash> treeHash;
234234
};
235235

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

238238
virtual DownloadUrl getDownloadUrl(const Settings & settings, const Input & input) const = 0;
239239

@@ -243,7 +243,7 @@ struct GitArchiveInputScheme : InputScheme
243243
time_t lastModified;
244244
};
245245

246-
std::pair<Input, TarballInfo> downloadArchive(const Settings & settings, ref<Store> store, Input input) const
246+
std::pair<Input, TarballInfo> downloadArchive(const Settings & settings, Store & store, Input input) const
247247
{
248248
if (!maybeGetStrAttr(input.attrs, "ref"))
249249
input.attrs.insert_or_assign("ref", "HEAD");
@@ -316,7 +316,7 @@ struct GitArchiveInputScheme : InputScheme
316316
}
317317

318318
std::pair<ref<SourceAccessor>, Input>
319-
getAccessor(const Settings & settings, ref<Store> store, const Input & _input) const override
319+
getAccessor(const Settings & settings, Store & store, const Input & _input) const override
320320
{
321321
auto [input, tarballInfo] = downloadArchive(settings, store, _input);
322322

@@ -345,7 +345,7 @@ struct GitArchiveInputScheme : InputScheme
345345
return Xp::Flakes;
346346
}
347347

348-
std::optional<std::string> getFingerprint(ref<Store> store, const Input & input) const override
348+
std::optional<std::string> getFingerprint(Store & store, const Input & input) const override
349349
{
350350
if (auto rev = input.getRev())
351351
return rev->gitRev();
@@ -387,7 +387,7 @@ struct GitHubInputScheme : GitArchiveInputScheme
387387
return getStrAttr(input.attrs, "repo");
388388
}
389389

390-
RefInfo getRevFromRef(const Settings & settings, nix::ref<Store> store, const Input & input) const override
390+
RefInfo getRevFromRef(const Settings & settings, nix::Store & store, const Input & input) const override
391391
{
392392
auto host = getHost(input);
393393
auto url = fmt(
@@ -401,7 +401,7 @@ struct GitHubInputScheme : GitArchiveInputScheme
401401

402402
auto downloadResult = downloadFile(store, settings, url, "source", headers);
403403
auto json = nlohmann::json::parse(
404-
store->requireStoreObjectAccessor(downloadResult.storePath)->readFile(CanonPath::root));
404+
store.requireStoreObjectAccessor(downloadResult.storePath)->readFile(CanonPath::root));
405405

406406
return RefInfo{
407407
.rev = Hash::parseAny(std::string{json["sha"]}, HashAlgorithm::SHA1),
@@ -426,7 +426,7 @@ struct GitHubInputScheme : GitArchiveInputScheme
426426
return DownloadUrl{parseURL(url), headers};
427427
}
428428

429-
void clone(const Settings & settings, ref<Store> store, const Input & input, const std::filesystem::path & destDir)
429+
void clone(const Settings & settings, Store & store, const Input & input, const std::filesystem::path & destDir)
430430
const override
431431
{
432432
auto host = getHost(input);
@@ -462,7 +462,7 @@ struct GitLabInputScheme : GitArchiveInputScheme
462462
return std::make_pair(token.substr(0, fldsplit), token.substr(fldsplit + 1));
463463
}
464464

465-
RefInfo getRevFromRef(const Settings & settings, nix::ref<Store> store, const Input & input) const override
465+
RefInfo getRevFromRef(const Settings & settings, nix::Store & store, const Input & input) const override
466466
{
467467
auto host = maybeGetStrAttr(input.attrs, "host").value_or("gitlab.com");
468468
// See rate limiting note below
@@ -477,7 +477,7 @@ struct GitLabInputScheme : GitArchiveInputScheme
477477

478478
auto downloadResult = downloadFile(store, settings, url, "source", headers);
479479
auto json = nlohmann::json::parse(
480-
store->requireStoreObjectAccessor(downloadResult.storePath)->readFile(CanonPath::root));
480+
store.requireStoreObjectAccessor(downloadResult.storePath)->readFile(CanonPath::root));
481481

482482
if (json.is_array() && json.size() >= 1 && json[0]["id"] != nullptr) {
483483
return RefInfo{.rev = Hash::parseAny(std::string(json[0]["id"]), HashAlgorithm::SHA1)};
@@ -508,7 +508,7 @@ struct GitLabInputScheme : GitArchiveInputScheme
508508
return DownloadUrl{parseURL(url), headers};
509509
}
510510

511-
void clone(const Settings & settings, ref<Store> store, const Input & input, const std::filesystem::path & destDir)
511+
void clone(const Settings & settings, Store & store, const Input & input, const std::filesystem::path & destDir)
512512
const override
513513
{
514514
auto host = maybeGetStrAttr(input.attrs, "host").value_or("gitlab.com");
@@ -538,7 +538,7 @@ struct SourceHutInputScheme : GitArchiveInputScheme
538538
// Once it is implemented, however, should work as expected.
539539
}
540540

541-
RefInfo getRevFromRef(const Settings & settings, nix::ref<Store> store, const Input & input) const override
541+
RefInfo getRevFromRef(const Settings & settings, nix::Store & store, const Input & input) const override
542542
{
543543
// TODO: In the future, when the sourcehut graphql API is implemented for mercurial
544544
// and with anonymous access, this method should use it instead.
@@ -554,7 +554,7 @@ struct SourceHutInputScheme : GitArchiveInputScheme
554554
std::string refUri;
555555
if (ref == "HEAD") {
556556
auto downloadFileResult = downloadFile(store, settings, fmt("%s/HEAD", base_url), "source", headers);
557-
auto contents = store->requireStoreObjectAccessor(downloadFileResult.storePath)->readFile(CanonPath::root);
557+
auto contents = store.requireStoreObjectAccessor(downloadFileResult.storePath)->readFile(CanonPath::root);
558558

559559
auto remoteLine = git::parseLsRemoteLine(getLine(contents).first);
560560
if (!remoteLine) {
@@ -567,7 +567,7 @@ struct SourceHutInputScheme : GitArchiveInputScheme
567567
std::regex refRegex(refUri);
568568

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

573573
std::string line;
@@ -598,7 +598,7 @@ struct SourceHutInputScheme : GitArchiveInputScheme
598598
return DownloadUrl{parseURL(url), headers};
599599
}
600600

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

0 commit comments

Comments
 (0)