From fee334f6725736fe63360f9342eaa2886ad1cb40 Mon Sep 17 00:00:00 2001 From: obadz Date: Wed, 27 Jul 2016 15:44:26 +0100 Subject: [PATCH] lib/sources.nix@commitIdFromGitRepo: remove use of lib.splitString lib.splitString was blowing up the stack in instances where the .git/packed-refs file was too large. We now use a regexp over the whole file instead. Closes #16570 --- lib/sources.nix | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/sources.nix b/lib/sources.nix index 8e58e4b6a9d..535b04523b5 100644 --- a/lib/sources.nix +++ b/lib/sources.nix @@ -55,10 +55,11 @@ rec { # packed-refs file, so we have to grep through it: else if lib.pathExists packedRefsName then - let packedRefs = lib.splitString "\n" (readFile packedRefsName); - matchRule = match ("^(.*) " + file + "$"); - matchedRefs = lib.flatten (lib.filter (m: ! (isNull m)) (map matchRule packedRefs)); - in lib.head matchedRefs + let fileContent = readFile packedRefsName; + matchRef = match ".*\n([^\n ]*) " + file + "\n.*" fileContent; + in if isNull matchRef + then throw ("Could not find " + file + " in " + packedRefsName) + else lib.head matchRef else throw ("Not a .git directory: " + path); in lib.flip readCommitFromFile "HEAD"; }