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>
Junio C Hamano committed
Jun 26, 2008 at 15:35 UTC
8f8841e9c8e6a26153b0cf9417c7540cf65ef09f
4 files changed
+25
-16
builtin-apply.c
+2
-3
@@ -979,8 +979,7 @@ static int find_header(char *line, unsigned long size, int *hdrsize, struct patc
979
static void check_whitespace(const char *line, int len, unsigned ws_rule)
980
{
981
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);
983
if (!result)
984
return;
985
@@ -991,7 +990,7 @@ static void check_whitespace(const char *line, int len, unsigned ws_rule)
990
else {
991
err = whitespace_error_string(result);
992
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);
994
free(err);
995
}
996
}
cache.h
+2
-3
@@ -819,9 +819,8 @@ void shift_tree(const unsigned char *, const unsigned char *, unsigned char *, i
819
extern unsigned whitespace_rule_cfg;
820
extern unsigned whitespace_rule(const char *);
821
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);
824
extern char *whitespace_error_string(unsigned ws);
825
extern int ws_fix_copy(char *, const char *, int, unsigned, int *);
826
diff.c
+6
-7
@@ -535,9 +535,9 @@ static void emit_add_line(const char *reset, struct emit_callback *ecbdata, cons
535
else {
536
/* Emit just the prefix, then the rest. */
537
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);
541
}
542
}
543
@@ -1153,8 +1153,7 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)
1153
if (line[0] == '+') {
1154
unsigned bad;
1155
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);
1157
if (!bad)
1158
return;
1159
data->status |= bad;
@@ -1162,8 +1161,8 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)
1161
fprintf(data->file, "%s:%d: %s.\n", data->filename, data->lineno, err);
1162
free(err);
1163
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);
1166
} else if (line[0] == ' ')
1167
data->lineno++;
1168
else if (line[0] == '@') {
ws.c
+15
-3
@@ -117,9 +117,9 @@ char *whitespace_error_string(unsigned ws)
117
}
118
119
/* 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)
123
{
124
unsigned result = 0;
125
int written = 0;
@@ -213,6 +213,18 @@ unsigned check_and_emit_line(const char *line, int len, unsigned ws_rule,
213
return result;
214
}
215
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
+
228
/* Copy the line to the buffer while fixing whitespaces */
229
int ws_fix_copy(char *dst, const char *src, int len, unsigned ws_rule, int *error_count)
230
{