1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-29 06:21:14 +02:00

Add StoreReference::render

This will be needed for the next step.

Also allows us to write round trip tests.
This commit is contained in:
John Ericson 2024-01-23 15:36:44 -05:00
parent c036d75f9e
commit b59a7a14c4
15 changed files with 233 additions and 3 deletions

View file

@ -4,6 +4,7 @@
#include "url.hh"
#include "store-reference.hh"
#include "file-system.hh"
#include "util.hh"
namespace nix {
@ -17,6 +18,29 @@ static bool isNonUriPath(const std::string & spec)
&& spec.find("/") != std::string::npos;
}
std::string StoreReference::render() const
{
std::string res;
std::visit(
overloaded{
[&](const StoreReference::Auto &) { res = "auto"; },
[&](const StoreReference::Specified & g) {
res = g.scheme;
res += "://";
res += g.authority;
},
},
variant);
if (!params.empty()) {
res += "?";
res += encodeQuery(params);
}
return res;
}
StoreReference StoreReference::parse(const std::string & uri, const StoreReference::Params & extraParams)
{
auto params = extraParams;