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

View file

@ -66,7 +66,7 @@ void emitTreeAttrs(
v.attrs->sort(); 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); state.checkURI(uri);
return uri.find("://") != std::string::npos ? uri : defaultScheme + "://" + 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); 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 { struct FetchTreeParams {
bool emptyRevFallback = false; bool emptyRevFallback = false;
bool allowNameArgument = false; bool allowNameArgument = false;
}; };
static void fetchTree( static void fetchTree(
EvalState &state, EvalState & state,
const Pos &pos, const Pos & pos,
Value **args, Value * * args,
Value &v, Value & v,
const std::optional<std::string> type, const std::optional<std::string> & type,
const FetchTreeParams & params = FetchTreeParams{} const FetchTreeParams & params = FetchTreeParams{}
) { ) {
fetchers::Input input; fetchers::Input input;
@ -126,14 +106,15 @@ static void fetchTree(
for (auto & attr : *args[0]->attrs) { for (auto & attr : *args[0]->attrs) {
state.forceValue(*attr.value); state.forceValue(*attr.value);
if (attr.value->type() == nPath || attr.value->type() == nString) if (attr.value->type() == nPath || attr.value->type() == nString) {
addURI( auto s = state.coerceToString(*attr.pos, *attr.value, context, false, false);
state, attrs.emplace(attr.name,
attrs, attr.name == "url"
attr.name, ? type == "git"
state.coerceToString(*attr.pos, *attr.value, context, false, false), ? fixURIForGit(s, state)
type : fixURI(s, state)
); : s);
}
else if (attr.value->type() == nBool) else if (attr.value->type() == nBool)
attrs.emplace(attr.name, Explicit<bool>{attr.value->boolean}); attrs.emplace(attr.name, Explicit<bool>{attr.value->boolean});
else if (attr.value->type() == nInt) else if (attr.value->type() == nInt)
@ -159,7 +140,6 @@ static void fetchTree(
.errPos = pos .errPos = pos
}); });
input = fetchers::Input::fromAttrs(std::move(attrs)); input = fetchers::Input::fromAttrs(std::move(attrs));
} else { } else {
auto url = state.coerceToString(pos, *args[0], context, false, false); auto url = state.coerceToString(pos, *args[0], context, false, false);