1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-07 01:51:47 +02:00
This commit is contained in:
Eelco Dolstra 2020-01-31 19:35:28 +01:00
parent 8414685c0f
commit 185c3c8240
7 changed files with 62 additions and 34 deletions

View file

@ -370,32 +370,39 @@ struct GitInputScheme : InputScheme
url.scheme != "git+ssh" &&
url.scheme != "git+file") return nullptr;
auto input = std::make_unique<GitInput>(url);
auto url2(url);
// FIXME: strip git+
url2.query.clear();
input->url.query.clear();
Input::Attrs attrs;
attrs.emplace("type", "git");
for (auto &[name, value] : url.query) {
if (name == "rev") {
if (!std::regex_match(value, revRegex))
throw BadURL("Git URL '%s' contains an invalid commit hash", url.url);
input->rev = Hash(value, htSHA1);
}
else if (name == "ref") {
if (!std::regex_match(value, refRegex))
throw BadURL("Git URL '%s' contains an invalid branch/tag name", url.url);
input->ref = value;
}
else input->url.query.insert_or_assign(name, value);
if (name == "rev" || name == "ref")
attrs.emplace(name, value);
else
url2.query.emplace(name, value);
}
return input;
attrs.emplace("url", url2.to_string());
return inputFromAttrs(attrs);
}
std::unique_ptr<Input> inputFromAttrs(const Input::Attrs & attrs) override
{
if (maybeGetStrAttr(attrs, "type") != "git") return {};
for (auto & [name, value] : attrs)
if (name != "type" && name != "url" && name != "ref" && name != "rev")
throw Error("unsupported Git input attribute '%s'", name);
auto input = std::make_unique<GitInput>(parseURL(getStrAttr(attrs, "url")));
input->ref = maybeGetStrAttr(attrs, "ref");
if (auto ref = maybeGetStrAttr(attrs, "ref")) {
if (!std::regex_match(*ref, refRegex))
throw BadURL("invalid Git branch/tag name '%s'", *ref);
input->ref = *ref;
}
if (auto rev = maybeGetStrAttr(attrs, "rev"))
input->rev = Hash(*rev, htSHA1);
return input;