diff options
author | Junio C Hamano <gitster@pobox.com> | 2008-08-13 23:18:22 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2008-08-14 00:30:26 -0700 |
commit | 8a3f524bf2ac534b313a7d8e70cc164cef744949 (patch) | |
tree | ec390ebbf7cb3d7b441043d18956abf82b40e3ad /xdiff-interface.c | |
parent | b463776086a12c587f6d91c0347641fb6f7ddd72 (diff) | |
download | git-8a3f524bf2ac534b313a7d8e70cc164cef744949.tar.gz |
xdiff-interface: hide the whole "xdiff_emit_state" business from the caller
This further enhances xdi_diff_outf() interface so that it takes two
common parameters: the callback function that processes one line at a
time, and a pointer to its application specific callback data structure.
xdi_diff_outf() creates its own "xdiff_emit_state" structure and stashes
these two away inside it, which is used by the lowest level output
function in the xdiff_outf() callchain, consume_one(), to call back to the
application layer. With this restructuring, we lift the requirement that
the caller supplied callback data structure embeds xdiff_emit_state
structure as its first member.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'xdiff-interface.c')
-rw-r--r-- | xdiff-interface.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/xdiff-interface.c b/xdiff-interface.c index bf98866c4f..944ad9887f 100644 --- a/xdiff-interface.c +++ b/xdiff-interface.c @@ -1,5 +1,12 @@ #include "cache.h" #include "xdiff-interface.h" +#include "strbuf.h" + +struct xdiff_emit_state { + xdiff_emit_consume_fn consume; + void *consume_callback_data; + struct strbuf remainder; +}; static int parse_num(char **cp_p, int *num_p) { @@ -55,7 +62,7 @@ static void consume_one(void *priv_, char *s, unsigned long size) unsigned long this_size; ep = memchr(s, '\n', size); this_size = (ep == NULL) ? size : (ep - s + 1); - priv->consume(priv, s, this_size); + priv->consume(priv->consume_callback_data, s, this_size); size -= this_size; s += this_size; } @@ -128,15 +135,21 @@ int xdi_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, xdemitconf_t co } int xdi_diff_outf(mmfile_t *mf1, mmfile_t *mf2, - struct xdiff_emit_state *state, xpparam_t const *xpp, + xdiff_emit_consume_fn fn, void *consume_callback_data, + xpparam_t const *xpp, xdemitconf_t const *xecfg, xdemitcb_t *xecb) { int ret; + struct xdiff_emit_state state; + + memset(&state, 0, sizeof(state)); + state.consume = fn; + state.consume_callback_data = consume_callback_data; xecb->outf = xdiff_outf; - xecb->priv = state; - strbuf_init(&state->remainder, 0); + xecb->priv = &state; + strbuf_init(&state.remainder, 0); ret = xdi_diff(mf1, mf2, xpp, xecfg, xecb); - strbuf_release(&state->remainder); + strbuf_release(&state.remainder); return ret; } |