diff options
author | Junio C Hamano <gitster@pobox.com> | 2012-05-17 15:22:13 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2012-05-17 15:22:13 -0700 |
commit | 2e464dd5b220d4d2d8a16d5c43efe7af3c9adda9 (patch) | |
tree | e36a8a20733792bdcad789363fb0f50985123d11 | |
parent | 8be441ea1fbd6e39952c5c314014162900c2c148 (diff) | |
parent | 85c20c304f991b33b59fbf00182a66f5cf6d2960 (diff) | |
download | git-2e464dd5b220d4d2d8a16d5c43efe7af3c9adda9.tar.gz git-2e464dd5b220d4d2d8a16d5c43efe7af3c9adda9.tar.xz |
Merge branch 'rs/xdiff-lose-emit-func'
Simplifies the interface between the implementation of "blame" and
underlying xdiff engine, and removes a lot of unused or unnecessary code
from the latter.
By René Scharfe (6) and Ramsay Jones (1)
* rs/xdiff-lose-emit-func:
builtin/blame.c: Fix a "Using plain integer as NULL pointer" warning
xdiff: remove unused functions
xdiff: remove emit_func() and xdi_diff_hunks()
blame: factor out helper for calling xdi_diff()
blame: use hunk_func(), part 2
blame: use hunk_func(), part 1
xdiff: add hunk_func()
-rw-r--r-- | builtin/blame.c | 53 | ||||
-rw-r--r-- | xdiff-interface.c | 44 | ||||
-rw-r--r-- | xdiff-interface.h | 4 | ||||
-rw-r--r-- | xdiff/xdiff.h | 6 | ||||
-rw-r--r-- | xdiff/xdiffi.c | 17 | ||||
-rw-r--r-- | xdiff/xutils.c | 43 | ||||
-rw-r--r-- | xdiff/xutils.h | 3 |
7 files changed, 51 insertions, 119 deletions
diff --git a/builtin/blame.c b/builtin/blame.c index 324d476ab..24d3dd529 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -88,6 +88,20 @@ struct origin { char path[FLEX_ARRAY]; }; +static int diff_hunks(mmfile_t *file_a, mmfile_t *file_b, long ctxlen, + xdl_emit_hunk_consume_func_t hunk_func, void *cb_data) +{ + xpparam_t xpp = {0}; + xdemitconf_t xecfg = {0}; + xdemitcb_t ecb = {NULL}; + + xpp.flags = xdl_opts; + xecfg.ctxlen = ctxlen; + xecfg.hunk_func = hunk_func; + ecb.priv = cb_data; + return xdi_diff(file_a, file_b, &xpp, &xecfg, &ecb); +} + /* * Prepare diff_filespec and convert it using diff textconv API * if the textconv driver exists. @@ -759,12 +773,14 @@ struct blame_chunk_cb_data { long tlno; }; -static void blame_chunk_cb(void *data, long same, long p_next, long t_next) +static int blame_chunk_cb(long start_a, long count_a, + long start_b, long count_b, void *data) { struct blame_chunk_cb_data *d = data; - blame_chunk(d->sb, d->tlno, d->plno, same, d->target, d->parent); - d->plno = p_next; - d->tlno = t_next; + blame_chunk(d->sb, d->tlno, d->plno, start_b, d->target, d->parent); + d->plno = start_a + count_a; + d->tlno = start_b + count_b; + return 0; } /* @@ -779,8 +795,7 @@ static int pass_blame_to_parent(struct scoreboard *sb, int last_in_target; mmfile_t file_p, file_o; struct blame_chunk_cb_data d; - xpparam_t xpp; - xdemitconf_t xecfg; + memset(&d, 0, sizeof(d)); d.sb = sb; d.target = target; d.parent = parent; last_in_target = find_last_in_target(sb, target); @@ -791,11 +806,7 @@ static int pass_blame_to_parent(struct scoreboard *sb, fill_origin_blob(&sb->revs->diffopt, target, &file_o); num_get_patch++; - memset(&xpp, 0, sizeof(xpp)); - xpp.flags = xdl_opts; - memset(&xecfg, 0, sizeof(xecfg)); - xecfg.ctxlen = 0; - xdi_diff_hunks(&file_p, &file_o, blame_chunk_cb, &d, &xpp, &xecfg); + diff_hunks(&file_p, &file_o, 0, blame_chunk_cb, &d); /* The rest (i.e. anything after tlno) are the same as the parent */ blame_chunk(sb, d.tlno, d.plno, last_in_target, target, parent); @@ -899,12 +910,15 @@ struct handle_split_cb_data { long tlno; }; -static void handle_split_cb(void *data, long same, long p_next, long t_next) +static int handle_split_cb(long start_a, long count_a, + long start_b, long count_b, void *data) { struct handle_split_cb_data *d = data; - handle_split(d->sb, d->ent, d->tlno, d->plno, same, d->parent, d->split); - d->plno = p_next; - d->tlno = t_next; + handle_split(d->sb, d->ent, d->tlno, d->plno, start_b, d->parent, + d->split); + d->plno = start_a + count_a; + d->tlno = start_b + count_b; + return 0; } /* @@ -922,8 +936,7 @@ static void find_copy_in_blob(struct scoreboard *sb, int cnt; mmfile_t file_o; struct handle_split_cb_data d; - xpparam_t xpp; - xdemitconf_t xecfg; + memset(&d, 0, sizeof(d)); d.sb = sb; d.ent = ent; d.parent = parent; d.split = split; /* @@ -943,12 +956,8 @@ static void find_copy_in_blob(struct scoreboard *sb, * file_o is a part of final image we are annotating. * file_p partially may match that image. */ - memset(&xpp, 0, sizeof(xpp)); - xpp.flags = xdl_opts; - memset(&xecfg, 0, sizeof(xecfg)); - xecfg.ctxlen = 1; memset(split, 0, sizeof(struct blame_entry [3])); - xdi_diff_hunks(file_p, &file_o, handle_split_cb, &d, &xpp, &xecfg); + diff_hunks(file_p, &file_o, 1, handle_split_cb, &d); /* remainder, if any, all match the preimage */ handle_split(sb, ent, d.tlno, d.plno, ent->num_lines, parent, split); } diff --git a/xdiff-interface.c b/xdiff-interface.c index 0e2c16922..ecfa05f61 100644 --- a/xdiff-interface.c +++ b/xdiff-interface.c @@ -156,50 +156,6 @@ int xdi_diff_outf(mmfile_t *mf1, mmfile_t *mf2, return ret; } -struct xdiff_emit_hunk_state { - xdiff_emit_hunk_consume_fn consume; - void *consume_callback_data; -}; - -static int process_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb, - xdemitconf_t const *xecfg) -{ - long s1, s2, same, p_next, t_next; - xdchange_t *xch, *xche; - struct xdiff_emit_hunk_state *state = ecb->priv; - xdiff_emit_hunk_consume_fn fn = state->consume; - void *consume_callback_data = state->consume_callback_data; - - for (xch = xscr; xch; xch = xche->next) { - xche = xdl_get_hunk(xch, xecfg); - - s1 = XDL_MAX(xch->i1 - xecfg->ctxlen, 0); - s2 = XDL_MAX(xch->i2 - xecfg->ctxlen, 0); - same = s2 + XDL_MAX(xch->i1 - s1, 0); - p_next = xche->i1 + xche->chg1; - t_next = xche->i2 + xche->chg2; - - fn(consume_callback_data, same, p_next, t_next); - } - return 0; -} - -int xdi_diff_hunks(mmfile_t *mf1, mmfile_t *mf2, - xdiff_emit_hunk_consume_fn fn, void *consume_callback_data, - xpparam_t const *xpp, xdemitconf_t *xecfg) -{ - struct xdiff_emit_hunk_state state; - xdemitcb_t ecb; - - memset(&state, 0, sizeof(state)); - memset(&ecb, 0, sizeof(ecb)); - state.consume = fn; - state.consume_callback_data = consume_callback_data; - xecfg->emit_func = (void (*)())process_diff; - ecb.priv = &state; - return xdi_diff(mf1, mf2, xpp, xecfg, &ecb); -} - int read_mmfile(mmfile_t *ptr, const char *filename) { struct stat st; diff --git a/xdiff-interface.h b/xdiff-interface.h index 49d1116fc..eff7762ee 100644 --- a/xdiff-interface.h +++ b/xdiff-interface.h @@ -4,15 +4,11 @@ #include "xdiff/xdiff.h" typedef void (*xdiff_emit_consume_fn)(void *, char *, unsigned long); -typedef void (*xdiff_emit_hunk_consume_fn)(void *, long, long, long); int xdi_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, xdemitconf_t const *xecfg, xdemitcb_t *ecb); int xdi_diff_outf(mmfile_t *mf1, mmfile_t *mf2, xdiff_emit_consume_fn fn, void *consume_callback_data, xpparam_t const *xpp, xdemitconf_t const *xecfg); -int xdi_diff_hunks(mmfile_t *mf1, mmfile_t *mf2, - xdiff_emit_hunk_consume_fn fn, void *consume_callback_data, - xpparam_t const *xpp, xdemitconf_t *xecfg); int parse_hunk_header(char *line, int len, int *ob, int *on, int *nb, int *nn); diff --git a/xdiff/xdiff.h b/xdiff/xdiff.h index 09215afe6..219a3bbca 100644 --- a/xdiff/xdiff.h +++ b/xdiff/xdiff.h @@ -86,13 +86,17 @@ typedef struct s_xdemitcb { typedef long (*find_func_t)(const char *line, long line_len, char *buffer, long buffer_size, void *priv); +typedef int (*xdl_emit_hunk_consume_func_t)(long start_a, long count_a, + long start_b, long count_b, + void *cb_data); + typedef struct s_xdemitconf { long ctxlen; long interhunkctxlen; unsigned long flags; find_func_t find_func; void *find_func_priv; - void (*emit_func)(); + xdl_emit_hunk_consume_func_t hunk_func; } xdemitconf_t; typedef struct s_bdiffparam { diff --git a/xdiff/xdiffi.c b/xdiff/xdiffi.c index bc889e878..1b7012a11 100644 --- a/xdiff/xdiffi.c +++ b/xdiff/xdiffi.c @@ -538,13 +538,26 @@ void xdl_free_script(xdchange_t *xscr) { } } +static int xdl_call_hunk_func(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb, + xdemitconf_t const *xecfg) +{ + xdchange_t *xch, *xche; + + for (xch = xscr; xch; xch = xche->next) { + xche = xdl_get_hunk(xch, xecfg); + if (xecfg->hunk_func(xch->i1, xche->i1 + xche->chg1 - xch->i1, + xch->i2, xche->i2 + xche->chg2 - xch->i2, + ecb->priv) < 0) + return -1; + } + return 0; +} int xdl_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, xdemitconf_t const *xecfg, xdemitcb_t *ecb) { xdchange_t *xscr; xdfenv_t xe; - emit_func_t ef = xecfg->emit_func ? - (emit_func_t)xecfg->emit_func : xdl_emit_diff; + emit_func_t ef = xecfg->hunk_func ? xdl_call_hunk_func : xdl_emit_diff; if (xdl_do_diff(mf1, mf2, xpp, &xe) < 0) { diff --git a/xdiff/xutils.c b/xdiff/xutils.c index 1b3b471ac..ae6ce0d95 100644 --- a/xdiff/xutils.c +++ b/xdiff/xutils.c @@ -122,35 +122,6 @@ void *xdl_cha_alloc(chastore_t *cha) { return data; } - -void *xdl_cha_first(chastore_t *cha) { - chanode_t *sncur; - - if (!(cha->sncur = sncur = cha->head)) - return NULL; - - cha->scurr = 0; - - return (char *) sncur + sizeof(chanode_t) + cha->scurr; -} - - -void *xdl_cha_next(chastore_t *cha) { - chanode_t *sncur; - - if (!(sncur = cha->sncur)) - return NULL; - cha->scurr += cha->isize; - if (cha->scurr == sncur->icurr) { - if (!(sncur = cha->sncur = sncur->next)) - return NULL; - cha->scurr = 0; - } - - return (char *) sncur + sizeof(chanode_t) + cha->scurr; -} - - long xdl_guess_lines(mmfile_t *mf, long sample) { long nl = 0, size, tsize = 0; char const *data, *cur, *top; @@ -430,20 +401,6 @@ int xdl_num_out(char *out, long val) { return str - out; } - -long xdl_atol(char const *str, char const **next) { - long val, base; - char const *top; - - for (top = str; XDL_ISDIGIT(*top); top++); - if (next) - *next = top; - for (val = 0, base = 1, top--; top >= str; top--, base *= 10) - val += base * (long)(*top - '0'); - return val; -} - - int xdl_emit_hunk_hdr(long s1, long c1, long s2, long c2, const char *func, long funclen, xdemitcb_t *ecb) { int nb = 0; diff --git a/xdiff/xutils.h b/xdiff/xutils.h index 714719a89..ad1428ed6 100644 --- a/xdiff/xutils.h +++ b/xdiff/xutils.h @@ -31,14 +31,11 @@ int xdl_emit_diffrec(char const *rec, long size, char const *pre, long psize, int xdl_cha_init(chastore_t *cha, long isize, long icount); void xdl_cha_free(chastore_t *cha); void *xdl_cha_alloc(chastore_t *cha); -void *xdl_cha_first(chastore_t *cha); -void *xdl_cha_next(chastore_t *cha); long xdl_guess_lines(mmfile_t *mf, long sample); int xdl_recmatch(const char *l1, long s1, const char *l2, long s2, long flags); unsigned long xdl_hash_record(char const **data, char const *top, long flags); unsigned int xdl_hashbits(unsigned int size); int xdl_num_out(char *out, long val); -long xdl_atol(char const *str, char const **next); int xdl_emit_hunk_hdr(long s1, long c1, long s2, long c2, const char *func, long funclen, xdemitcb_t *ecb); int xdl_fall_back_diff(xdfenv_t *diff_env, xpparam_t const *xpp, |