summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b463776)
raw | patch | inline | side by side (parent: b463776)
author | Junio C Hamano <gitster@pobox.com> | |
Thu, 14 Aug 2008 06:18:22 +0000 (23:18 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Thu, 14 Aug 2008 07:30:26 +0000 (00:30 -0700) |
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>
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>
builtin-blame.c | patch | blob | history | |
combine-diff.c | patch | blob | history | |
diff.c | patch | blob | history | |
xdiff-interface.c | patch | blob | history | |
xdiff-interface.h | patch | blob | history |
diff --git a/builtin-blame.c b/builtin-blame.c
index 8cca3b16d2ffbadb3f34c4bd80a04121f622abd3..e4d12de8a994434058745439a86929c0d556a3ec 100644 (file)
--- a/builtin-blame.c
+++ b/builtin-blame.c
};
struct blame_diff_state {
- struct xdiff_emit_state xm;
struct patch *ret;
unsigned hunk_post_context;
unsigned hunk_in_pre_context : 1;
memset(&xecfg, 0, sizeof(xecfg));
xecfg.ctxlen = context;
memset(&state, 0, sizeof(state));
- state.xm.consume = process_u_diff;
state.ret = xmalloc(sizeof(struct patch));
state.ret->chunks = NULL;
state.ret->num = 0;
- xdi_diff_outf(file_p, file_o, &state.xm, &xpp, &xecfg, &ecb);
+ xdi_diff_outf(file_p, file_o, process_u_diff, &state, &xpp, &xecfg, &ecb);
if (state.ret->num) {
struct chunk *chunk;
diff --git a/combine-diff.c b/combine-diff.c
index 72dd6d22340ddd2b5f3d9c7887911a16334848bd..31ec0c5165fec5e26b14c2b8eb5df4dc2f63604a 100644 (file)
--- a/combine-diff.c
+++ b/combine-diff.c
}
struct combine_diff_state {
- struct xdiff_emit_state xm;
-
unsigned int lno;
int ob, on, nb, nn;
unsigned long nmask;
xpp.flags = XDF_NEED_MINIMAL;
memset(&xecfg, 0, sizeof(xecfg));
memset(&state, 0, sizeof(state));
- state.xm.consume = consume_line;
state.nmask = nmask;
state.sline = sline;
state.lno = 1;
state.num_parent = num_parent;
state.n = n;
- xdi_diff_outf(&parent_file, result_file,
- &state.xm, &xpp, &xecfg, &ecb);
+ xdi_diff_outf(&parent_file, result_file, consume_line, &state,
+ &xpp, &xecfg, &ecb);
free(parent_file.ptr);
/* Assign line numbers for this parent.
index 913a92f3e92cb489dc58c688a9e14d6a4ff9f895..a6c143251c8cd7da84400b960cb153b6f24c2ae6 100644 (file)
--- a/diff.c
+++ b/diff.c
}
struct diff_words_data {
- struct xdiff_emit_state xm;
struct diff_words_buffer minus, plus;
FILE *file;
};
xpp.flags = XDF_NEED_MINIMAL;
xecfg.ctxlen = diff_words->minus.alloc + diff_words->plus.alloc;
- diff_words->xm.consume = fn_out_diff_words_aux;
- xdi_diff_outf(&minus, &plus, &diff_words->xm, &xpp, &xecfg, &ecb);
-
+ xdi_diff_outf(&minus, &plus, fn_out_diff_words_aux, diff_words,
+ &xpp, &xecfg, &ecb);
free(minus.ptr);
free(plus.ptr);
diff_words->minus.text.size = diff_words->plus.text.size = 0;
typedef unsigned long (*sane_truncate_fn)(char *line, unsigned long len);
struct emit_callback {
- struct xdiff_emit_state xm;
int nparents, color_diff;
unsigned ws_rule;
sane_truncate_fn truncate;
}
struct diffstat_t {
- struct xdiff_emit_state xm;
-
int nr;
int alloc;
struct diffstat_file {
}
struct checkdiff_t {
- struct xdiff_emit_state xm;
const char *filename;
int lineno;
struct diff_options *o;
xecfg.ctxlen = strtoul(diffopts + 10, NULL, 10);
else if (!prefixcmp(diffopts, "-u"))
xecfg.ctxlen = strtoul(diffopts + 2, NULL, 10);
- ecbdata.xm.consume = fn_out_consume;
if (DIFF_OPT_TST(o, COLOR_DIFF_WORDS)) {
ecbdata.diff_words =
xcalloc(1, sizeof(struct diff_words_data));
ecbdata.diff_words->file = o->file;
}
- xdi_diff_outf(&mf1, &mf2, &ecbdata.xm, &xpp, &xecfg, &ecb);
+ xdi_diff_outf(&mf1, &mf2, fn_out_consume, &ecbdata,
+ &xpp, &xecfg, &ecb);
if (DIFF_OPT_TST(o, COLOR_DIFF_WORDS))
free_diff_words_data(&ecbdata);
}
memset(&xecfg, 0, sizeof(xecfg));
xpp.flags = XDF_NEED_MINIMAL | o->xdl_opts;
- xdi_diff_outf(&mf1, &mf2, &diffstat->xm, &xpp, &xecfg, &ecb);
+ xdi_diff_outf(&mf1, &mf2, diffstat_consume, diffstat,
+ &xpp, &xecfg, &ecb);
}
free_and_return:
return;
memset(&data, 0, sizeof(data));
- data.xm.consume = checkdiff_consume;
data.filename = name_b ? name_b : name_a;
data.lineno = 0;
data.o = o;
memset(&xecfg, 0, sizeof(xecfg));
xpp.flags = XDF_NEED_MINIMAL;
- xdi_diff_outf(&mf1, &mf2, &data.xm, &xpp, &xecfg, &ecb);
+ xdi_diff_outf(&mf1, &mf2, checkdiff_consume, &data,
+ &xpp, &xecfg, &ecb);
if ((data.ws_rule & WS_TRAILING_SPACE) &&
data.trailing_blanks_start) {
}
struct patch_id_t {
- struct xdiff_emit_state xm;
SHA_CTX *ctx;
int patchlen;
};
@@ -3055,7 +3049,6 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1)
SHA1_Init(&ctx);
memset(&data, 0, sizeof(struct patch_id_t));
data.ctx = &ctx;
- data.xm.consume = patch_id_consume;
for (i = 0; i < q->nr; i++) {
xpparam_t xpp;
@@ -3120,7 +3113,8 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1)
xpp.flags = XDF_NEED_MINIMAL;
xecfg.ctxlen = 3;
xecfg.flags = XDL_EMIT_FUNCNAMES;
- xdi_diff_outf(&mf1, &mf2, &data.xm, &xpp, &xecfg, &ecb);
+ xdi_diff_outf(&mf1, &mf2, patch_id_consume, &data,
+ &xpp, &xecfg, &ecb);
}
SHA1_Final(sha1, &ctx);
struct diffstat_t diffstat;
memset(&diffstat, 0, sizeof(struct diffstat_t));
- diffstat.xm.consume = diffstat_consume;
for (i = 0; i < q->nr; i++) {
struct diff_filepair *p = q->queue[i];
if (check_pair_status(p))
diff --git a/xdiff-interface.c b/xdiff-interface.c
index bf98866c4f5aa2027135741cb07bc1ec04b11e9f..944ad9887f5c94ca0e63f9a6c901447634f871ce 100644 (file)
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
#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)
{
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;
}
diff --git a/xdiff-interface.h b/xdiff-interface.h
index f6a1ec2220512b9aff5c69c4a7f94b0af0dbe3e2..558492ba38c50351a98f80c16e83a058ace849ab 100644 (file)
--- a/xdiff-interface.h
+++ b/xdiff-interface.h
#define XDIFF_INTERFACE_H
#include "xdiff/xdiff.h"
-#include "strbuf.h"
-
-struct xdiff_emit_state;
typedef void (*xdiff_emit_consume_fn)(void *, char *, unsigned long);
-struct xdiff_emit_state {
- xdiff_emit_consume_fn consume;
- struct strbuf remainder;
-};
-
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,
- 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 parse_hunk_header(char *line, int len,
int *ob, int *on,