this executes the word diff on the accumulated buffers */
| 2225 | |
| 2226 | /* this executes the word diff on the accumulated buffers */ |
| 2227 | static void diff_words_show(struct diff_words_data *diff_words) |
| 2228 | { |
| 2229 | xpparam_t xpp; |
| 2230 | xdemitconf_t xecfg; |
| 2231 | mmfile_t minus, plus; |
| 2232 | struct diff_words_style *style = diff_words->style; |
| 2233 | |
| 2234 | struct diff_options *opt = diff_words->opt; |
| 2235 | const char *line_prefix; |
| 2236 | |
| 2237 | assert(opt); |
| 2238 | line_prefix = diff_line_prefix(opt); |
| 2239 | |
| 2240 | /* special case: only removal */ |
| 2241 | if (!diff_words->plus.text.size) { |
| 2242 | emit_diff_symbol(diff_words->opt, DIFF_SYMBOL_WORD_DIFF, |
| 2243 | line_prefix, strlen(line_prefix), 0); |
| 2244 | fn_out_diff_words_write_helper(diff_words->opt, |
| 2245 | &style->old_word, style->newline, |
| 2246 | diff_words->minus.text.size, |
| 2247 | diff_words->minus.text.ptr); |
| 2248 | diff_words->minus.text.size = 0; |
| 2249 | return; |
| 2250 | } |
| 2251 | |
| 2252 | diff_words->current_plus = diff_words->plus.text.ptr; |
| 2253 | diff_words->last_minus = 0; |
| 2254 | |
| 2255 | memset(&xpp, 0, sizeof(xpp)); |
| 2256 | memset(&xecfg, 0, sizeof(xecfg)); |
| 2257 | diff_words_fill(&diff_words->minus, &minus, diff_words->word_regex); |
| 2258 | diff_words_fill(&diff_words->plus, &plus, diff_words->word_regex); |
| 2259 | xpp.flags = 0; |
| 2260 | /* as only the hunk header will be parsed, we need a 0-context */ |
| 2261 | xecfg.ctxlen = 0; |
| 2262 | if (xdi_diff_outf(&minus, &plus, fn_out_diff_words_aux, NULL, |
| 2263 | diff_words, &xpp, &xecfg)) |
| 2264 | die("unable to generate word diff"); |
| 2265 | free(minus.ptr); |
| 2266 | free(plus.ptr); |
| 2267 | if (diff_words->current_plus != diff_words->plus.text.ptr + |
| 2268 | diff_words->plus.text.size) { |
| 2269 | if (color_words_output_graph_prefix(diff_words)) |
| 2270 | emit_diff_symbol(diff_words->opt, DIFF_SYMBOL_WORD_DIFF, |
| 2271 | line_prefix, strlen(line_prefix), 0); |
| 2272 | fn_out_diff_words_write_helper(diff_words->opt, |
| 2273 | &style->ctx, style->newline, |
| 2274 | diff_words->plus.text.ptr + diff_words->plus.text.size |
| 2275 | - diff_words->current_plus, diff_words->current_plus); |
| 2276 | } |
| 2277 | diff_words->minus.text.size = diff_words->plus.text.size = 0; |
| 2278 | } |
| 2279 | |
| 2280 | /* In "color-words" mode, show word-diff of words accumulated in the buffer */ |
| 2281 | static void diff_words_flush(struct emit_callback *ecbdata) |
no test coverage detected