From a9ebc3ea5db2fb0cbf7ab8ea35c9d9d5073abfc8 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sun, 2 Feb 2020 13:06:00 +0100 Subject: [PATCH] Remove the git+ and hg+ prefixes from structured input refs --- src/libstore/fetchers/git.cc | 11 ++++++----- src/libstore/fetchers/mercurial.cc | 9 +++++---- tests/flakes.sh | 5 ++++- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/libstore/fetchers/git.cc b/src/libstore/fetchers/git.cc index 67cb5a9e0..0101744bd 100644 --- a/src/libstore/fetchers/git.cc +++ b/src/libstore/fetchers/git.cc @@ -104,6 +104,7 @@ struct GitInput : Input std::string to_string() 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); return url2.to_string(); @@ -159,19 +160,19 @@ struct GitInput : Input std::optional getSourcePath() const override { - if (url.scheme == "git+file" && !ref && !rev) + if (url.scheme == "file" && !ref && !rev) return url.path; return {}; } std::pair 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 // HEAD). static bool forceHttp = getEnv("_NIX_FORCE_HTTP") == "1"; // for testing - bool isLocal = url.scheme == "git+file" && !forceHttp; - return {isLocal, isLocal ? url.path : std::string(url.base, 4)}; + bool isLocal = url.scheme == "file" && !forceHttp; + return {isLocal, isLocal ? url.path : url.base}; } std::pair> fetchTreeInternal(nix::ref store) const override @@ -382,7 +383,7 @@ struct GitInputScheme : InputScheme url.scheme != "git+file") return nullptr; auto url2(url); - // FIXME: strip git+ + if (hasPrefix(url2.scheme, "git+")) url2.scheme = std::string(url2.scheme, 4); url2.query.clear(); Input::Attrs attrs; diff --git a/src/libstore/fetchers/mercurial.cc b/src/libstore/fetchers/mercurial.cc index 0eb81d014..9b8c2132c 100644 --- a/src/libstore/fetchers/mercurial.cc +++ b/src/libstore/fetchers/mercurial.cc @@ -46,6 +46,7 @@ struct MercurialInput : Input std::string to_string() 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(); @@ -78,15 +79,15 @@ struct MercurialInput : Input std::optional getSourcePath() const { - if (url.scheme == "hg+file" && !ref && !rev) + if (url.scheme == "file" && !ref && !rev) return url.path; return {}; } std::pair getActualUrl() const { - bool isLocal = url.scheme == "hg+file"; - return {isLocal, isLocal ? url.path : std::string(url.base, 3)}; + bool isLocal = url.scheme == "file"; + return {isLocal, isLocal ? url.path : url.base}; } std::pair> fetchTreeInternal(nix::ref store) const override @@ -273,7 +274,7 @@ struct MercurialInputScheme : InputScheme url.scheme != "hg+file") return nullptr; auto url2(url); - // FIXME: strip hg+ + url2.scheme = std::string(url2.scheme, 3); url2.query.clear(); Input::Attrs attrs; diff --git a/tests/flakes.sh b/tests/flakes.sh index 1d0da556c..5a00d8671 100644 --- a/tests/flakes.sh +++ b/tests/flakes.sh @@ -516,7 +516,10 @@ cat > $flake3Dir/flake.nix <