aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-02-02 11:31:58 +0100
committerEelco Dolstra <edolstra@gmail.com>2020-02-02 11:31:58 +0100
commit958ec5de568904a07ef050418088d882cbf2ea61 (patch)
treec3102f9fd58525521638a20f4dc7a10e231f2e02 /src/libexpr
parentb2708694664f41f85ffc8cb6ca51cd0cc599806e (diff)
Cleanup
Diffstat (limited to 'src/libexpr')
-rw-r--r--src/libexpr/flake/flake.cc12
-rw-r--r--src/libexpr/flake/flakeref.cc16
-rw-r--r--src/libexpr/flake/flakeref.hh10
-rw-r--r--src/libexpr/flake/lockfile.cc4
4 files changed, 14 insertions, 28 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<fetchers::Tree, FlakeRef> 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<fetchers::Tree, FlakeRef> FlakeRef::fetchTree(ref<Store> 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> store) const;
static FlakeRef fromAttrs(const fetchers::Input::Attrs & attrs);
+
+ std::pair<fetchers::Tree, FlakeRef> fetchTree(ref<Store> 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;
}