| 504 | } |
| 505 | |
| 506 | static void output(struct string_list *a, struct string_list *b, |
| 507 | struct range_diff_options *range_diff_opts) |
| 508 | { |
| 509 | struct strbuf buf = STRBUF_INIT, dashes = STRBUF_INIT; |
| 510 | int patch_no_width = decimal_width(1 + (a->nr > b->nr ? a->nr : b->nr)); |
| 511 | int i = 0, j = 0; |
| 512 | struct diff_options opts; |
| 513 | struct strbuf indent = STRBUF_INIT; |
| 514 | |
| 515 | if (range_diff_opts->diffopt) |
| 516 | memcpy(&opts, range_diff_opts->diffopt, sizeof(opts)); |
| 517 | else |
| 518 | repo_diff_setup(the_repository, &opts); |
| 519 | |
| 520 | opts.no_free = 1; |
| 521 | if (!opts.output_format) |
| 522 | opts.output_format = DIFF_FORMAT_PATCH; |
| 523 | opts.flags.suppress_diff_headers = 1; |
| 524 | opts.flags.dual_color_diffed_diffs = |
| 525 | range_diff_opts->dual_color; |
| 526 | opts.flags.suppress_hunk_header_line_count = 1; |
| 527 | opts.output_prefix = output_prefix_cb; |
| 528 | strbuf_addstr(&indent, " "); |
| 529 | opts.output_prefix_data = indent.buf; |
| 530 | diff_setup_done(&opts); |
| 531 | |
| 532 | /* |
| 533 | * We assume the user is really more interested in the second argument |
| 534 | * ("newer" version). To that end, we print the output in the order of |
| 535 | * the RHS (the `b` parameter). To put the LHS (the `a` parameter) |
| 536 | * commits that are no longer in the RHS into a good place, we place |
| 537 | * them once we have shown all of their predecessors in the LHS. |
| 538 | */ |
| 539 | |
| 540 | while (i < a->nr || j < b->nr) { |
| 541 | struct patch_util *a_util, *b_util; |
| 542 | a_util = i < a->nr ? a->items[i].util : NULL; |
| 543 | b_util = j < b->nr ? b->items[j].util : NULL; |
| 544 | |
| 545 | /* Skip all the already-shown commits from the LHS. */ |
| 546 | while (i < a->nr && a_util->shown) |
| 547 | a_util = ++i < a->nr ? a->items[i].util : NULL; |
| 548 | |
| 549 | /* Show unmatched LHS commit whose predecessors were shown. */ |
| 550 | if (i < a->nr && a_util->matching < 0) { |
| 551 | if (!range_diff_opts->right_only) |
| 552 | output_pair_header(&opts, patch_no_width, |
| 553 | &buf, &dashes, a_util, NULL); |
| 554 | i++; |
| 555 | continue; |
| 556 | } |
| 557 | |
| 558 | /* Show unmatched RHS commits. */ |
| 559 | while (j < b->nr && b_util->matching < 0) { |
| 560 | if (!range_diff_opts->left_only) |
| 561 | output_pair_header(&opts, patch_no_width, |
| 562 | &buf, &dashes, NULL, b_util); |
| 563 | b_util = ++j < b->nr ? b->items[j].util : NULL; |
no test coverage detected