3
0
Fork 0
forked from mirrors/nixpkgs
nixpkgs/pkgs/build-support/fetchgit/gitrepotoname.nix

14 lines
408 B
Nix

{ lib }:
urlOrRepo: rev: let
inherit (lib) removeSuffix splitString last;
base = last (splitString ":" (baseNameOf (removeSuffix "/" urlOrRepo)));
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}"