Skip to content

Commit 986c177

Browse files
committedJul 9, 2017
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 d10c3cc; I haven't noticed the part of the PR has already got to master)
2 parents 316dd74 + ab8dd33 commit 986c177

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed
 

‎pkgs/build-support/fetchgit/default.nix

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
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)));
25

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
315
{ url, rev ? "HEAD", md5 ? "", sha256 ? "", leaveDotGit ? deepClone
416
, fetchSubmodules ? true, deepClone ? false
517
, branchName ? null
6-
, name ? gitRepoToName url rev
18+
, name ? urlToName url rev
719
, # Shell code executed after the file has been fetched
820
# successfully. This can do things like check or transform the file.
921
postFetch ? ""
+16-11
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
{ lib }:
22

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;
65

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"

0 commit comments

Comments
 (0)
Please sign in to comment.