Remove the git+ and hg+ prefixes from structured input refs

This commit is contained in:
Eelco Dolstra 2020-02-02 13:06:00 +01:00
parent 90ada8e31a
commit a9ebc3ea5d
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
3 changed files with 15 additions and 10 deletions

View file

@ -104,6 +104,7 @@ struct GitInput : Input
std::string to_string() const override std::string to_string() const override
{ {
ParsedURL url2(url); ParsedURL url2(url);
if (url2.scheme != "git") url2.scheme = "git+" + url2.scheme;
if (rev) url2.query.insert_or_assign("rev", rev->gitRev()); if (rev) url2.query.insert_or_assign("rev", rev->gitRev());
if (ref) url2.query.insert_or_assign("ref", *ref); if (ref) url2.query.insert_or_assign("ref", *ref);
return url2.to_string(); return url2.to_string();
@ -159,19 +160,19 @@ struct GitInput : Input
std::optional<Path> getSourcePath() const override std::optional<Path> getSourcePath() const override
{ {
if (url.scheme == "git+file" && !ref && !rev) if (url.scheme == "file" && !ref && !rev)
return url.path; return url.path;
return {}; return {};
} }
std::pair<bool, std::string> getActualUrl() const std::pair<bool, std::string> getActualUrl() const
{ {
// Don't clone git+file:// URIs (but otherwise treat them the // Don't clone file:// URIs (but otherwise treat them the
// same as remote URIs, i.e. don't use the working tree or // same as remote URIs, i.e. don't use the working tree or
// HEAD). // HEAD).
static bool forceHttp = getEnv("_NIX_FORCE_HTTP") == "1"; // for testing static bool forceHttp = getEnv("_NIX_FORCE_HTTP") == "1"; // for testing
bool isLocal = url.scheme == "git+file" && !forceHttp; bool isLocal = url.scheme == "file" && !forceHttp;
return {isLocal, isLocal ? url.path : std::string(url.base, 4)}; return {isLocal, isLocal ? url.path : url.base};
} }
std::pair<Tree, std::shared_ptr<const Input>> fetchTreeInternal(nix::ref<Store> store) const override std::pair<Tree, std::shared_ptr<const Input>> fetchTreeInternal(nix::ref<Store> store) const override
@ -382,7 +383,7 @@ struct GitInputScheme : InputScheme
url.scheme != "git+file") return nullptr; url.scheme != "git+file") return nullptr;
auto url2(url); auto url2(url);
// FIXME: strip git+ if (hasPrefix(url2.scheme, "git+")) url2.scheme = std::string(url2.scheme, 4);
url2.query.clear(); url2.query.clear();
Input::Attrs attrs; Input::Attrs attrs;

View file

@ -46,6 +46,7 @@ struct MercurialInput : Input
std::string to_string() const override std::string to_string() const override
{ {
ParsedURL url2(url); ParsedURL url2(url);
url2.scheme = "hg+" + url2.scheme;
if (rev) url2.query.insert_or_assign("rev", rev->gitRev()); if (rev) url2.query.insert_or_assign("rev", rev->gitRev());
if (ref) url2.query.insert_or_assign("ref", *ref); if (ref) url2.query.insert_or_assign("ref", *ref);
return url2.to_string(); return url2.to_string();
@ -78,15 +79,15 @@ struct MercurialInput : Input
std::optional<Path> getSourcePath() const std::optional<Path> getSourcePath() const
{ {
if (url.scheme == "hg+file" && !ref && !rev) if (url.scheme == "file" && !ref && !rev)
return url.path; return url.path;
return {}; return {};
} }
std::pair<bool, std::string> getActualUrl() const std::pair<bool, std::string> getActualUrl() const
{ {
bool isLocal = url.scheme == "hg+file"; bool isLocal = url.scheme == "file";
return {isLocal, isLocal ? url.path : std::string(url.base, 3)}; return {isLocal, isLocal ? url.path : url.base};
} }
std::pair<Tree, std::shared_ptr<const Input>> fetchTreeInternal(nix::ref<Store> store) const override std::pair<Tree, std::shared_ptr<const Input>> fetchTreeInternal(nix::ref<Store> store) const override
@ -273,7 +274,7 @@ struct MercurialInputScheme : InputScheme
url.scheme != "hg+file") return nullptr; url.scheme != "hg+file") return nullptr;
auto url2(url); auto url2(url);
// FIXME: strip hg+ url2.scheme = std::string(url2.scheme, 3);
url2.query.clear(); url2.query.clear();
Input::Attrs attrs; Input::Attrs attrs;

View file

@ -516,7 +516,10 @@ cat > $flake3Dir/flake.nix <<EOF
{ {
edition = 201909; edition = 201909;
inputs.flake2.inputs.flake1.url = git+file://$flake7Dir; inputs.flake2.inputs.flake1 = {
type = "git";
url = file://$flake7Dir;
};
outputs = { self, flake2 }: { outputs = { self, flake2 }: {
}; };