summary refs log tree commit diff
path: root/pkgs/build-support/fetchgit
diff options
context:
space:
mode:
authorVladimír Čunát <vcunat@gmail.com>2017-07-09 10:31:24 +0200
committerVladimír Čunát <vcunat@gmail.com>2017-07-09 10:31:24 +0200
commit986c17727e646112c97d08c9ac76685f3d740495 (patch)
tree9c9448370ce7b29d449ba0f0c2a0f8898fc0c8ad /pkgs/build-support/fetchgit
parent316dd74ab1c19807e7980ff54601f5a3ed3d7a1f (diff)
parentab8dd33e5cda3abe78d244f23e6097cd3e3bca4e (diff)
downloadnixpkgs-986c17727e646112c97d08c9ac76685f3d740495.tar
nixpkgs-986c17727e646112c97d08c9ac76685f3d740495.tar.gz
nixpkgs-986c17727e646112c97d08c9ac76685f3d740495.tar.bz2
nixpkgs-986c17727e646112c97d08c9ac76685f3d740495.tar.lz
nixpkgs-986c17727e646112c97d08c9ac76685f3d740495.tar.xz
nixpkgs-986c17727e646112c97d08c9ac76685f3d740495.tar.zst
nixpkgs-986c17727e646112c97d08c9ac76685f3d740495.zip
Merge: more compatibility for git* fetchers
They're additional commits from #26877.
Changing names of the fetched stuff was changing very many hashes,
and I think it's better to avoid that for the moment to reduce work
needed by nixpkgs users.  The fetchers are expected to be commonly
used even outside nixpkgs, and the current naming wasn't that bad
usually.

(commit analogical to d10c3cc5eedf58e80e2; I haven't noticed the part of
the PR has already got to master)
Diffstat (limited to 'pkgs/build-support/fetchgit')
-rw-r--r--pkgs/build-support/fetchgit/default.nix16
-rw-r--r--pkgs/build-support/fetchgit/gitrepotoname.nix27
2 files changed, 30 insertions, 13 deletions
diff --git a/pkgs/build-support/fetchgit/default.nix b/pkgs/build-support/fetchgit/default.nix
index 57afb1c4ab8..8e060b87ebd 100644
--- a/pkgs/build-support/fetchgit/default.nix
+++ b/pkgs/build-support/fetchgit/default.nix
@@ -1,9 +1,21 @@
-{stdenv, git, cacert, gitRepoToName}:
+{stdenv, git, cacert}: let
+  urlToName = url: rev: let
+    inherit (stdenv.lib) removeSuffix splitString last;
+    base = last (splitString ":" (baseNameOf (removeSuffix "/" url)));
 
+    matched = builtins.match "(.*).git" base;
+
+    short = builtins.substring 0 7 rev;
+
+    appendShort = if (builtins.match "[a-f0-9]*" rev) != null
+      then "-${short}"
+      else "";
+  in "${if matched == null then base else builtins.head matched}${appendShort}";
+in
 { url, rev ? "HEAD", md5 ? "", sha256 ? "", leaveDotGit ? deepClone
 , fetchSubmodules ? true, deepClone ? false
 , branchName ? null
-, name ? gitRepoToName url rev
+, name ? urlToName url rev
 , # Shell code executed after the file has been fetched
   # successfully. This can do things like check or transform the file.
   postFetch ? ""
diff --git a/pkgs/build-support/fetchgit/gitrepotoname.nix b/pkgs/build-support/fetchgit/gitrepotoname.nix
index 9f4392c387f..90005b54569 100644
--- a/pkgs/build-support/fetchgit/gitrepotoname.nix
+++ b/pkgs/build-support/fetchgit/gitrepotoname.nix
@@ -1,14 +1,19 @@
 { lib }:
 
-urlOrRepo: rev: let
-  inherit (lib) removeSuffix splitString last;
-  base = last (splitString ":" (baseNameOf (removeSuffix "/" urlOrRepo)));
+let
+  inherit (lib) removeSuffix hasPrefix removePrefix splitString stringToCharacters concatMapStrings last elem;
 
-  matched = builtins.match "(.*).git" base;
-
-  short = builtins.substring 0 7 rev;
-
-  appendShort = if (builtins.match "[a-f0-9]*" rev) != null
-    then "-${short}"
-    else "";
-in "${if matched == null then base else builtins.head matched}${appendShort}"
\ No newline at end of file
+  allowedChars = stringToCharacters "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-._?=";
+  sanitizeStoreName = s:
+    let
+      s' = concatMapStrings (c: if elem c allowedChars then c else "") (stringToCharacters s);
+      s'' = if hasPrefix "." s' then "_${removePrefix "." s'}" else s';
+    in
+      s'';
+in
+  urlOrRepo: rev:
+    let
+      repo' = last (splitString ":" (baseNameOf (removeSuffix ".git" (removeSuffix "/" urlOrRepo))));
+      rev' = baseNameOf rev;
+    in
+     "${sanitizeStoreName repo'}-${sanitizeStoreName rev'}-src"