X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=combine-diff.c;h=eb0d757f47b74161c4bfc1212f4510a6790ff92a;hb=0ba9ea97e2d621fd50ae4be22ee465096267dbae;hp=11f5143eeceb62e75ba993460e35a378a65a4831;hpb=110cb41cbf7b7cfefdc1f9fab521f165dd1d5d00;p=git.git diff --git a/combine-diff.c b/combine-diff.c index 11f5143e..eb0d757f 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -4,7 +4,7 @@ #include "diff.h" #include "diffcore.h" #include "quote.h" -#include "xdiff/xdiff.h" +#include "xdiff-interface.h" static int uninteresting(struct diff_filepair *p) { @@ -111,52 +111,6 @@ static char *grab_blob(const unsigned char *sha1, unsigned long *size) return blob; } -static int parse_num(char **cp_p, unsigned int *num_p) -{ - char *cp = *cp_p; - unsigned int num = 0; - int read_some; - - while ('0' <= *cp && *cp <= '9') - num = num * 10 + *cp++ - '0'; - if (!(read_some = cp - *cp_p)) - return -1; - *cp_p = cp; - *num_p = num; - return 0; -} - -static int parse_hunk_header(char *line, int len, - unsigned int *ob, unsigned int *on, - unsigned int *nb, unsigned int *nn) -{ - char *cp; - cp = line + 4; - if (parse_num(&cp, ob)) { - bad_line: - return error("malformed diff output: %s", line); - } - if (*cp == ',') { - cp++; - if (parse_num(&cp, on)) - goto bad_line; - } - else - *on = 1; - if (*cp++ != ' ' || *cp++ != '+') - goto bad_line; - if (parse_num(&cp, nb)) - goto bad_line; - if (*cp == ',') { - cp++; - if (parse_num(&cp, nn)) - goto bad_line; - } - else - *nn = 1; - return -!!memcmp(cp, " @@", 3); -} - static void append_lost(struct sline *sline, int n, const char *line, int len) { struct lline *lline; @@ -195,9 +149,10 @@ static void append_lost(struct sline *sline, int n, const char *line, int len) } struct combine_diff_state { - char *remainder; - unsigned long remainder_size; - unsigned int lno, ob, on, nb, nn; + struct xdiff_emit_state xm; + + unsigned int lno; + int ob, on, nb, nn; unsigned long nmask; int num_parent; int n; @@ -205,10 +160,9 @@ struct combine_diff_state { struct sline *lost_bucket; }; -static void consume_line(struct combine_diff_state *state, - char *line, - unsigned long len) +static void consume_line(void *state_, char *line, unsigned long len) { + struct combine_diff_state *state = state_; if (5 < len && !memcmp("@@ -", line, 4)) { if (parse_hunk_header(line, len, &state->ob, &state->on, @@ -249,41 +203,6 @@ static void consume_line(struct combine_diff_state *state, } } -static int combine_diff_outf(void *priv_, mmbuffer_t *mb, int nbuf) -{ - struct combine_diff_state *priv = priv_; - int i; - for (i = 0; i < nbuf; i++) { - if (mb[i].ptr[mb[i].size-1] != '\n') { - /* Incomplete line */ - priv->remainder = realloc(priv->remainder, - priv->remainder_size + - mb[i].size); - memcpy(priv->remainder + priv->remainder_size, - mb[i].ptr, mb[i].size); - priv->remainder_size += mb[i].size; - continue; - } - - /* we have a complete line */ - if (!priv->remainder) { - consume_line(priv, mb[i].ptr, mb[i].size); - continue; - } - priv->remainder = realloc(priv->remainder, - priv->remainder_size + - mb[i].size); - memcpy(priv->remainder + priv->remainder_size, - mb[i].ptr, mb[i].size); - consume_line(priv, priv->remainder, - priv->remainder_size + mb[i].size); - free(priv->remainder); - priv->remainder = NULL; - priv->remainder_size = 0; - } - return 0; -} - static void combine_diff(const unsigned char *parent, mmfile_t *result_file, struct sline *sline, int cnt, int n, int num_parent) { @@ -304,9 +223,10 @@ static void combine_diff(const unsigned char *parent, mmfile_t *result_file, xpp.flags = XDF_NEED_MINIMAL; xecfg.ctxlen = 0; xecfg.flags = 0; - ecb.outf = combine_diff_outf; + ecb.outf = xdiff_outf; ecb.priv = &state; memset(&state, 0, sizeof(state)); + state.xm.consume = consume_line; state.nmask = nmask; state.sline = sline; state.lno = 1; @@ -314,9 +234,6 @@ static void combine_diff(const unsigned char *parent, mmfile_t *result_file, state.n = n; xdl_diff(&parent_file, result_file, &xpp, &xecfg, &ecb); - if (state.remainder && state.remainder_size) - consume_line(&state, state.remainder, state.remainder_size); - free(state.remainder); free(parent_file.ptr); /* Assign line numbers for this parent.