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.
This commit is contained in:
Vladimír Čunát 2017-07-09 09:50:30 +02:00
commit d10c3cc5ee
No known key found for this signature in database
GPG Key ID: E747DF1F9575A3AA
2 changed files with 30 additions and 13 deletions

View File

@ -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 { url, rev ? "HEAD", md5 ? "", sha256 ? "", leaveDotGit ? deepClone
, fetchSubmodules ? true, deepClone ? false , fetchSubmodules ? true, deepClone ? false
, branchName ? null , branchName ? null
, name ? gitRepoToName url rev , name ? urlToName url rev
, # Shell code executed after the file has been fetched , # Shell code executed after the file has been fetched
# successfully. This can do things like check or transform the file. # successfully. This can do things like check or transform the file.
postFetch ? "" postFetch ? ""

View File

@ -1,14 +1,19 @@
{ lib }: { lib }:
urlOrRepo: rev: let let
inherit (lib) removeSuffix splitString last; inherit (lib) removeSuffix hasPrefix removePrefix splitString stringToCharacters concatMapStrings last elem;
base = last (splitString ":" (baseNameOf (removeSuffix "/" urlOrRepo)));
matched = builtins.match "(.*).git" base; allowedChars = stringToCharacters "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-._?=";
sanitizeStoreName = s:
short = builtins.substring 0 7 rev; let
s' = concatMapStrings (c: if elem c allowedChars then c else "") (stringToCharacters s);
appendShort = if (builtins.match "[a-f0-9]*" rev) != null s'' = if hasPrefix "." s' then "_${removePrefix "." s'}" else s';
then "-${short}" in
else ""; s'';
in "${if matched == null then base else builtins.head matched}${appendShort}" in
urlOrRepo: rev:
let
repo' = last (splitString ":" (baseNameOf (removeSuffix ".git" (removeSuffix "/" urlOrRepo))));
rev' = baseNameOf rev;
in
"${sanitizeStoreName repo'}-${sanitizeStoreName rev'}-src"