@matheusbsbs / matheus-bagliano / commits / dfea79004c
Fork 0

remove ecb parameter from xdi_diff_outf()

xdi_diff_outf() overrides the structure members of its last parameter, ignoring any value that callers pass in. It's no surprise then that all callers pass a pointer to an uninitialized structure. They also don't read it after the call, so the parameter is neither used for input nor for output. Turn it into a local variable of xdi_diff_outf(). Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Acked-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed May 4, 2010 at 22:41 UTC dfea79004c54bc96143386d6ac22de500ba4f747
4 files changed +13 -19
combine-diff.c
+1 -2
@@ -211,7 +211,6 @@ static void combine_diff(const unsigned char *parent, unsigned int mode,
211 xpparam_t xpp;
212 xdemitconf_t xecfg;
213 mmfile_t parent_file;
214 - xdemitcb_t ecb;
214 struct combine_diff_state state;
215 unsigned long sz;
216
@@ -231,7 +230,7 @@ static void combine_diff(const unsigned char *parent, unsigned int mode,
230 state.n = n;
231
232 xdi_diff_outf(&parent_file, result_file, consume_line, &state,
234 - &xpp, &xecfg, &ecb);
233 + &xpp, &xecfg);
234 free(parent_file.ptr);
235
236 /* Assign line numbers for this parent.
diff.c
+5 -10
@@ -696,7 +696,6 @@ static void diff_words_show(struct diff_words_data *diff_words)
696 {
697 xpparam_t xpp;
698 xdemitconf_t xecfg;
699 - xdemitcb_t ecb;
699 mmfile_t minus, plus;
700
701 /* special case: only removal */
@@ -718,7 +717,7 @@ static void diff_words_show(struct diff_words_data *diff_words)
717 /* as only the hunk header will be parsed, we need a 0-context */
718 xecfg.ctxlen = 0;
719 xdi_diff_outf(&minus, &plus, fn_out_diff_words_aux, diff_words,
721 - &xpp, &xecfg, &ecb);
720 + &xpp, &xecfg);
721 free(minus.ptr);
722 free(plus.ptr);
723 if (diff_words->current_plus != diff_words->plus.text.ptr +
@@ -1704,7 +1703,6 @@ static void builtin_diff(const char *name_a,
1703 const char *diffopts = getenv("GIT_DIFF_OPTS");
1704 xpparam_t xpp;
1705 xdemitconf_t xecfg;
1707 - xdemitcb_t ecb;
1706 struct emit_callback ecbdata;
1707 const struct userdiff_funcname *pe;
1708
@@ -1776,7 +1774,7 @@ static void builtin_diff(const char *name_a,
1774 }
1775 }
1776 xdi_diff_outf(&mf1, &mf2, fn_out_consume, &ecbdata,
1779 - &xpp, &xecfg, &ecb);
1777 + &xpp, &xecfg);
1778 if (DIFF_OPT_TST(o, COLOR_DIFF_WORDS))
1779 free_diff_words_data(&ecbdata);
1780 if (textconv_one)
@@ -1829,13 +1827,12 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
1827 /* Crazy xdl interfaces.. */
1828 xpparam_t xpp;
1829 xdemitconf_t xecfg;
1832 - xdemitcb_t ecb;
1830
1831 memset(&xpp, 0, sizeof(xpp));
1832 memset(&xecfg, 0, sizeof(xecfg));
1833 xpp.flags = XDF_NEED_MINIMAL | o->xdl_opts;
1834 xdi_diff_outf(&mf1, &mf2, diffstat_consume, diffstat,
1838 - &xpp, &xecfg, &ecb);
1835 + &xpp, &xecfg);
1836 }
1837
1838 free_and_return:
@@ -1877,14 +1874,13 @@ static void builtin_checkdiff(const char *name_a, const char *name_b,
1874 /* Crazy xdl interfaces.. */
1875 xpparam_t xpp;
1876 xdemitconf_t xecfg;
1880 - xdemitcb_t ecb;
1877
1878 memset(&xpp, 0, sizeof(xpp));
1879 memset(&xecfg, 0, sizeof(xecfg));
1880 xecfg.ctxlen = 1; /* at least one context line */
1881 xpp.flags = XDF_NEED_MINIMAL;
1882 xdi_diff_outf(&mf1, &mf2, checkdiff_consume, &data,
1887 - &xpp, &xecfg, &ecb);
1883 + &xpp, &xecfg);
1884
1885 if (data.ws_rule & WS_BLANK_AT_EOF) {
1886 struct emit_callback ecbdata;
@@ -3361,7 +3357,6 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1)
3357 for (i = 0; i < q->nr; i++) {
3358 xpparam_t xpp;
3359 xdemitconf_t xecfg;
3364 - xdemitcb_t ecb;
3360 mmfile_t mf1, mf2;
3361 struct diff_filepair *p = q->queue[i];
3362 int len1, len2;
@@ -3423,7 +3418,7 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1)
3418 xecfg.ctxlen = 3;
3419 xecfg.flags = XDL_EMIT_FUNCNAMES;
3420 xdi_diff_outf(&mf1, &mf2, patch_id_consume, &data,
3426 - &xpp, &xecfg, &ecb);
3421 + &xpp, &xecfg);
3422 }
3423
3424 git_SHA1_Final(sha1, &ctx);
xdiff-interface.c
+6 -5
@@ -138,19 +138,20 @@ int xdi_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, xdemitconf_t co
138
139 int xdi_diff_outf(mmfile_t *mf1, mmfile_t *mf2,
140 xdiff_emit_consume_fn fn, void *consume_callback_data,
141 - xpparam_t const *xpp,
142 - xdemitconf_t const *xecfg, xdemitcb_t *xecb)
141 + xpparam_t const *xpp, xdemitconf_t const *xecfg)
142 {
143 int ret;
144 struct xdiff_emit_state state;
145 + xdemitcb_t ecb;
146
147 memset(&state, 0, sizeof(state));
148 state.consume = fn;
149 state.consume_callback_data = consume_callback_data;
150 - xecb->outf = xdiff_outf;
151 - xecb->priv = &state;
150 + memset(&ecb, 0, sizeof(ecb));
151 + ecb.outf = xdiff_outf;
152 + ecb.priv = &state;
153 strbuf_init(&state.remainder, 0);
153 - ret = xdi_diff(mf1, mf2, xpp, xecfg, xecb);
154 + ret = xdi_diff(mf1, mf2, xpp, xecfg, &ecb);
155 strbuf_release(&state.remainder);
156 return ret;
157 }
xdiff-interface.h
+1 -2
@@ -9,8 +9,7 @@ typedef void (*xdiff_emit_hunk_consume_fn)(void *, long, long, long);
9 int xdi_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, xdemitconf_t const *xecfg, xdemitcb_t *ecb);
10 int xdi_diff_outf(mmfile_t *mf1, mmfile_t *mf2,
11 xdiff_emit_consume_fn fn, void *consume_callback_data,
12 - xpparam_t const *xpp,
13 - xdemitconf_t const *xecfg, xdemitcb_t *xecb);
12 + xpparam_t const *xpp, xdemitconf_t const *xecfg);
13 int xdi_diff_hunks(mmfile_t *mf1, mmfile_t *mf2,
14 xdiff_emit_hunk_consume_fn fn, void *consume_callback_data,
15 xpparam_t const *xpp, xdemitconf_t *xecfg);