diff options
author | Volth <volth@webmaster.ms> | 2017-07-04 20:09:34 +0000 |
---|---|---|
committer | Volth <volth@webmaster.ms> | 2017-07-04 20:22:13 +0000 |
commit | e7521e289ccbcba8928a0c0a2220fbbb35716556 (patch) | |
tree | cfd1dfefd88393a11df136408a7c7fcacd929c49 /pkgs/build-support/fetchgit | |
parent | b935b21ffd06284d0c8297651d7d28c0961d3274 (diff) |
gitRepoToName: make it compatible with old fetchFromGitHub's "${repo}-${rev}-scr" to avoid mass rebuild
Diffstat (limited to 'pkgs/build-support/fetchgit')
-rw-r--r-- | pkgs/build-support/fetchgit/gitrepotoname.nix | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/pkgs/build-support/fetchgit/gitrepotoname.nix b/pkgs/build-support/fetchgit/gitrepotoname.nix index 9f4392c387f6..90005b545692 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" |