Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/diff.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2018-11-02 09:39:03 +0300
committerJunio C Hamano <gitster@pobox.com>2018-11-05 07:14:35 +0300
commit75ab76306cb97b223b29e9460a9589cfd099213e (patch)
treef41fbc4fa3d168221bca6522003e82fc157d1b92 /diff.c
parent0074c9110db6b8cddc9950f94f69d143379b25ed (diff)
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>
Diffstat (limited to 'diff.c')
-rw-r--r--diff.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/diff.c b/diff.c
index be312bc20d..6a34bbeeeb 100644
--- a/diff.c
+++ b/diff.c
@@ -3101,6 +3101,15 @@ static int is_conflict_marker(const char *line, int marker_size, unsigned long l
return 1;
}
+static void checkdiff_consume_hunk(void *priv,
+ long ob, long on, long nb, long nn,
+ const char *func, long funclen)
+
+{
+ struct checkdiff_t *data = priv;
+ data->lineno = nb - 1;
+}
+
static void checkdiff_consume(void *priv, char *line, unsigned long len)
{
struct checkdiff_t *data = priv;
@@ -3136,12 +3145,6 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)
data->o->file, set, reset, ws);
} else if (line[0] == ' ') {
data->lineno++;
- } else if (line[0] == '@') {
- char *plus = strchr(line, '+');
- if (plus)
- data->lineno = strtol(plus, NULL, 10) - 1;
- else
- die("invalid diff");
}
}
@@ -3650,8 +3653,9 @@ static void builtin_checkdiff(const char *name_a, const char *name_b,
memset(&xecfg, 0, sizeof(xecfg));
xecfg.ctxlen = 1; /* at least one context line */
xpp.flags = 0;
- if (xdi_diff_outf(&mf1, &mf2, NULL, checkdiff_consume,
- &data, &xpp, &xecfg))
+ if (xdi_diff_outf(&mf1, &mf2, checkdiff_consume_hunk,
+ checkdiff_consume, &data,
+ &xpp, &xecfg))
die("unable to generate checkdiff for %s", one->path);
if (data.ws_rule & WS_BLANK_AT_EOF) {