@matheusbsbs / matheus-bagliano / commits / 92a1747eea
Fork 0

apply.c: split check_whitespace() into two

This splits the logic to record the presence of whitespace errors out of the check_whitespace() function, which checks and then records. The new function, record_ws_error(), can be used by the blank-at-eof check that does not use ws_check() logic to report its findings in the same output format. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Sep 3, 2009 at 22:26 UTC 92a1747eeab6bc497db748e79ca4f029b1c1dc10
1 file changed +15 -9
builtin-apply.c
+15 -9
@@ -1055,23 +1055,29 @@ static int find_header(char *line, unsigned long size, int *hdrsize, struct patc
1055 return -1;
1056 }
1057
1058 -static void check_whitespace(const char *line, int len, unsigned ws_rule)
1058 +static void record_ws_error(unsigned result, const char *line, int len, int linenr)
1059 {
1060 char *err;
1061 - unsigned result = ws_check(line + 1, len - 1, ws_rule);
1061 +
1062 if (!result)
1063 return;
1064
1065 whitespace_error++;
1066 if (squelch_whitespace_errors &&
1067 squelch_whitespace_errors < whitespace_error)
1068 - ;
1069 - else {
1070 - err = whitespace_error_string(result);
1071 - fprintf(stderr, "%s:%d: %s.\n%.*s\n",
1072 - patch_input_file, linenr, err, len - 2, line + 1);
1073 - free(err);
1074 - }
1068 + return;
1069 +
1070 + err = whitespace_error_string(result);
1071 + fprintf(stderr, "%s:%d: %s.\n%.*s\n",
1072 + patch_input_file, linenr, err, len, line);
1073 + free(err);
1074 +}
1075 +
1076 +static void check_whitespace(const char *line, int len, unsigned ws_rule)
1077 +{
1078 + unsigned result = ws_check(line + 1, len - 1, ws_rule);
1079 +
1080 + record_ws_error(result, line + 1, len - 2, linenr);
1081 }
1082
1083 /*