mirror of
https://github.com/NixOS/nix
synced 2025-06-27 12:41:15 +02:00
Took ref and rev out of FlakeRef
This commit is contained in:
parent
3ec0c82fab
commit
f39670c631
3 changed files with 41 additions and 87 deletions
|
@ -58,11 +58,11 @@ FlakeRef::FlakeRef(const std::string & uri, bool allowRelative)
|
|||
IsFlakeId d;
|
||||
d.id = match[1];
|
||||
if (match[2].matched)
|
||||
d.rev = Hash(match[2], htSHA1);
|
||||
rev = Hash(match[2], htSHA1);
|
||||
else if (match[3].matched) {
|
||||
d.ref = match[3];
|
||||
ref = match[3];
|
||||
if (match[4].matched)
|
||||
d.rev = Hash(match[4], htSHA1);
|
||||
rev = Hash(match[4], htSHA1);
|
||||
}
|
||||
data = d;
|
||||
}
|
||||
|
@ -72,9 +72,9 @@ FlakeRef::FlakeRef(const std::string & uri, bool allowRelative)
|
|||
d.owner = match[1];
|
||||
d.repo = match[2];
|
||||
if (match[3].matched)
|
||||
d.rev = Hash(match[3], htSHA1);
|
||||
rev = Hash(match[3], htSHA1);
|
||||
else if (match[4].matched) {
|
||||
d.ref = match[4];
|
||||
ref = match[4];
|
||||
}
|
||||
data = d;
|
||||
}
|
||||
|
@ -92,16 +92,16 @@ FlakeRef::FlakeRef(const std::string & uri, bool allowRelative)
|
|||
if (name == "rev") {
|
||||
if (!std::regex_match(value, revRegex))
|
||||
throw Error("invalid Git revision '%s'", value);
|
||||
d.rev = Hash(value, htSHA1);
|
||||
rev = Hash(value, htSHA1);
|
||||
} else if (name == "ref") {
|
||||
if (!std::regex_match(value, refRegex2))
|
||||
throw Error("invalid Git ref '%s'", value);
|
||||
d.ref = value;
|
||||
ref = value;
|
||||
} else
|
||||
// FIXME: should probably pass through unknown parameters
|
||||
throw Error("invalid Git flake reference parameter '%s', in '%s'", name, uri);
|
||||
}
|
||||
if (d.rev && !d.ref)
|
||||
if (rev && !ref)
|
||||
throw Error("flake URI '%s' lacks a Git ref", uri);
|
||||
data = d;
|
||||
}
|
||||
|
@ -118,27 +118,18 @@ FlakeRef::FlakeRef(const std::string & uri, bool allowRelative)
|
|||
|
||||
std::string FlakeRef::to_string() const
|
||||
{
|
||||
if (auto refData = std::get_if<FlakeRef::IsFlakeId>(&data)) {
|
||||
return
|
||||
"flake:" + refData->id +
|
||||
(refData->ref ? "/" + *refData->ref : "") +
|
||||
(refData->rev ? "/" + refData->rev->to_string(Base16, false) : "");
|
||||
}
|
||||
std::string string;
|
||||
if (auto refData = std::get_if<FlakeRef::IsFlakeId>(&data))
|
||||
string = "flake:" + refData->id;
|
||||
|
||||
else if (auto refData = std::get_if<FlakeRef::IsGitHub>(&data)) {
|
||||
assert(!refData->ref || !refData->rev);
|
||||
return
|
||||
"github:" + refData->owner + "/" + refData->repo +
|
||||
(refData->ref ? "/" + *refData->ref : "") +
|
||||
(refData->rev ? "/" + refData->rev->to_string(Base16, false) : "");
|
||||
assert(!ref || !rev);
|
||||
string = "github:" + refData->owner + "/" + refData->repo;
|
||||
}
|
||||
|
||||
else if (auto refData = std::get_if<FlakeRef::IsGit>(&data)) {
|
||||
assert(refData->ref || !refData->rev);
|
||||
return
|
||||
refData->uri +
|
||||
(refData->ref ? "?ref=" + *refData->ref : "") +
|
||||
(refData->rev ? "&rev=" + refData->rev->to_string(Base16, false) : "");
|
||||
assert(ref || !rev);
|
||||
string = refData->uri;
|
||||
}
|
||||
|
||||
else if (auto refData = std::get_if<FlakeRef::IsPath>(&data)) {
|
||||
|
@ -146,38 +137,22 @@ std::string FlakeRef::to_string() const
|
|||
}
|
||||
|
||||
else abort();
|
||||
|
||||
string += (ref ? "/" + *ref : "") +
|
||||
(rev ? "/" + rev->to_string(Base16, false) : "");
|
||||
return string;
|
||||
}
|
||||
|
||||
bool FlakeRef::isImmutable() const
|
||||
{
|
||||
if (auto refData = std::get_if<FlakeRef::IsFlakeId>(&data))
|
||||
return (bool) refData->rev;
|
||||
|
||||
else if (auto refData = std::get_if<FlakeRef::IsGitHub>(&data))
|
||||
return (bool) refData->rev;
|
||||
|
||||
else if (auto refData = std::get_if<FlakeRef::IsGit>(&data))
|
||||
return (bool) refData->rev;
|
||||
|
||||
else if (std::get_if<FlakeRef::IsPath>(&data))
|
||||
return false;
|
||||
|
||||
else abort();
|
||||
return (bool) rev;
|
||||
}
|
||||
|
||||
FlakeRef FlakeRef::baseRef() const // Removes the ref and rev from a FlakeRef.
|
||||
{
|
||||
FlakeRef result(*this);
|
||||
if (auto refData = std::get_if<FlakeRef::IsGitHub>(&result.data)) {
|
||||
refData->ref = std::nullopt;
|
||||
refData->rev = std::nullopt;
|
||||
} else if (auto refData = std::get_if<FlakeRef::IsGit>(&result.data)) {
|
||||
refData->ref = std::nullopt;
|
||||
refData->rev = std::nullopt;
|
||||
} else if (auto refData = std::get_if<FlakeRef::IsGit>(&result.data)) {
|
||||
refData->ref = std::nullopt;
|
||||
refData->rev = std::nullopt;
|
||||
}
|
||||
result.ref = std::nullopt;
|
||||
result.rev = std::nullopt;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue