summaryrefslogtreecommitdiff
path: root/combine-diff.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2018-11-02 02:38:20 -0400
committerJunio C Hamano <gitster@pobox.com>2018-11-05 13:14:35 +0900
commit0074c9110db6b8cddc9950f94f69d143379b25ed (patch)
treef1119b2d39440b2b5c55394b837b6fab5c341561 /combine-diff.c
parent7c61e25fbf1a4a65208be1197940a383f220a1b7 (diff)
downloadgit-0074c9110db6b8cddc9950f94f69d143379b25ed.tar.gz
combine-diff: use an xdiff hunk callback
A combined diff has to line up the hunks for all of the individual pairwise diffs, and thus needs to know their line numbers and sizes. We get that now by parsing the hunk header line that xdiff generates. However, now that xdiff supports a hunk callback, we can just use the values directly. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'combine-diff.c')
-rw-r--r--combine-diff.c67
1 files changed, 36 insertions, 31 deletions
diff --git a/combine-diff.c b/combine-diff.c
index 195054b87a..e585683ea9 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -344,38 +344,43 @@ struct combine_diff_state {
struct sline *lost_bucket;
};
-static void consume_line(void *state_, char *line, unsigned long len)
+static void consume_hunk(void *state_,
+ long ob, long on,
+ long nb, long nn,
+ const char *funcline, long funclen)
{
struct combine_diff_state *state = state_;
- if (5 < len && !memcmp("@@ -", line, 4)) {
- if (parse_hunk_header(line, len,
- &state->ob, &state->on,
- &state->nb, &state->nn))
- return;
- state->lno = state->nb;
- if (state->nn == 0) {
- /* @@ -X,Y +N,0 @@ removed Y lines
- * that would have come *after* line N
- * in the result. Our lost buckets hang
- * to the line after the removed lines,
- *
- * Note that this is correct even when N == 0,
- * in which case the hunk removes the first
- * line in the file.
- */
- state->lost_bucket = &state->sline[state->nb];
- if (!state->nb)
- state->nb = 1;
- } else {
- state->lost_bucket = &state->sline[state->nb-1];
- }
- if (!state->sline[state->nb-1].p_lno)
- state->sline[state->nb-1].p_lno =
- xcalloc(state->num_parent,
- sizeof(unsigned long));
- state->sline[state->nb-1].p_lno[state->n] = state->ob;
- return;
+
+ state->ob = ob;
+ state->on = on;
+ state->nb = nb;
+ state->nn = nn;
+ state->lno = state->nb;
+ if (state->nn == 0) {
+ /* @@ -X,Y +N,0 @@ removed Y lines
+ * that would have come *after* line N
+ * in the result. Our lost buckets hang
+ * to the line after the removed lines,
+ *
+ * Note that this is correct even when N == 0,
+ * in which case the hunk removes the first
+ * line in the file.
+ */
+ state->lost_bucket = &state->sline[state->nb];
+ if (!state->nb)
+ state->nb = 1;
+ } else {
+ state->lost_bucket = &state->sline[state->nb-1];
}
+ if (!state->sline[state->nb-1].p_lno)
+ state->sline[state->nb-1].p_lno =
+ xcalloc(state->num_parent, sizeof(unsigned long));
+ state->sline[state->nb-1].p_lno[state->n] = state->ob;
+}
+
+static void consume_line(void *state_, char *line, unsigned long len)
+{
+ struct combine_diff_state *state = state_;
if (!state->lost_bucket)
return; /* not in any hunk yet */
switch (line[0]) {
@@ -419,8 +424,8 @@ static void combine_diff(const struct object_id *parent, unsigned int mode,
state.num_parent = num_parent;
state.n = n;
- if (xdi_diff_outf(&parent_file, result_file, NULL, consume_line,
- &state, &xpp, &xecfg))
+ if (xdi_diff_outf(&parent_file, result_file, consume_hunk,
+ consume_line, &state, &xpp, &xecfg))
die("unable to generate combined diff for %s",
oid_to_hex(parent));
free(parent_file.ptr);