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.

+30 -13
+14 -2
pkgs/build-support/fetchgit/default.nix
··· 1 - {stdenv, git, cacert, gitRepoToName}: 1 + {stdenv, git, cacert}: let 2 + urlToName = url: rev: let 3 + inherit (stdenv.lib) removeSuffix splitString last; 4 + base = last (splitString ":" (baseNameOf (removeSuffix "/" url))); 2 5 6 + matched = builtins.match "(.*).git" base; 7 + 8 + short = builtins.substring 0 7 rev; 9 + 10 + appendShort = if (builtins.match "[a-f0-9]*" rev) != null 11 + then "-${short}" 12 + else ""; 13 + in "${if matched == null then base else builtins.head matched}${appendShort}"; 14 + in 3 15 { url, rev ? "HEAD", md5 ? "", sha256 ? "", leaveDotGit ? deepClone 4 16 , fetchSubmodules ? true, deepClone ? false 5 17 , branchName ? null 6 - , name ? gitRepoToName url rev 18 + , name ? urlToName url rev 7 19 , # Shell code executed after the file has been fetched 8 20 # successfully. This can do things like check or transform the file. 9 21 postFetch ? ""
+16 -11
pkgs/build-support/fetchgit/gitrepotoname.nix
··· 1 1 { lib }: 2 2 3 - urlOrRepo: rev: let 4 - inherit (lib) removeSuffix splitString last; 5 - base = last (splitString ":" (baseNameOf (removeSuffix "/" urlOrRepo))); 3 + let 4 + inherit (lib) removeSuffix hasPrefix removePrefix splitString stringToCharacters concatMapStrings last elem; 6 5 7 - matched = builtins.match "(.*).git" base; 8 - 9 - short = builtins.substring 0 7 rev; 10 - 11 - appendShort = if (builtins.match "[a-f0-9]*" rev) != null 12 - then "-${short}" 13 - else ""; 14 - in "${if matched == null then base else builtins.head matched}${appendShort}" 6 + allowedChars = stringToCharacters "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-._?="; 7 + sanitizeStoreName = s: 8 + let 9 + s' = concatMapStrings (c: if elem c allowedChars then c else "") (stringToCharacters s); 10 + s'' = if hasPrefix "." s' then "_${removePrefix "." s'}" else s'; 11 + in 12 + s''; 13 + in 14 + urlOrRepo: rev: 15 + let 16 + repo' = last (splitString ":" (baseNameOf (removeSuffix ".git" (removeSuffix "/" urlOrRepo)))); 17 + rev' = baseNameOf rev; 18 + in 19 + "${sanitizeStoreName repo'}-${sanitizeStoreName rev'}-src"