| 536 | } |
| 537 | |
| 538 | static int parse_diff(struct add_p_state *s, const struct pathspec *ps) |
| 539 | { |
| 540 | struct strvec args = STRVEC_INIT; |
| 541 | struct strbuf *plain = &s->plain, *colored = NULL; |
| 542 | struct child_process cp = CHILD_PROCESS_INIT; |
| 543 | char *p, *pend, *colored_p = NULL, *colored_pend = NULL, marker = '\0'; |
| 544 | size_t file_diff_alloc = 0, i, color_arg_index; |
| 545 | struct file_diff *file_diff = NULL; |
| 546 | struct hunk *hunk = NULL; |
| 547 | int res; |
| 548 | |
| 549 | strvec_pushv(&args, s->mode->diff_cmd); |
| 550 | if (s->cfg.context != -1) |
| 551 | strvec_pushf(&args, "--unified=%i", s->cfg.context); |
| 552 | if (s->cfg.interhunkcontext != -1) |
| 553 | strvec_pushf(&args, "--inter-hunk-context=%i", s->cfg.interhunkcontext); |
| 554 | if (s->cfg.interactive_diff_algorithm) |
| 555 | strvec_pushf(&args, "--diff-algorithm=%s", s->cfg.interactive_diff_algorithm); |
| 556 | if (s->revision) { |
| 557 | struct object_id oid; |
| 558 | strvec_push(&args, |
| 559 | /* could be on an unborn branch */ |
| 560 | !strcmp("HEAD", s->revision) && |
| 561 | repo_get_oid(s->r, "HEAD", &oid) ? |
| 562 | empty_tree_oid_hex(s->r->hash_algo) : s->revision); |
| 563 | } |
| 564 | color_arg_index = args.nr; |
| 565 | /* Use `--no-color` explicitly, just in case `diff.color = always`. */ |
| 566 | strvec_pushl(&args, "--no-color", "--ignore-submodules=dirty", "-p", |
| 567 | "--", NULL); |
| 568 | for (i = 0; i < ps->nr; i++) |
| 569 | strvec_push(&args, ps->items[i].original); |
| 570 | |
| 571 | setup_child_process(s, &cp, NULL); |
| 572 | strvec_pushv(&cp.args, args.v); |
| 573 | res = capture_command(&cp, plain, 0); |
| 574 | if (res) { |
| 575 | strvec_clear(&args); |
| 576 | return error(_("could not parse diff")); |
| 577 | } |
| 578 | if (!plain->len) { |
| 579 | strvec_clear(&args); |
| 580 | return 0; |
| 581 | } |
| 582 | strbuf_complete_line(plain); |
| 583 | |
| 584 | if (want_color_fd(1, s->cfg.use_color_diff)) { |
| 585 | struct child_process colored_cp = CHILD_PROCESS_INIT; |
| 586 | const char *diff_filter = s->cfg.interactive_diff_filter; |
| 587 | |
| 588 | setup_child_process(s, &colored_cp, NULL); |
| 589 | xsnprintf((char *)args.v[color_arg_index], 8, "--color"); |
| 590 | strvec_pushv(&colored_cp.args, args.v); |
| 591 | colored = &s->colored; |
| 592 | res = capture_command(&colored_cp, colored, 0); |
| 593 | strvec_clear(&args); |
| 594 | if (res) |
| 595 | return error(_("could not parse colored diff")); |
no test coverage detected