summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorJörg Thalheim <joerg@thalheim.io>2020-07-17 10:38:38 +0100
committerJörg Thalheim <joerg@thalheim.io>2020-07-17 10:44:08 +0100
commitd7e89fa661d94edcdfb8c16ed8a74beee6b8d63d (patch)
treef9c7daa2364eb226b73aa8c72c66b81ebfdc2ade /lib
parent3829979d8d29c9f24d52768a0fe485cfb3257a2b (diff)
downloadnixpkgs-d7e89fa661d94edcdfb8c16ed8a74beee6b8d63d.tar
nixpkgs-d7e89fa661d94edcdfb8c16ed8a74beee6b8d63d.tar.gz
nixpkgs-d7e89fa661d94edcdfb8c16ed8a74beee6b8d63d.tar.bz2
nixpkgs-d7e89fa661d94edcdfb8c16ed8a74beee6b8d63d.tar.lz
nixpkgs-d7e89fa661d94edcdfb8c16ed8a74beee6b8d63d.tar.xz
nixpkgs-d7e89fa661d94edcdfb8c16ed8a74beee6b8d63d.tar.zst
nixpkgs-d7e89fa661d94edcdfb8c16ed8a74beee6b8d63d.zip
commitIdFromGitRepo: fix stackoverflow if many branches are used.
If many branches are created than builtins.match stack overflows because
of a bug in libstdc++: see https://github.com/NixOS/nix/issues/2147
Diffstat (limited to 'lib')
-rw-r--r--lib/sources.nix10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/sources.nix b/lib/sources.nix
index ed9bce48530..776fcc32052 100644
--- a/lib/sources.nix
+++ b/lib/sources.nix
@@ -145,10 +145,14 @@ rec {
            # packed-refs file, so we have to grep through it:
            then
              let fileContent = readFile packedRefsName;
-                 matchRef    = match (".*\n([^\n ]*) " + file + "\n.*") fileContent;
-             in if  matchRef == null
+                 matchRef = builtins.match "([a-z0-9]+) ${file}";
+                 isRef = s: builtins.isString s && (matchRef s) != null;
+                 # there is a bug in libstdc++ leading to stackoverflow for long strings:
+                 # https://github.com/NixOS/nix/issues/2147#issuecomment-659868795
+                 refs = builtins.filter isRef (builtins.split "\n" fileContent);
+             in if refs == []
                 then throw ("Could not find " + file + " in " + packedRefsName)
-                else lib.head matchRef
+                else lib.head (matchRef (lib.head refs))
 
            else throw ("Not a .git directory: " + path);
     in readCommitFromFile "HEAD";