aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/fetchers
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstore/fetchers')
-rw-r--r--src/libstore/fetchers/fetchers.hh10
-rw-r--r--src/libstore/fetchers/git.cc4
-rw-r--r--src/libstore/fetchers/github.cc13
-rw-r--r--src/libstore/fetchers/indirect.cc4
-rw-r--r--src/libstore/fetchers/mercurial.cc4
-rw-r--r--src/libstore/fetchers/tarball.cc4
6 files changed, 23 insertions, 16 deletions
diff --git a/src/libstore/fetchers/fetchers.hh b/src/libstore/fetchers/fetchers.hh
index deb1c9c59..5e33ec4ca 100644
--- a/src/libstore/fetchers/fetchers.hh
+++ b/src/libstore/fetchers/fetchers.hh
@@ -5,6 +5,7 @@
#include "path.hh"
#include "tree-info.hh"
#include "attrs.hh"
+#include "parse.hh"
#include <memory>
@@ -45,7 +46,12 @@ struct Input : std::enable_shared_from_this<Input>
virtual std::optional<Hash> getRev() const { return {}; }
- virtual std::string to_string() const = 0;
+ virtual ParsedURL toURL() const = 0;
+
+ std::string to_string() const
+ {
+ return toURL().to_string();
+ }
Attrs toAttrs() const;
@@ -74,8 +80,6 @@ private:
virtual Attrs toAttrsInternal() const = 0;
};
-struct ParsedURL;
-
struct InputScheme
{
virtual ~InputScheme() { }
diff --git a/src/libstore/fetchers/git.cc b/src/libstore/fetchers/git.cc
index ede758544..f6b7820b8 100644
--- a/src/libstore/fetchers/git.cc
+++ b/src/libstore/fetchers/git.cc
@@ -48,14 +48,14 @@ struct GitInput : Input
std::optional<Hash> getRev() const override { return rev; }
- std::string to_string() const override
+ ParsedURL toURL() const override
{
ParsedURL url2(url);
if (url2.scheme != "git") url2.scheme = "git+" + url2.scheme;
if (rev) url2.query.insert_or_assign("rev", rev->gitRev());
if (ref) url2.query.insert_or_assign("ref", *ref);
if (shallow) url2.query.insert_or_assign("shallow", "1");
- return url2.to_string();
+ return url2;
}
Attrs toAttrsInternal() const override
diff --git a/src/libstore/fetchers/github.cc b/src/libstore/fetchers/github.cc
index 0fef456df..5e34ee051 100644
--- a/src/libstore/fetchers/github.cc
+++ b/src/libstore/fetchers/github.cc
@@ -42,13 +42,16 @@ struct GitHubInput : Input
std::optional<Hash> getRev() const override { return rev; }
- std::string to_string() const override
+ ParsedURL toURL() const override
{
- auto s = fmt("github:%s/%s", owner, repo);
+ auto path = owner + "/" + repo;
assert(!(ref && rev));
- if (ref) s += "/" + *ref;
- if (rev) s += "/" + rev->to_string(Base16, false);
- return s;
+ if (ref) path += "/" + *ref;
+ if (rev) path += "/" + rev->to_string(Base16, false);
+ return ParsedURL {
+ .scheme = "github",
+ .path = path,
+ };
}
Attrs toAttrsInternal() const override
diff --git a/src/libstore/fetchers/indirect.cc b/src/libstore/fetchers/indirect.cc
index 963abd85f..37e5afbc4 100644
--- a/src/libstore/fetchers/indirect.cc
+++ b/src/libstore/fetchers/indirect.cc
@@ -43,14 +43,14 @@ struct IndirectInput : Input
&& (!rev || rev == other2->rev);
}
- std::string to_string() const override
+ ParsedURL toURL() const override
{
ParsedURL url;
url.scheme = "flake";
url.path = id;
if (ref) { url.path += '/'; url.path += *ref; };
if (rev) { url.path += '/'; url.path += rev->gitRev(); };
- return url.to_string();
+ return url;
}
Attrs toAttrsInternal() const override
diff --git a/src/libstore/fetchers/mercurial.cc b/src/libstore/fetchers/mercurial.cc
index 5cd43a74e..6fb13391b 100644
--- a/src/libstore/fetchers/mercurial.cc
+++ b/src/libstore/fetchers/mercurial.cc
@@ -42,13 +42,13 @@ struct MercurialInput : Input
std::optional<Hash> getRev() const override { return rev; }
- std::string to_string() const override
+ ParsedURL toURL() const override
{
ParsedURL url2(url);
url2.scheme = "hg+" + url2.scheme;
if (rev) url2.query.insert_or_assign("rev", rev->gitRev());
if (ref) url2.query.insert_or_assign("ref", *ref);
- return url2.to_string();
+ return url;
}
Attrs toAttrsInternal() const override
diff --git a/src/libstore/fetchers/tarball.cc b/src/libstore/fetchers/tarball.cc
index 62d43ca36..2beb7876d 100644
--- a/src/libstore/fetchers/tarball.cc
+++ b/src/libstore/fetchers/tarball.cc
@@ -190,7 +190,7 @@ struct TarballInput : Input
return hash || narHash;
}
- std::string to_string() const override
+ ParsedURL toURL() const override
{
auto url2(url);
// NAR hashes are preferred over file hashes since tar/zip files
@@ -199,7 +199,7 @@ struct TarballInput : Input
url2.query.insert_or_assign("narHash", narHash->to_string(SRI));
else if (hash)
url2.query.insert_or_assign("hash", hash->to_string(SRI));
- return url2.to_string();
+ return url2;
}
Attrs toAttrsInternal() const override