Skip to content

Commit

Permalink
commitIdFromGitRepo: fix stackoverflow if many branches are used.
Browse files Browse the repository at this point in the history
If many branches are created than builtins.match stack overflows because
of a bug in libstdc++: see NixOS/nix#2147

(cherry picked from commit d7e89fa)
  • Loading branch information
Mic92 authored and lheckemann committed Jul 17, 2020
1 parent b103b4b commit e7c435c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/sources.nix
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,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";
Expand Down

0 comments on commit e7c435c

Please sign in to comment.