1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-12-16 14:01:05 +01:00

Change lock file format to use an attribute representation of flake refs rather than URLs

This commit is contained in:
Eelco Dolstra 2020-01-31 19:16:40 +01:00
parent dbefe9e6b8
commit 8414685c0f
12 changed files with 293 additions and 39 deletions

View file

@ -19,6 +19,8 @@ struct GitHubInput : Input
std::optional<std::string> ref;
std::optional<Hash> rev;
std::string type() const override { return "github"; }
bool operator ==(const Input & other) const override
{
auto other2 = dynamic_cast<const GitHubInput *>(&other);
@ -48,6 +50,18 @@ struct GitHubInput : Input
return s;
}
Attrs toAttrsInternal() const override
{
Attrs attrs;
attrs.emplace("owner", owner);
attrs.emplace("repo", repo);
if (ref)
attrs.emplace("ref", *ref);
if (rev)
attrs.emplace("rev", rev->gitRev());
return attrs;
}
void clone(const Path & destDir) const override
{
std::shared_ptr<const Input> input = inputFromURL(fmt("git+ssh://git@github.com/%s/%s.git", owner, repo));
@ -138,7 +152,6 @@ struct GitHubInputScheme : InputScheme
auto path = tokenizeString<std::vector<std::string>>(url.path, "/");
auto input = std::make_unique<GitHubInput>();
input->type = "github";
if (path.size() == 2) {
} else if (path.size() == 3) {
@ -176,6 +189,18 @@ struct GitHubInputScheme : InputScheme
return input;
}
std::unique_ptr<Input> inputFromAttrs(const Input::Attrs & attrs) override
{
if (maybeGetStrAttr(attrs, "type") != "github") return {};
auto input = std::make_unique<GitHubInput>();
input->owner = getStrAttr(attrs, "owner");
input->repo = getStrAttr(attrs, "repo");
input->ref = maybeGetStrAttr(attrs, "ref");
if (auto rev = maybeGetStrAttr(attrs, "rev"))
input->rev = Hash(*rev, htSHA1);
return input;
}
};
static auto r1 = OnStartup([] { registerInputScheme(std::make_unique<GitHubInputScheme>()); });