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>
This commit is contained in:
Junio C Hamano 2008-06-26 15:35:21 -07:00
parent 5ff10dd602
commit 8f8841e9c8
4 changed files with 25 additions and 16 deletions

View File

@ -979,8 +979,7 @@ static int find_header(char *line, unsigned long size, int *hdrsize, struct patc
static void check_whitespace(const char *line, int len, unsigned ws_rule) static void check_whitespace(const char *line, int len, unsigned ws_rule)
{ {
char *err; char *err;
unsigned result = check_and_emit_line(line + 1, len - 1, ws_rule, unsigned result = ws_check(line + 1, len - 1, ws_rule);
NULL, NULL, NULL, NULL);
if (!result) if (!result)
return; return;

View File

@ -819,9 +819,8 @@ void shift_tree(const unsigned char *, const unsigned char *, unsigned char *, i
extern unsigned whitespace_rule_cfg; extern unsigned whitespace_rule_cfg;
extern unsigned whitespace_rule(const char *); extern unsigned whitespace_rule(const char *);
extern unsigned parse_whitespace_rule(const char *); extern unsigned parse_whitespace_rule(const char *);
extern unsigned check_and_emit_line(const char *line, int len, unsigned ws_rule, extern unsigned ws_check(const char *line, int len, unsigned ws_rule);
FILE *stream, const char *set, extern void ws_check_emit(const char *line, int len, unsigned ws_rule, FILE *stream, const char *set, const char *reset, const char *ws);
const char *reset, const char *ws);
extern char *whitespace_error_string(unsigned ws); extern char *whitespace_error_string(unsigned ws);
extern int ws_fix_copy(char *, const char *, int, unsigned, int *); extern int ws_fix_copy(char *, const char *, int, unsigned, int *);

7
diff.c
View File

@ -535,7 +535,7 @@ static void emit_add_line(const char *reset, struct emit_callback *ecbdata, cons
else { else {
/* Emit just the prefix, then the rest. */ /* Emit just the prefix, then the rest. */
emit_line(ecbdata->file, set, reset, line, ecbdata->nparents); emit_line(ecbdata->file, set, reset, line, ecbdata->nparents);
(void)check_and_emit_line(line + ecbdata->nparents, ws_check_emit(line + ecbdata->nparents,
len - ecbdata->nparents, ecbdata->ws_rule, len - ecbdata->nparents, ecbdata->ws_rule,
ecbdata->file, set, reset, ws); ecbdata->file, set, reset, ws);
} }
@ -1153,8 +1153,7 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)
if (line[0] == '+') { if (line[0] == '+') {
unsigned bad; unsigned bad;
data->lineno++; data->lineno++;
bad = check_and_emit_line(line + 1, len - 1, bad = ws_check(line + 1, len - 1, data->ws_rule);
data->ws_rule, NULL, NULL, NULL, NULL);
if (!bad) if (!bad)
return; return;
data->status |= bad; data->status |= bad;
@ -1162,7 +1161,7 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)
fprintf(data->file, "%s:%d: %s.\n", data->filename, data->lineno, err); fprintf(data->file, "%s:%d: %s.\n", data->filename, data->lineno, err);
free(err); free(err);
emit_line(data->file, set, reset, line, 1); emit_line(data->file, set, reset, line, 1);
(void)check_and_emit_line(line + 1, len - 1, data->ws_rule, ws_check_emit(line + 1, len - 1, data->ws_rule,
data->file, set, reset, ws); data->file, set, reset, ws);
} else if (line[0] == ' ') } else if (line[0] == ' ')
data->lineno++; data->lineno++;

14
ws.c
View File

@ -117,7 +117,7 @@ char *whitespace_error_string(unsigned ws)
} }
/* If stream is non-NULL, emits the line after checking. */ /* If stream is non-NULL, emits the line after checking. */
unsigned check_and_emit_line(const char *line, int len, unsigned ws_rule, static unsigned ws_check_emit_1(const char *line, int len, unsigned ws_rule,
FILE *stream, const char *set, FILE *stream, const char *set,
const char *reset, const char *ws) const char *reset, const char *ws)
{ {
@ -213,6 +213,18 @@ unsigned check_and_emit_line(const char *line, int len, unsigned ws_rule,
return result; return result;
} }
void ws_check_emit(const char *line, int len, unsigned ws_rule,
FILE *stream, const char *set,
const char *reset, const char *ws)
{
(void)ws_check_emit_1(line, len, ws_rule, stream, set, reset, ws);
}
unsigned ws_check(const char *line, int len, unsigned ws_rule)
{
return ws_check_emit_1(line, len, ws_rule, NULL, NULL, NULL, NULL);
}
/* Copy the line to the buffer while fixing whitespaces */ /* Copy the line to the buffer while fixing whitespaces */
int ws_fix_copy(char *dst, const char *src, int len, unsigned ws_rule, int *error_count) int ws_fix_copy(char *dst, const char *src, int len, unsigned ws_rule, int *error_count)
{ {