about summary refs log tree commit diff
path: root/pkgs/build-support/fetchgit/default.nix
diff options
context:
space:
mode:
authorShea Levy <shea@shealevy.com>2015-01-01 08:34:56 -0500
committerShea Levy <shea@shealevy.com>2015-01-01 10:03:45 -0500
commita8603605aaaf780aa45edd0f16c8c9588455ccf2 (patch)
tree1121c8eb793ff2f50977afd2c256c248b5648f17 /pkgs/build-support/fetchgit/default.nix
parentfdb785f4d14a37c399507aa2aec98e086a566b2a (diff)
downloadnixlib-a8603605aaaf780aa45edd0f16c8c9588455ccf2.tar
nixlib-a8603605aaaf780aa45edd0f16c8c9588455ccf2.tar.gz
nixlib-a8603605aaaf780aa45edd0f16c8c9588455ccf2.tar.bz2
nixlib-a8603605aaaf780aa45edd0f16c8c9588455ccf2.tar.lz
nixlib-a8603605aaaf780aa45edd0f16c8c9588455ccf2.tar.xz
nixlib-a8603605aaaf780aa45edd0f16c8c9588455ccf2.tar.zst
nixlib-a8603605aaaf780aa45edd0f16c8c9588455ccf2.zip
fetchgit: give output a nicer name
Instead of git-export, we get the basename of the repo, plus the
shortrev if the commit-ish is a rev.
Diffstat (limited to 'pkgs/build-support/fetchgit/default.nix')
-rw-r--r--pkgs/build-support/fetchgit/default.nix20
1 files changed, 17 insertions, 3 deletions
diff --git a/pkgs/build-support/fetchgit/default.nix b/pkgs/build-support/fetchgit/default.nix
index c52a26b7165d..2ba48189833e 100644
--- a/pkgs/build-support/fetchgit/default.nix
+++ b/pkgs/build-support/fetchgit/default.nix
@@ -1,6 +1,20 @@
-{stdenv, git, cacert}:
-{url, rev ? "HEAD", md5 ? "", sha256 ? "", leaveDotGit ? false, fetchSubmodules ? true
-, name ? "git-export"
+{stdenv, git, cacert}: let
+  urlToName = url: rev: let
+    base = baseNameOf url;
+
+    matched = (builtins.match or (x: y:
+      abort "This version of fetchgit requires Nix >= 1.8, please upgrade!"
+    )) "(.*).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 ? false
+, fetchSubmodules ? true
+, name ? urlToName url rev
 }:
 
 /* NOTE: