diff: convert --check to use a hunk callback
The "diff --check" code needs to know the line number on which each hunk starts in order to generate its output. We get that now by parsing the hunk header line generated by xdiff, but it's much simpler to just pass it directly using a hunk callback. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Nov 2, 2018 at 02:39 UTC
75ab76306cb97b223b29e9460a9589cfd099213e
1 file changed
+12
-8
diff.c
+12
-8
@@ -3101,6 +3101,15 @@ static int is_conflict_marker(const char *line, int marker_size, unsigned long l
3101
return 1;
3102
}
3103
3104
+static void checkdiff_consume_hunk(void *priv,
3105
+ long ob, long on, long nb, long nn,
3106
+ const char *func, long funclen)
3107
+
3108
+{
3109
+ struct checkdiff_t *data = priv;
3110
+ data->lineno = nb - 1;
3111
+}
3112
+
3113
static void checkdiff_consume(void *priv, char *line, unsigned long len)
3114
{
3115
struct checkdiff_t *data = priv;
@@ -3136,12 +3145,6 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)
3145
data->o->file, set, reset, ws);
3146
} else if (line[0] == ' ') {
3147
data->lineno++;
3139
- } else if (line[0] == '@') {
3140
- char *plus = strchr(line, '+');
3141
- if (plus)
3142
- data->lineno = strtol(plus, NULL, 10) - 1;
3143
- else
3144
- die("invalid diff");
3148
}
3149
}
3150
@@ -3650,8 +3653,9 @@ static void builtin_checkdiff(const char *name_a, const char *name_b,
3653
memset(&xecfg, 0, sizeof(xecfg));
3654
xecfg.ctxlen = 1; /* at least one context line */
3655
xpp.flags = 0;
3653
- if (xdi_diff_outf(&mf1, &mf2, NULL, checkdiff_consume,
3654
- &data, &xpp, &xecfg))
3656
+ if (xdi_diff_outf(&mf1, &mf2, checkdiff_consume_hunk,
3657
+ checkdiff_consume, &data,
3658
+ &xpp, &xecfg))
3659
die("unable to generate checkdiff for %s", one->path);
3660
3661
if (data.ws_rule & WS_BLANK_AT_EOF) {