about summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorEric Seidel <github@eric.seidel.io>2015-10-07 18:37:35 -0700
committerEric Seidel <github@eric.seidel.io>2015-10-07 18:37:35 -0700
commit9be18c4d070794aff37f0ea9dabc2766d4d050bd (patch)
tree5652e5088d058aceaa822000070f8402b5bb7a3c /pkgs/build-support
parent9108533d4ee497fa2242002ae6882c4a4bf240e7 (diff)
parent72660409f5b27f095ee1a355e0577bc406d914b0 (diff)
downloadnixlib-9be18c4d070794aff37f0ea9dabc2766d4d050bd.tar
nixlib-9be18c4d070794aff37f0ea9dabc2766d4d050bd.tar.gz
nixlib-9be18c4d070794aff37f0ea9dabc2766d4d050bd.tar.bz2
nixlib-9be18c4d070794aff37f0ea9dabc2766d4d050bd.tar.lz
nixlib-9be18c4d070794aff37f0ea9dabc2766d4d050bd.tar.xz
nixlib-9be18c4d070794aff37f0ea9dabc2766d4d050bd.tar.zst
nixlib-9be18c4d070794aff37f0ea9dabc2766d4d050bd.zip
Merge pull request #10176 from Ericson2314/fetchgitLocal
Rewrite `fetchgitLocal`
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/fetchgitlocal/default.nix59
1 files changed, 38 insertions, 21 deletions
diff --git a/pkgs/build-support/fetchgitlocal/default.nix b/pkgs/build-support/fetchgitlocal/default.nix
index 43fc4b1179d7..830133b982d3 100644
--- a/pkgs/build-support/fetchgitlocal/default.nix
+++ b/pkgs/build-support/fetchgitlocal/default.nix
@@ -1,23 +1,40 @@
 { runCommand, git, nix }: src:
 
-let hash = import (runCommand "head-hash.nix"
-  { dummy = builtins.currentTime;
-    preferLocalBuild = true; }
-''
-  cd ${toString src}
-  (${git}/bin/git show && ${git}/bin/git diff) > $out
-  hash=$(${nix}/bin/nix-hash $out)
-  echo "\"$hash\"" > $out
-''); in
-
-runCommand "local-git-export"
-  { dummy = hash;
-    preferLocalBuild = true; }
-''
-  cd ${toString src}
-  mkdir -p "$out"
-  for file in $(${git}/bin/git ls-files); do
-    mkdir -p "$out/$(dirname $file)"
-    cp -d $file "$out/$file" || true # don't fail when trying to copy a directory
-  done
-''
+let
+  srcStr = toString src;
+
+  # Adds the current directory (respecting ignored files) to the git store, and returns the hash
+  gitHashFile = runCommand "put-in-git" {
+      nativeBuildInputs = [ git ];
+      dummy = builtins.currentTime; # impure, do every time
+      preferLocalBuild = true;
+    } ''
+      cd ${srcStr}
+      ROOT=$(git rev-parse --show-toplevel) # path to repo
+
+      cp $ROOT/.git/index $ROOT/.git/index-user # backup index
+      git reset # reset index
+      git add . # add current directory
+
+      # hash of current directory
+      # remove trailing newline
+      git rev-parse $(git write-tree) \
+        | tr -d '\n' > $out
+
+      mv $ROOT/.git/index-user $ROOT/.git/index # restore index
+    '';
+
+  gitHash = builtins.readFile gitHashFile; # cache against git hash
+
+  nixPath = runCommand "put-in-nix" {
+      nativeBuildInputs = [ git ];
+      preferLocalBuild = true;
+    } ''
+      mkdir $out
+
+      # dump tar of *current directory* at given revision
+      git -C ${srcStr} archive --format=tar ${gitHash} \
+        | tar xvf - -C $out
+    '';
+
+in nixPath