Make xdi_diff_outf interface for running xdiff_outf diffs
To prepare for the need to initialize and release resources for an xdi_diff with the xdiff_outf output function, make a new function to wrap this usage. Old: ecb.outf = xdiff_outf; ecb.priv = &state; ... xdi_diff(file_p, file_o, &xpp, &xecfg, &ecb); New: xdi_diff_outf(file_p, file_o, &state.xm, &xpp, &xecfg, &ecb); Signed-off-by: Brian Downing <bdowning@lavos.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Brian Downing committed
Aug 14, 2008 at 00:36 UTC
c99db9d292c5f63c83ae2b441a67121d76553413
5 files changed
+23
-23
builtin-blame.c
+1
-3
@@ -528,15 +528,13 @@ static struct patch *compare_buffer(mmfile_t *file_p, mmfile_t *file_o,
528
xpp.flags = xdl_opts;
529
memset(&xecfg, 0, sizeof(xecfg));
530
xecfg.ctxlen = context;
531
- ecb.outf = xdiff_outf;
532
- ecb.priv = &state;
531
memset(&state, 0, sizeof(state));
532
state.xm.consume = process_u_diff;
533
state.ret = xmalloc(sizeof(struct patch));
534
state.ret->chunks = NULL;
535
state.ret->num = 0;
536
539
- xdi_diff(file_p, file_o, &xpp, &xecfg, &ecb);
537
+ xdi_diff_outf(file_p, file_o, &state.xm, &xpp, &xecfg, &ecb);
538
539
if (state.ret->num) {
540
struct chunk *chunk;
combine-diff.c
+2
-3
@@ -217,8 +217,6 @@ static void combine_diff(const unsigned char *parent, mmfile_t *result_file,
217
parent_file.size = sz;
218
xpp.flags = XDF_NEED_MINIMAL;
219
memset(&xecfg, 0, sizeof(xecfg));
220
- ecb.outf = xdiff_outf;
221
- ecb.priv = &state;
220
memset(&state, 0, sizeof(state));
221
state.xm.consume = consume_line;
222
state.nmask = nmask;
@@ -227,7 +225,8 @@ static void combine_diff(const unsigned char *parent, mmfile_t *result_file,
225
state.num_parent = num_parent;
226
state.n = n;
227
230
- xdi_diff(&parent_file, result_file, &xpp, &xecfg, &ecb);
228
+ xdi_diff_outf(&parent_file, result_file,
229
+ &state.xm, &xpp, &xecfg, &ecb);
230
free(parent_file.ptr);
231
232
/* Assign line numbers for this parent.
diff.c
+5
-15
@@ -459,10 +459,8 @@ static void diff_words_show(struct diff_words_data *diff_words)
459
460
xpp.flags = XDF_NEED_MINIMAL;
461
xecfg.ctxlen = diff_words->minus.alloc + diff_words->plus.alloc;
462
- ecb.outf = xdiff_outf;
463
- ecb.priv = diff_words;
462
diff_words->xm.consume = fn_out_diff_words_aux;
465
- xdi_diff(&minus, &plus, &xpp, &xecfg, &ecb);
463
+ xdi_diff_outf(&minus, &plus, &diff_words->xm, &xpp, &xecfg, &ecb);
464
465
free(minus.ptr);
466
free(plus.ptr);
@@ -1521,15 +1519,13 @@ static void builtin_diff(const char *name_a,
1519
xecfg.ctxlen = strtoul(diffopts + 10, NULL, 10);
1520
else if (!prefixcmp(diffopts, "-u"))
1521
xecfg.ctxlen = strtoul(diffopts + 2, NULL, 10);
1524
- ecb.outf = xdiff_outf;
1525
- ecb.priv = &ecbdata;
1522
ecbdata.xm.consume = fn_out_consume;
1523
if (DIFF_OPT_TST(o, COLOR_DIFF_WORDS)) {
1524
ecbdata.diff_words =
1525
xcalloc(1, sizeof(struct diff_words_data));
1526
ecbdata.diff_words->file = o->file;
1527
}
1532
- xdi_diff(&mf1, &mf2, &xpp, &xecfg, &ecb);
1528
+ xdi_diff_outf(&mf1, &mf2, &ecbdata.xm, &xpp, &xecfg, &ecb);
1529
if (DIFF_OPT_TST(o, COLOR_DIFF_WORDS))
1530
free_diff_words_data(&ecbdata);
1531
}
@@ -1580,9 +1576,7 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
1576
1577
memset(&xecfg, 0, sizeof(xecfg));
1578
xpp.flags = XDF_NEED_MINIMAL | o->xdl_opts;
1583
- ecb.outf = xdiff_outf;
1584
- ecb.priv = diffstat;
1585
- xdi_diff(&mf1, &mf2, &xpp, &xecfg, &ecb);
1579
+ xdi_diff_outf(&mf1, &mf2, &diffstat->xm, &xpp, &xecfg, &ecb);
1580
}
1581
1582
free_and_return:
@@ -1628,9 +1622,7 @@ static void builtin_checkdiff(const char *name_a, const char *name_b,
1622
1623
memset(&xecfg, 0, sizeof(xecfg));
1624
xpp.flags = XDF_NEED_MINIMAL;
1631
- ecb.outf = xdiff_outf;
1632
- ecb.priv = &data;
1633
- xdi_diff(&mf1, &mf2, &xpp, &xecfg, &ecb);
1625
+ xdi_diff_outf(&mf1, &mf2, &data.xm, &xpp, &xecfg, &ecb);
1626
1627
if ((data.ws_rule & WS_TRAILING_SPACE) &&
1628
data.trailing_blanks_start) {
@@ -3128,9 +3120,7 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1)
3120
xpp.flags = XDF_NEED_MINIMAL;
3121
xecfg.ctxlen = 3;
3122
xecfg.flags = XDL_EMIT_FUNCNAMES;
3131
- ecb.outf = xdiff_outf;
3132
- ecb.priv = &data;
3133
- xdi_diff(&mf1, &mf2, &xpp, &xecfg, &ecb);
3123
+ xdi_diff_outf(&mf1, &mf2, &data.xm, &xpp, &xecfg, &ecb);
3124
}
3125
3126
SHA1_Final(sha1, &ctx);
xdiff-interface.c
+12
-1
@@ -61,7 +61,7 @@ static void consume_one(void *priv_, char *s, unsigned long size)
61
}
62
}
63
64
-int xdiff_outf(void *priv_, mmbuffer_t *mb, int nbuf)
64
+static int xdiff_outf(void *priv_, mmbuffer_t *mb, int nbuf)
65
{
66
struct xdiff_emit_state *priv = priv_;
67
int i;
@@ -141,6 +141,17 @@ int xdi_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, xdemitconf_t co
141
return xdl_diff(&a, &b, xpp, xecfg, xecb);
142
}
143
144
+int xdi_diff_outf(mmfile_t *mf1, mmfile_t *mf2,
145
+ struct xdiff_emit_state *state, xpparam_t const *xpp,
146
+ xdemitconf_t const *xecfg, xdemitcb_t *xecb)
147
+{
148
+ int ret;
149
+ xecb->outf = xdiff_outf;
150
+ xecb->priv = state;
151
+ ret = xdi_diff(mf1, mf2, xpp, xecfg, xecb);
152
+ return ret;
153
+}
154
+
155
int read_mmfile(mmfile_t *ptr, const char *filename)
156
{
157
struct stat st;
xdiff-interface.h
+3
-1
@@ -14,7 +14,9 @@ struct xdiff_emit_state {
14
};
15
16
int xdi_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, xdemitconf_t const *xecfg, xdemitcb_t *ecb);
17
-int xdiff_outf(void *priv_, mmbuffer_t *mb, int nbuf);
17
+int xdi_diff_outf(mmfile_t *mf1, mmfile_t *mf2,
18
+ struct xdiff_emit_state *state, xpparam_t const *xpp,
19
+ xdemitconf_t const *xecfg, xdemitcb_t *xecb);
20
int parse_hunk_header(char *line, int len,
21
int *ob, int *on,
22
int *nb, int *nn);