aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/primops
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-05-07 23:06:15 +0200
committerEelco Dolstra <edolstra@gmail.com>2019-05-07 23:32:09 +0200
commit2a41a567e29846cf32d38f338b992069592770c5 (patch)
treeb019c7d139f7f48654d5fa61f350978029d1b2f8 /src/libexpr/primops
parent3c171851a8aed22e977a1798dc5d306faa6e5b63 (diff)
Improve FlakeRef::to_string()
We were incorrectly using path syntax (i.e. /<ref>/<rev>) for Git repositories. This is only valid for GitHub flakerefs.
Diffstat (limited to 'src/libexpr/primops')
-rw-r--r--src/libexpr/primops/flakeref.cc44
1 files changed, 33 insertions, 11 deletions
diff --git a/src/libexpr/primops/flakeref.cc b/src/libexpr/primops/flakeref.cc
index 141d61c0d..784a0868e 100644
--- a/src/libexpr/primops/flakeref.cc
+++ b/src/libexpr/primops/flakeref.cc
@@ -147,30 +147,52 @@ FlakeRef::FlakeRef(const std::string & uri, bool allowRelative)
std::string FlakeRef::to_string() const
{
std::string string;
-
- if (auto refData = std::get_if<FlakeRef::IsAlias>(&data))
+ bool first = true;
+
+ auto addParam =
+ [&](const std::string & name, std::string value) {
+ string += first ? '?' : '&';
+ first = false;
+ string += name;
+ string += '=';
+ string += value; // FIXME: escaping
+ };
+
+ if (auto refData = std::get_if<FlakeRef::IsAlias>(&data)) {
string = refData->alias;
+ if (ref) string += '/' + *ref;
+ if (rev) string += '/' + rev->to_string(Base16, false);
+ }
+
+ else if (auto refData = std::get_if<FlakeRef::IsPath>(&data)) {
+ assert(subdir == "");
+ assert(!rev);
+ assert(!ref);
+ return refData->path;
+ }
else if (auto refData = std::get_if<FlakeRef::IsGitHub>(&data)) {
assert(!(ref && rev));
string = "github:" + refData->owner + "/" + refData->repo;
+ if (ref) { string += '/'; string += *ref; }
+ if (rev) { string += '/'; string += rev->to_string(Base16, false); }
+ if (subdir != "") addParam("dir", subdir);
}
else if (auto refData = std::get_if<FlakeRef::IsGit>(&data)) {
assert(!rev || ref);
string = refData->uri;
- }
- else if (auto refData = std::get_if<FlakeRef::IsPath>(&data))
- return refData->path;
-
- else abort();
+ if (ref) {
+ addParam("ref", *ref);
+ if (rev)
+ addParam("rev", rev->to_string(Base16, false));
+ }
- // FIXME: need to use ?rev etc. for IsGit URIs.
- string += (ref ? "/" + *ref : "") +
- (rev ? "/" + rev->to_string(Base16, false) : "");
+ if (subdir != "") addParam("dir", subdir);
+ }
- if (subdir != "") string += "?dir=" + subdir;
+ else abort();
return string;
}