aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2024-06-28 15:53:15 -0700
committerJunio C Hamano <gitster@pobox.com>2024-06-28 15:53:15 -0700
commit903b4da27fdf9dbcc8d2b59c846fcfa90882d6f3 (patch)
tree2cd2842f69fe14fd886bd123afc4ef01bd3fde38
parentMerge branch 'jc/rev-parse-fatal-doc' into maint-2.45 (diff)
parentchainlint.pl: latch CPU count directly reported by /proc/cpuinfo (diff)
downloadgit-903b4da27fdf9dbcc8d2b59c846fcfa90882d6f3.tar.gz
git-903b4da27fdf9dbcc8d2b59c846fcfa90882d6f3.zip
Merge branch 'es/chainlint-ncores-fix' into maint-2.45
The chainlint script (invoked during "make test") did nothing when it failed to detect the number of available CPUs. It now falls back to 1 CPU to avoid the problem. * es/chainlint-ncores-fix: chainlint.pl: latch CPU count directly reported by /proc/cpuinfo chainlint.pl: fix incorrect CPU count on Linux SPARC chainlint.pl: make CPU count computation more robust
-rwxr-xr-xt/chainlint.pl20
1 files changed, 17 insertions, 3 deletions
diff --git a/t/chainlint.pl b/t/chainlint.pl
index 556ee91a15..1bbd985b78 100755
--- a/t/chainlint.pl
+++ b/t/chainlint.pl
@@ -716,11 +716,25 @@ sub fd_colors {
sub ncores {
# Windows
- return $ENV{NUMBER_OF_PROCESSORS} if exists($ENV{NUMBER_OF_PROCESSORS});
+ if (exists($ENV{NUMBER_OF_PROCESSORS})) {
+ my $ncpu = $ENV{NUMBER_OF_PROCESSORS};
+ return $ncpu > 0 ? $ncpu : 1;
+ }
# Linux / MSYS2 / Cygwin / WSL
- do { local @ARGV='/proc/cpuinfo'; return scalar(grep(/^processor[\s\d]*:/, <>)); } if -r '/proc/cpuinfo';
+ if (open my $fh, '<', '/proc/cpuinfo') {
+ my $cpuinfo = do { local $/; <$fh> };
+ close($fh);
+ if ($cpuinfo =~ /^n?cpus active\s*:\s*(\d+)/m) {
+ return $1 if $1 > 0;
+ }
+ my @matches = ($cpuinfo =~ /^(processor|CPU)[\s\d]*:/mg);
+ return @matches ? scalar(@matches) : 1;
+ }
# macOS & BSD
- return qx/sysctl -n hw.ncpu/ if $^O =~ /(?:^darwin$|bsd)/;
+ if ($^O =~ /(?:^darwin$|bsd)/) {
+ my $ncpu = qx/sysctl -n hw.ncpu/;
+ return $ncpu > 0 ? $ncpu : 1;
+ }
return 1;
}