Skip to content

Commit 75ab763

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0074c91 commit 75ab763

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

diff.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3101,6 +3101,15 @@ static int is_conflict_marker(const char *line, int marker_size, unsigned long l
31013101
return 1;
31023102
}
31033103

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+
31043113
static void checkdiff_consume(void *priv, char *line, unsigned long len)
31053114
{
31063115
struct checkdiff_t *data = priv;
@@ -3136,12 +3145,6 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)
31363145
data->o->file, set, reset, ws);
31373146
} else if (line[0] == ' ') {
31383147
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");
31453148
}
31463149
}
31473150

@@ -3650,8 +3653,9 @@ static void builtin_checkdiff(const char *name_a, const char *name_b,
36503653
memset(&xecfg, 0, sizeof(xecfg));
36513654
xecfg.ctxlen = 1; /* at least one context line */
36523655
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))
36553659
die("unable to generate checkdiff for %s", one->path);
36563660

36573661
if (data.ws_rule & WS_BLANK_AT_EOF) {

0 commit comments

Comments
 (0)