This commit is contained in:
Eelco Dolstra 2021-10-06 17:29:47 +02:00
parent 46753b5e9c
commit 83d86cc1b0

View file

@ -81,26 +81,6 @@ 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;
@ -111,7 +91,7 @@ static void fetchTree(
const Pos & pos,
Value * * args,
Value & v,
const std::optional<std::string> type,
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);