git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #12597 from zimbatm/nix-prefetch-git-name

nix-prefetch-git: use fetchgit's naming heuristic

commite63a3a6ad4a1a3fe7d5b7a2d07fd6ef8f8563bac authorDaniel Peebles <copumpkin@users.noreply.github.com> dateSat 13 Feb 2016, 10:53 (11 years ago) parent8cdccc802f5a01
1 file changed+20−3
pkgs/build-support/fetchgit/nix-prefetch-git+20−3
pkgs/build-support/fetchgit/nix-prefetch-git+20−3
@@ -102,6 +102,23 @@ hash_from_ref(){
102102 git ls-remote origin | sed -n "\,\t$ref, { s,\(.*\)\t\(.*\),\1,; p; q}"
103103}
104104
105+# Returns a name based on the url and reference
106+#
107+# This function needs to be in sync with nix's fetchgit implementation
108+# of urlToName() to re-use the same nix store paths.
109+url_to_name(){
110+ local url=$1
111+ local ref=$2
112+ # basename removes the / and .git suffixes
113+ local base=$(basename "$url" .git)
114+
115+ if [[ $ref =~ [a-z0-9]+ ]]; then
116+ echo "$base-${ref:0:7}"
117+ else
118+ echo $base
119+ fi
120+}
121+
105122# Fetch everything and checkout the right sha1
106123checkout_hash(){
107124 local hash="$1"
@@ -288,7 +305,7 @@ else
288305 # If the hash was given, a file with that hash may already be in the
289306 # store.
290307 if test -n "$expHash"; then
291− finalPath=$(nix-store --print-fixed-path --recursive "$hashType" "$expHash" git-export)
308+ finalPath=$(nix-store --print-fixed-path --recursive "$hashType" "$expHash" "$(url_to_name "$url" "$rev")")
292309 if ! nix-store --check-validity "$finalPath" 2> /dev/null; then
293310 finalPath=
294311 fi
@@ -302,7 +319,7 @@ else
302319 tmpPath="$(mktemp -d "${TMPDIR:-/tmp}/git-checkout-tmp-XXXXXXXX")"
303320 trap "rm -rf \"$tmpPath\"" EXIT
304321
305− tmpFile="$tmpPath/git-export"
322+ tmpFile="$tmpPath/$(url_to_name "$url" "$rev")"
306323 mkdir "$tmpFile"
307324
308325 # Perform the checkout.
@@ -313,7 +330,7 @@ else
313330 if ! test -n "$QUIET"; then echo "hash is $hash" >&2; fi
314331
315332 # Add the downloaded file to the Nix store.
316− finalPath=$(nix-store --add-fixed --recursive "$hashType" $tmpFile)
333+ finalPath=$(nix-store --add-fixed --recursive "$hashType" "$tmpFile")
317334
318335 if test -n "$expHash" -a "$expHash" != "$hash"; then
319336 echo "hash mismatch for URL \`$url'"