spacecheck: cap number of lines per file

To prevent merging large text files by accident.

Set the cap at 10k lines. The current line number top list is:
```
    5577 configure.ac
    5561 lib/vtls/openssl.c
    5077 lib/http.c
    4517 lib/ftp.c
    4284 lib/multi.c
```

Closes #22387
This commit is contained in:
Viktor Szakats 2026-07-24 20:26:01 +02:00
parent e093c67f1c
commit c4dcdb8388
No known key found for this signature in database

View file

@ -84,10 +84,7 @@ sub fn_match {
}
sub eol_detect {
my ($content) = @_;
my $cr = () = $content =~ /\r/g;
my $lf = () = $content =~ /\n/g;
my ($cr, $lf) = @_;
if($cr > 0 && $lf == 0) {
return 'cr';
@ -107,6 +104,7 @@ sub eol_detect {
my $max_repeat_space = 79;
my $max_line_len = 192;
my $max_lines = 10000;
my $max_path_len = 64;
my $max_filename_len = 48;
@ -140,7 +138,10 @@ while(my $filename = <$git_ls_files>) {
push @err, 'content: has tab';
}
my $eol = eol_detect($content);
my $cnt_cr = () = $content =~ /\r/g;
my $cnt_lf = () = $content =~ /\n/g;
my $eol = eol_detect($cnt_cr, $cnt_lf);
if($eol eq '') {
push @err, 'content: has mixed EOL types';
@ -156,6 +157,13 @@ while(my $filename = <$git_ls_files>) {
push @err, 'content: must use LF EOL for this file type';
}
if($cnt_cr > $max_lines) {
push @err, sprintf('content: too many lines (%d > %d)', $cnt_cr, $max_lines);
}
elsif($cnt_lf > $max_lines) {
push @err, sprintf('content: too many lines (%d > %d)', $cnt_lf, $max_lines);
}
if($content =~ /[ \t]\n/) {
my $line;
for my $l (split(/\n/, $content)) {