| 2328 | } |
| 2329 | |
| 2330 | static void init_diff_words_data(struct emit_callback *ecbdata, |
| 2331 | struct diff_options *orig_opts, |
| 2332 | struct diff_filespec *one, |
| 2333 | struct diff_filespec *two) |
| 2334 | { |
| 2335 | int i; |
| 2336 | struct diff_options *o = xmalloc(sizeof(struct diff_options)); |
| 2337 | memcpy(o, orig_opts, sizeof(struct diff_options)); |
| 2338 | |
| 2339 | CALLOC_ARRAY(ecbdata->diff_words, 1); |
| 2340 | ecbdata->diff_words->type = o->word_diff; |
| 2341 | ecbdata->diff_words->opt = o; |
| 2342 | |
| 2343 | if (orig_opts->emitted_symbols) |
| 2344 | CALLOC_ARRAY(o->emitted_symbols, 1); |
| 2345 | |
| 2346 | if (!o->word_regex) |
| 2347 | o->word_regex = userdiff_word_regex(one, o->repo->index); |
| 2348 | if (!o->word_regex) |
| 2349 | o->word_regex = userdiff_word_regex(two, o->repo->index); |
| 2350 | if (!o->word_regex) |
| 2351 | o->word_regex = diff_word_regex_cfg; |
| 2352 | if (o->word_regex) { |
| 2353 | ecbdata->diff_words->word_regex = (regex_t *) |
| 2354 | xmalloc(sizeof(regex_t)); |
| 2355 | if (regcomp(ecbdata->diff_words->word_regex, |
| 2356 | o->word_regex, |
| 2357 | REG_EXTENDED | REG_NEWLINE)) |
| 2358 | die("invalid regular expression: %s", |
| 2359 | o->word_regex); |
| 2360 | } |
| 2361 | for (i = 0; i < ARRAY_SIZE(diff_words_styles); i++) { |
| 2362 | if (o->word_diff == diff_words_styles[i].type) { |
| 2363 | ecbdata->diff_words->style = |
| 2364 | &diff_words_styles[i]; |
| 2365 | break; |
| 2366 | } |
| 2367 | } |
| 2368 | if (want_color(o->use_color)) { |
| 2369 | struct diff_words_style *st = ecbdata->diff_words->style; |
| 2370 | st->old_word.color = diff_get_color_opt(o, DIFF_FILE_OLD); |
| 2371 | st->new_word.color = diff_get_color_opt(o, DIFF_FILE_NEW); |
| 2372 | st->ctx.color = diff_get_color_opt(o, DIFF_CONTEXT); |
| 2373 | } |
| 2374 | } |
| 2375 | |
| 2376 | static void free_diff_words_data(struct emit_callback *ecbdata) |
| 2377 | { |
no test coverage detected