]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
spacecheck: cap number of lines per file
authorViktor Szakats <commit@vsz.me>
Fri, 24 Jul 2026 18:26:01 +0000 (20:26 +0200)
committerViktor Szakats <commit@vsz.me>
Sat, 25 Jul 2026 09:33:55 +0000 (11:33 +0200)
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

scripts/spacecheck.pl

index 18543dfd9a02bb5ff60026aff2ec53145a192fa8..44274d0a21b48f08a2372884e82219af390400e6 100755 (executable)
@@ -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)) {