Skip to content

Commit 8f8841e

Browse files
committed
check_and_emit_line(): rename and refactor
The function name was too bland and not explicit enough as to what it is checking. Split it into two, and call the one that checks if there is a whitespace breakage "ws_check()", and call the other one that checks and emits the line after color coding "ws_check_emit()". Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 5ff10dd commit 8f8841e

File tree

4 files changed

+25
-16
lines changed

4 files changed

+25
-16
lines changed

builtin-apply.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -979,8 +979,7 @@ static int find_header(char *line, unsigned long size, int *hdrsize, struct patc
979979
static void check_whitespace(const char *line, int len, unsigned ws_rule)
980980
{
981981
char *err;
982-
unsigned result = check_and_emit_line(line + 1, len - 1, ws_rule,
983-
NULL, NULL, NULL, NULL);
982+
unsigned result = ws_check(line + 1, len - 1, ws_rule);
984983
if (!result)
985984
return;
986985

@@ -991,7 +990,7 @@ static void check_whitespace(const char *line, int len, unsigned ws_rule)
991990
else {
992991
err = whitespace_error_string(result);
993992
fprintf(stderr, "%s:%d: %s.\n%.*s\n",
994-
patch_input_file, linenr, err, len - 2, line + 1);
993+
patch_input_file, linenr, err, len - 2, line + 1);
995994
free(err);
996995
}
997996
}

cache.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -819,9 +819,8 @@ void shift_tree(const unsigned char *, const unsigned char *, unsigned char *, i
819819
extern unsigned whitespace_rule_cfg;
820820
extern unsigned whitespace_rule(const char *);
821821
extern unsigned parse_whitespace_rule(const char *);
822-
extern unsigned check_and_emit_line(const char *line, int len, unsigned ws_rule,
823-
FILE *stream, const char *set,
824-
const char *reset, const char *ws);
822+
extern unsigned ws_check(const char *line, int len, unsigned ws_rule);
823+
extern void ws_check_emit(const char *line, int len, unsigned ws_rule, FILE *stream, const char *set, const char *reset, const char *ws);
825824
extern char *whitespace_error_string(unsigned ws);
826825
extern int ws_fix_copy(char *, const char *, int, unsigned, int *);
827826

diff.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -535,9 +535,9 @@ static void emit_add_line(const char *reset, struct emit_callback *ecbdata, cons
535535
else {
536536
/* Emit just the prefix, then the rest. */
537537
emit_line(ecbdata->file, set, reset, line, ecbdata->nparents);
538-
(void)check_and_emit_line(line + ecbdata->nparents,
539-
len - ecbdata->nparents, ecbdata->ws_rule,
540-
ecbdata->file, set, reset, ws);
538+
ws_check_emit(line + ecbdata->nparents,
539+
len - ecbdata->nparents, ecbdata->ws_rule,
540+
ecbdata->file, set, reset, ws);
541541
}
542542
}
543543

@@ -1153,17 +1153,16 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)
11531153
if (line[0] == '+') {
11541154
unsigned bad;
11551155
data->lineno++;
1156-
bad = check_and_emit_line(line + 1, len - 1,
1157-
data->ws_rule, NULL, NULL, NULL, NULL);
1156+
bad = ws_check(line + 1, len - 1, data->ws_rule);
11581157
if (!bad)
11591158
return;
11601159
data->status |= bad;
11611160
err = whitespace_error_string(bad);
11621161
fprintf(data->file, "%s:%d: %s.\n", data->filename, data->lineno, err);
11631162
free(err);
11641163
emit_line(data->file, set, reset, line, 1);
1165-
(void)check_and_emit_line(line + 1, len - 1, data->ws_rule,
1166-
data->file, set, reset, ws);
1164+
ws_check_emit(line + 1, len - 1, data->ws_rule,
1165+
data->file, set, reset, ws);
11671166
} else if (line[0] == ' ')
11681167
data->lineno++;
11691168
else if (line[0] == '@') {

ws.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ char *whitespace_error_string(unsigned ws)
117117
}
118118

119119
/* If stream is non-NULL, emits the line after checking. */
120-
unsigned check_and_emit_line(const char *line, int len, unsigned ws_rule,
121-
FILE *stream, const char *set,
122-
const char *reset, const char *ws)
120+
static unsigned ws_check_emit_1(const char *line, int len, unsigned ws_rule,
121+
FILE *stream, const char *set,
122+
const char *reset, const char *ws)
123123
{
124124
unsigned result = 0;
125125
int written = 0;
@@ -213,6 +213,18 @@ unsigned check_and_emit_line(const char *line, int len, unsigned ws_rule,
213213
return result;
214214
}
215215

216+
void ws_check_emit(const char *line, int len, unsigned ws_rule,
217+
FILE *stream, const char *set,
218+
const char *reset, const char *ws)
219+
{
220+
(void)ws_check_emit_1(line, len, ws_rule, stream, set, reset, ws);
221+
}
222+
223+
unsigned ws_check(const char *line, int len, unsigned ws_rule)
224+
{
225+
return ws_check_emit_1(line, len, ws_rule, NULL, NULL, NULL, NULL);
226+
}
227+
216228
/* Copy the line to the buffer while fixing whitespaces */
217229
int ws_fix_copy(char *dst, const char *src, int len, unsigned ws_rule, int *error_count)
218230
{

0 commit comments

Comments
 (0)