@@ -41,6 +41,8 @@ static enum whitespace_eol {
4141 strip_and_apply ,
4242} new_whitespace = nowarn ;
4343static int whitespace_error = 0 ;
44+ static int squelch_whitespace_errors = 5 ;
45+ static int applied_after_stripping = 0 ;
4446static const char * patch_input_file = NULL ;
4547
4648/*
@@ -832,11 +834,16 @@ static int parse_fragment(char *line, unsigned long size, struct patch *patch, s
832834 */
833835 if ((new_whitespace != nowarn ) &&
834836 isspace (line [len - 2 ])) {
835- fprintf (stderr , "Added whitespace\n" );
836- fprintf (stderr , "%s:%d:%.*s\n" ,
837- patch_input_file ,
838- linenr , len - 2 , line + 1 );
839- whitespace_error = 1 ;
837+ whitespace_error ++ ;
838+ if (squelch_whitespace_errors &&
839+ squelch_whitespace_errors <
840+ whitespace_error )
841+ ;
842+ else {
843+ fprintf (stderr , "Adds trailing whitespace.\n%s:%d:%.*s\n" ,
844+ patch_input_file ,
845+ linenr , len - 2 , line + 1 );
846+ }
840847 }
841848 added ++ ;
842849 newlines -- ;
@@ -1129,6 +1136,7 @@ static int apply_line(char *output, const char *patch, int plen)
11291136 plen -- ;
11301137 while (0 < plen && isspace (patch [plen ]))
11311138 plen -- ;
1139+ applied_after_stripping ++ ;
11321140 }
11331141 memcpy (output , patch + 1 , plen );
11341142 if (add_nl_to_tail )
@@ -1895,11 +1903,16 @@ int main(int argc, char **argv)
18951903 new_whitespace = error_on_whitespace ;
18961904 continue ;
18971905 }
1906+ if (!strcmp (arg + 13 , "error-all" )) {
1907+ new_whitespace = error_on_whitespace ;
1908+ squelch_whitespace_errors = 0 ;
1909+ continue ;
1910+ }
18981911 if (!strcmp (arg + 13 , "strip" )) {
18991912 new_whitespace = strip_and_apply ;
19001913 continue ;
19011914 }
1902- die ("unrecognixed whitespace option '%s'" , arg + 13 );
1915+ die ("unrecognized whitespace option '%s'" , arg + 13 );
19031916 }
19041917
19051918 if (check_index && prefix_length < 0 ) {
@@ -1919,7 +1932,31 @@ int main(int argc, char **argv)
19191932 }
19201933 if (read_stdin )
19211934 apply_patch (0 , "<stdin>" );
1922- if (whitespace_error && new_whitespace == error_on_whitespace )
1923- return 1 ;
1935+ if (whitespace_error ) {
1936+ if (squelch_whitespace_errors &&
1937+ squelch_whitespace_errors < whitespace_error ) {
1938+ int squelched =
1939+ whitespace_error - squelch_whitespace_errors ;
1940+ fprintf (stderr , "warning: squelched %d whitespace error%s\n" ,
1941+ squelched ,
1942+ squelched == 1 ? "" : "s" );
1943+ }
1944+ if (new_whitespace == error_on_whitespace )
1945+ die ("%d line%s add%s trailing whitespaces." ,
1946+ whitespace_error ,
1947+ whitespace_error == 1 ? "" : "s" ,
1948+ whitespace_error == 1 ? "s" : "" );
1949+ if (applied_after_stripping )
1950+ fprintf (stderr , "warning: %d line%s applied after"
1951+ " stripping trailing whitespaces.\n" ,
1952+ applied_after_stripping ,
1953+ applied_after_stripping == 1 ? "" : "s" );
1954+ else if (whitespace_error )
1955+ fprintf (stderr , "warning: %d line%s add%s trailing"
1956+ " whitespaces.\n" ,
1957+ whitespace_error ,
1958+ whitespace_error == 1 ? "" : "s" ,
1959+ whitespace_error == 1 ? "s" : "" );
1960+ }
19241961 return 0 ;
19251962}
0 commit comments