summaryrefslogtreecommitdiff
path: root/diff.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2018-11-13 13:37:27 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-11-13 13:37:27 (GMT)
commit39d23dfa409e51844ddda99599927092c8300f12 (patch)
treef4975a66a1fb9c33a875fe72042e9b7c75519597 /diff.c
parentf22838aa7a6dcf308a3307ba17f8afa40989ad3a (diff)
parent5eade0746e1daf659a9559d804068f9f31614625 (diff)
downloadgit-39d23dfa409e51844ddda99599927092c8300f12.zip
git-39d23dfa409e51844ddda99599927092c8300f12.tar.gz
git-39d23dfa409e51844ddda99599927092c8300f12.tar.bz2
Merge branch 'jk/xdiff-interface'
The interface into "xdiff" library used to discover the offset and size of a generated patch hunk by first formatting it into the textual hunk header "@@ -n,m +k,l @@" and then parsing the numbers out. A new interface has been introduced to allow callers a more direct access to them. * jk/xdiff-interface: xdiff-interface: drop parse_hunk_header() range-diff: use a hunk callback diff: convert --check to use a hunk callback combine-diff: use an xdiff hunk callback diff: use hunk callback for word-diff diff: discard hunk headers for patch-ids earlier diff: avoid generating unused hunk header lines xdiff-interface: provide a separate consume callback for hunks xdiff: provide a separate emit callback for hunks
Diffstat (limited to 'diff.c')
-rw-r--r--diff.c48
1 files changed, 23 insertions, 25 deletions
diff --git a/diff.c b/diff.c
index 8647db3..e38d1ec 100644
--- a/diff.c
+++ b/diff.c
@@ -1912,19 +1912,17 @@ static int color_words_output_graph_prefix(struct diff_words_data *diff_words)
}
}
-static void fn_out_diff_words_aux(void *priv, char *line, unsigned long len)
+static void fn_out_diff_words_aux(void *priv,
+ long minus_first, long minus_len,
+ long plus_first, long plus_len,
+ const char *func, long funclen)
{
struct diff_words_data *diff_words = priv;
struct diff_words_style *style = diff_words->style;
- int minus_first, minus_len, plus_first, plus_len;
const char *minus_begin, *minus_end, *plus_begin, *plus_end;
struct diff_options *opt = diff_words->opt;
const char *line_prefix;
- if (line[0] != '@' || parse_hunk_header(line, len,
- &minus_first, &minus_len, &plus_first, &plus_len))
- return;
-
assert(opt);
line_prefix = diff_line_prefix(opt);
@@ -2074,8 +2072,8 @@ static void diff_words_show(struct diff_words_data *diff_words)
xpp.flags = 0;
/* as only the hunk header will be parsed, we need a 0-context */
xecfg.ctxlen = 0;
- if (xdi_diff_outf(&minus, &plus, fn_out_diff_words_aux, diff_words,
- &xpp, &xecfg))
+ if (xdi_diff_outf(&minus, &plus, fn_out_diff_words_aux, NULL,
+ diff_words, &xpp, &xecfg))
die("unable to generate word diff");
free(minus.ptr);
free(plus.ptr);
@@ -3130,6 +3128,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;
@@ -3165,12 +3172,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");
}
}
@@ -3526,8 +3527,8 @@ static void builtin_diff(const char *name_a,
xecfg.ctxlen = strtoul(v, NULL, 10);
if (o->word_diff)
init_diff_words_data(&ecbdata, o, one, two);
- if (xdi_diff_outf(&mf1, &mf2, fn_out_consume, &ecbdata,
- &xpp, &xecfg))
+ if (xdi_diff_outf(&mf1, &mf2, NULL, fn_out_consume,
+ &ecbdata, &xpp, &xecfg))
die("unable to generate diff for %s", one->path);
if (o->word_diff)
free_diff_words_data(&ecbdata);
@@ -3637,8 +3638,8 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
xpp.anchors_nr = o->anchors_nr;
xecfg.ctxlen = o->context;
xecfg.interhunkctxlen = o->interhunkcontext;
- if (xdi_diff_outf(&mf1, &mf2, diffstat_consume, diffstat,
- &xpp, &xecfg))
+ if (xdi_diff_outf(&mf1, &mf2, discard_hunk_line,
+ diffstat_consume, diffstat, &xpp, &xecfg))
die("unable to generate diffstat for %s", one->path);
}
@@ -3686,7 +3687,8 @@ 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, checkdiff_consume, &data,
+ if (xdi_diff_outf(&mf1, &mf2, checkdiff_consume_hunk,
+ checkdiff_consume, &data,
&xpp, &xecfg))
die("unable to generate checkdiff for %s", one->path);
@@ -5666,10 +5668,6 @@ static void patch_id_consume(void *priv, char *line, unsigned long len)
struct patch_id_t *data = priv;
int new_len;
- /* Ignore line numbers when computing the SHA1 of the patch */
- if (starts_with(line, "@@ -"))
- return;
-
new_len = remove_space(line, len);
git_SHA1_Update(data->ctx, line, new_len);
@@ -5771,8 +5769,8 @@ static int diff_get_patch_id(struct diff_options *options, struct object_id *oid
xpp.flags = 0;
xecfg.ctxlen = 3;
xecfg.flags = 0;
- if (xdi_diff_outf(&mf1, &mf2, patch_id_consume, &data,
- &xpp, &xecfg))
+ if (xdi_diff_outf(&mf1, &mf2, discard_hunk_line,
+ patch_id_consume, &data, &xpp, &xecfg))
return error("unable to generate patch-id diff for %s",
p->one->path);
}