aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2021-10-06 17:29:47 +0200
committerEelco Dolstra <edolstra@gmail.com>2021-10-06 17:30:10 +0200
commit83d86cc1b007fc9cac5e9fd64a211cf8d78c9365 (patch)
treec7830b4cc4bd1931c8d1704ecffacc2a902d9e03
parent46753b5e9ca33b41273ac5815e502921008e7fb5 (diff)
Cleanup
-rw-r--r--src/libexpr/primops/fetchTree.cc50
1 files changed, 15 insertions, 35 deletions
diff --git a/src/libexpr/primops/fetchTree.cc b/src/libexpr/primops/fetchTree.cc
index 8ab9049a6..d598febbe 100644
--- a/src/libexpr/primops/fetchTree.cc
+++ b/src/libexpr/primops/fetchTree.cc
@@ -66,7 +66,7 @@ void emitTreeAttrs(
v.attrs->sort();
}
-std::string fixURI(std::string uri, EvalState &state, const std::string & defaultScheme = "file")
+std::string fixURI(std::string uri, EvalState & state, const std::string & defaultScheme = "file")
{
state.checkURI(uri);
return uri.find("://") != std::string::npos ? uri : defaultScheme + "://" + uri;
@@ -81,37 +81,17 @@ std::string fixURIForGit(std::string uri, EvalState & state)
return fixURI(uri, state);
}
-void addURI(
- EvalState &state,
- fetchers::Attrs &attrs,
- Symbol name,
- std::string v,
- const std::optional<std::string> type
-) {
- string n(name);
- if (n == "url") {
- if (type == "git") {
- attrs.emplace("type", "git");
- attrs.emplace(name, fixURIForGit(v, state));
- } else {
- attrs.emplace(name, fixURI(v, state));
- }
- } else {
- attrs.emplace(name, v);
- }
-}
-
struct FetchTreeParams {
bool emptyRevFallback = false;
bool allowNameArgument = false;
};
static void fetchTree(
- EvalState &state,
- const Pos &pos,
- Value **args,
- Value &v,
- const std::optional<std::string> type,
+ EvalState & state,
+ const Pos & pos,
+ Value * * args,
+ Value & v,
+ const std::optional<std::string> & type,
const FetchTreeParams & params = FetchTreeParams{}
) {
fetchers::Input input;
@@ -126,14 +106,15 @@ static void fetchTree(
for (auto & attr : *args[0]->attrs) {
state.forceValue(*attr.value);
- if (attr.value->type() == nPath || attr.value->type() == nString)
- addURI(
- state,
- attrs,
- attr.name,
- state.coerceToString(*attr.pos, *attr.value, context, false, false),
- type
- );
+ if (attr.value->type() == nPath || attr.value->type() == nString) {
+ auto s = state.coerceToString(*attr.pos, *attr.value, context, false, false);
+ attrs.emplace(attr.name,
+ attr.name == "url"
+ ? type == "git"
+ ? fixURIForGit(s, state)
+ : fixURI(s, state)
+ : s);
+ }
else if (attr.value->type() == nBool)
attrs.emplace(attr.name, Explicit<bool>{attr.value->boolean});
else if (attr.value->type() == nInt)
@@ -159,7 +140,6 @@ static void fetchTree(
.errPos = pos
});
-
input = fetchers::Input::fromAttrs(std::move(attrs));
} else {
auto url = state.coerceToString(pos, *args[0], context, false, false);