Skip to content

Commit 1ba111d

Browse files
committed
checkdiff: pass diff_options to the callback
This way, we could later use more information from the diff_options. Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 8f8841e commit 1ba111d

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

diff.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,18 +1136,19 @@ static void free_diffstat_info(struct diffstat_t *diffstat)
11361136
struct checkdiff_t {
11371137
struct xdiff_emit_state xm;
11381138
const char *filename;
1139-
int lineno, color_diff;
1139+
int lineno;
1140+
struct diff_options *o;
11401141
unsigned ws_rule;
11411142
unsigned status;
1142-
FILE *file;
11431143
};
11441144

11451145
static void checkdiff_consume(void *priv, char *line, unsigned long len)
11461146
{
11471147
struct checkdiff_t *data = priv;
1148-
const char *ws = diff_get_color(data->color_diff, DIFF_WHITESPACE);
1149-
const char *reset = diff_get_color(data->color_diff, DIFF_RESET);
1150-
const char *set = diff_get_color(data->color_diff, DIFF_FILE_NEW);
1148+
int color_diff = DIFF_OPT_TST(data->o, COLOR_DIFF);
1149+
const char *ws = diff_get_color(color_diff, DIFF_WHITESPACE);
1150+
const char *reset = diff_get_color(color_diff, DIFF_RESET);
1151+
const char *set = diff_get_color(color_diff, DIFF_FILE_NEW);
11511152
char *err;
11521153

11531154
if (line[0] == '+') {
@@ -1158,11 +1159,12 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)
11581159
return;
11591160
data->status |= bad;
11601161
err = whitespace_error_string(bad);
1161-
fprintf(data->file, "%s:%d: %s.\n", data->filename, data->lineno, err);
1162+
fprintf(data->o->file, "%s:%d: %s.\n",
1163+
data->filename, data->lineno, err);
11621164
free(err);
1163-
emit_line(data->file, set, reset, line, 1);
1165+
emit_line(data->o->file, set, reset, line, 1);
11641166
ws_check_emit(line + 1, len - 1, data->ws_rule,
1165-
data->file, set, reset, ws);
1167+
data->o->file, set, reset, ws);
11661168
} else if (line[0] == ' ')
11671169
data->lineno++;
11681170
else if (line[0] == '@') {
@@ -1557,9 +1559,8 @@ static void builtin_checkdiff(const char *name_a, const char *name_b,
15571559
data.xm.consume = checkdiff_consume;
15581560
data.filename = name_b ? name_b : name_a;
15591561
data.lineno = 0;
1560-
data.color_diff = DIFF_OPT_TST(o, COLOR_DIFF);
1562+
data.o = o;
15611563
data.ws_rule = whitespace_rule(attr_path);
1562-
data.file = o->file;
15631564

15641565
if (fill_mmfile(&mf1, one) < 0 || fill_mmfile(&mf2, two) < 0)
15651566
die("unable to read files to diff");

0 commit comments

Comments
 (0)