From 958ec5de568904a07ef050418088d882cbf2ea61 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sun, 2 Feb 2020 11:31:58 +0100 Subject: [PATCH] Cleanup --- src/libexpr/flake/flake.cc | 12 ++++-------- src/libexpr/flake/flakeref.cc | 16 ++++++---------- src/libexpr/flake/flakeref.hh | 10 ++-------- src/libexpr/flake/lockfile.cc | 4 ++-- src/libstore/fetchers/fetchers.hh | 4 ++++ src/nix/profile.cc | 2 +- 6 files changed, 19 insertions(+), 29 deletions(-) diff --git a/src/libexpr/flake/flake.cc b/src/libexpr/flake/flake.cc index 37b6f6c2c..a0f5158c5 100644 --- a/src/libexpr/flake/flake.cc +++ b/src/libexpr/flake/flake.cc @@ -22,7 +22,7 @@ static FlakeRef maybeLookupFlake( const FlakeRef & flakeRef, bool allowLookup) { - if (!flakeRef.isDirect()) { + if (!flakeRef.input->isDirect()) { if (allowLookup) return flakeRef.resolve(state.store); else @@ -150,9 +150,7 @@ static Flake getFlake(EvalState & state, const FlakeRef & originalRef, maybeLookupFlake(state, lookupInFlakeCache(flakeCache, originalRef), allowLookup)); - auto [sourceInfo, resolvedInput] = flakeRef.input->fetchTree(state.store); - - FlakeRef lockedRef(resolvedInput, flakeRef.subdir); + auto [sourceInfo, lockedRef] = flakeRef.fetchTree(state.store); debug("got flake source '%s' from '%s'", state.store->printStorePath(sourceInfo.storePath), lockedRef); @@ -257,9 +255,7 @@ static std::pair getNonFlake( maybeLookupFlake(state, lookupInFlakeCache(flakeCache, originalRef), allowLookup)); - auto [sourceInfo, resolvedInput] = flakeRef.input->fetchTree(state.store); - - FlakeRef lockedRef(resolvedInput, flakeRef.subdir); + auto [sourceInfo, lockedRef] = flakeRef.fetchTree(state.store); debug("got non-flake source '%s' from '%s'", state.store->printStorePath(sourceInfo.storePath), lockedRef); @@ -470,7 +466,7 @@ LockedFlake lockFlake( /* We need to update/create a new lock file entry. So fetch the flake/non-flake. */ - if (!lockFlags.allowMutable && !input.ref.isImmutable()) + if (!lockFlags.allowMutable && !input.ref.input->isImmutable()) throw Error("cannot update flake input '%s' in pure mode", inputPathS); if (input.isFlake) { diff --git a/src/libexpr/flake/flakeref.cc b/src/libexpr/flake/flakeref.cc index 194332674..5fc462246 100644 --- a/src/libexpr/flake/flakeref.cc +++ b/src/libexpr/flake/flakeref.cc @@ -27,16 +27,6 @@ fetchers::Input::Attrs FlakeRef::toAttrs() const return attrs; } -bool FlakeRef::isDirect() const -{ - return input->isDirect(); -} - -bool FlakeRef::isImmutable() const -{ - return input->isImmutable(); -} - std::ostream & operator << (std::ostream & str, const FlakeRef & flakeRef) { str << flakeRef.to_string(); @@ -182,4 +172,10 @@ FlakeRef FlakeRef::fromAttrs(const fetchers::Input::Attrs & attrs) fetchers::maybeGetStrAttr(attrs, "subdir").value_or("")); } +std::pair FlakeRef::fetchTree(ref store) const +{ + auto [tree, lockedInput] = input->fetchTree(store); + return {std::move(tree), FlakeRef(lockedInput, subdir)}; +} + } diff --git a/src/libexpr/flake/flakeref.hh b/src/libexpr/flake/flakeref.hh index 9febc639d..5acf43957 100644 --- a/src/libexpr/flake/flakeref.hh +++ b/src/libexpr/flake/flakeref.hh @@ -31,17 +31,11 @@ struct FlakeRef fetchers::Input::Attrs toAttrs() const; - /* Check whether this is a "direct" flake reference, that is, not - a flake ID, which requires a lookup in the flake registry. */ - bool isDirect() const; - - /* Check whether this is an "immutable" flake reference, that is, - one that contains a commit hash or content hash. */ - bool isImmutable() const; - FlakeRef resolve(ref store) const; static FlakeRef fromAttrs(const fetchers::Input::Attrs & attrs); + + std::pair fetchTree(ref store) const; }; std::ostream & operator << (std::ostream & str, const FlakeRef & flakeRef); diff --git a/src/libexpr/flake/lockfile.cc b/src/libexpr/flake/lockfile.cc index 9879ef2a7..6a64f113e 100644 --- a/src/libexpr/flake/lockfile.cc +++ b/src/libexpr/flake/lockfile.cc @@ -84,7 +84,7 @@ LockedInput::LockedInput(const nlohmann::json & json) , originalRef(getFlakeRef(json, "originalUrl", "originalUri", "original")) , info(parseTreeInfo(json)) { - if (!lockedRef.isImmutable()) + if (!lockedRef.input->isImmutable()) throw Error("lockfile contains mutable flakeref '%s'", lockedRef); } @@ -136,7 +136,7 @@ nlohmann::json LockedInputs::toJson() const bool LockedInputs::isImmutable() const { for (auto & i : inputs) - if (!i.second.lockedRef.isImmutable() || !i.second.isImmutable()) return false; + if (!i.second.lockedRef.input->isImmutable() || !i.second.isImmutable()) return false; return true; } diff --git a/src/libstore/fetchers/fetchers.hh b/src/libstore/fetchers/fetchers.hh index 7a7ce7d37..0ef79bc45 100644 --- a/src/libstore/fetchers/fetchers.hh +++ b/src/libstore/fetchers/fetchers.hh @@ -33,8 +33,12 @@ struct Input : std::enable_shared_from_this virtual bool operator ==(const Input & other) const { return false; } + /* Check whether this is a "direct" input, that is, not + one that goes through a registry. */ virtual bool isDirect() const { return true; } + /* Check whether this is an "immutable" input, that is, + one that contains a commit hash or content hash. */ virtual bool isImmutable() const { return (bool) narHash; } virtual bool contains(const Input & other) const { return false; } diff --git a/src/nix/profile.cc b/src/nix/profile.cc index c94d92567..1759b83a3 100644 --- a/src/nix/profile.cc +++ b/src/nix/profile.cc @@ -330,7 +330,7 @@ struct CmdProfileUpgrade : virtual SourceExprCommand, MixDefaultProfile, MixProf for (size_t i = 0; i < manifest.elements.size(); ++i) { auto & element(manifest.elements[i]); if (element.source - && !element.source->originalRef.isImmutable() + && !element.source->originalRef.input->isImmutable() && matches(*store, element, i, matchers)) { Activity act(*logger, lvlChatty, actUnknown,