show_log: factor out interdiff/range-diff generation

The integration of "git range-diff" with "git format-patch" for a single patch (i.e., not generating "range-diff" into the cover letter) hooks into log-tree.c:show_log(), which is responsible for writing the log message out and other stuff. Essentially, everything you see before the diffstat and the patch is generated there. Split out the code that spits out the interdiff/range-diff into a separate helper function show_diff_of_diff(). Hopefully this will make it easier to move things around in the output stream in the future patches. This is supposed to be a no-op refactoring. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed May 23, 2024 at 15:50 UTC 84ed5055153ccfe5c38501e68ac58634001bbd9d
1 file changed +48 -40
log-tree.c
+48 -40
@@ -673,6 +673,53 @@ static void next_commentary_block(struct rev_info *opt, struct strbuf *sb)
673 opt->shown_dashes = 1;
674 }
675
676 +static void show_diff_of_diff(struct rev_info *opt)
677 +{
678 + if (!cmit_fmt_is_mail(opt->commit_format))
679 + return;
680 +
681 + if (opt->idiff_oid1) {
682 + struct diff_queue_struct dq;
683 +
684 + memcpy(&dq, &diff_queued_diff, sizeof(diff_queued_diff));
685 + DIFF_QUEUE_CLEAR(&diff_queued_diff);
686 +
687 + next_commentary_block(opt, NULL);
688 + fprintf_ln(opt->diffopt.file, "%s", opt->idiff_title);
689 + show_interdiff(opt->idiff_oid1, opt->idiff_oid2, 2,
690 + &opt->diffopt);
691 +
692 + memcpy(&diff_queued_diff, &dq, sizeof(diff_queued_diff));
693 + }
694 +
695 + if (opt->rdiff1) {
696 + struct diff_queue_struct dq;
697 + struct diff_options opts;
698 + struct range_diff_options range_diff_opts = {
699 + .creation_factor = opt->creation_factor,
700 + .dual_color = 1,
701 + .diffopt = &opts
702 + };
703 +
704 + memcpy(&dq, &diff_queued_diff, sizeof(diff_queued_diff));
705 + DIFF_QUEUE_CLEAR(&diff_queued_diff);
706 +
707 + next_commentary_block(opt, NULL);
708 + fprintf_ln(opt->diffopt.file, "%s", opt->rdiff_title);
709 + /*
710 + * Pass minimum required diff-options to range-diff; others
711 + * can be added later if deemed desirable.
712 + */
713 + repo_diff_setup(the_repository, &opts);
714 + opts.file = opt->diffopt.file;
715 + opts.use_color = opt->diffopt.use_color;
716 + diff_setup_done(&opts);
717 + show_range_diff(opt->rdiff1, opt->rdiff2, &range_diff_opts);
718 +
719 + memcpy(&diff_queued_diff, &dq, sizeof(diff_queued_diff));
720 + }
721 +}
722 +
723 void show_log(struct rev_info *opt)
724 {
725 struct strbuf msgbuf = STRBUF_INIT;
@@ -857,46 +904,7 @@ void show_log(struct rev_info *opt)
904 free(ctx.notes_message);
905 free(ctx.after_subject);
906
860 - if (cmit_fmt_is_mail(ctx.fmt) && opt->idiff_oid1) {
861 - struct diff_queue_struct dq;
862 -
863 - memcpy(&dq, &diff_queued_diff, sizeof(diff_queued_diff));
864 - DIFF_QUEUE_CLEAR(&diff_queued_diff);
865 -
866 - next_commentary_block(opt, NULL);
867 - fprintf_ln(opt->diffopt.file, "%s", opt->idiff_title);
868 - show_interdiff(opt->idiff_oid1, opt->idiff_oid2, 2,
869 - &opt->diffopt);
870 -
871 - memcpy(&diff_queued_diff, &dq, sizeof(diff_queued_diff));
872 - }
873 -
874 - if (cmit_fmt_is_mail(ctx.fmt) && opt->rdiff1) {
875 - struct diff_queue_struct dq;
876 - struct diff_options opts;
877 - struct range_diff_options range_diff_opts = {
878 - .creation_factor = opt->creation_factor,
879 - .dual_color = 1,
880 - .diffopt = &opts
881 - };
882 -
883 - memcpy(&dq, &diff_queued_diff, sizeof(diff_queued_diff));
884 - DIFF_QUEUE_CLEAR(&diff_queued_diff);
885 -
886 - next_commentary_block(opt, NULL);
887 - fprintf_ln(opt->diffopt.file, "%s", opt->rdiff_title);
888 - /*
889 - * Pass minimum required diff-options to range-diff; others
890 - * can be added later if deemed desirable.
891 - */
892 - repo_diff_setup(the_repository, &opts);
893 - opts.file = opt->diffopt.file;
894 - opts.use_color = opt->diffopt.use_color;
895 - diff_setup_done(&opts);
896 - show_range_diff(opt->rdiff1, opt->rdiff2, &range_diff_opts);
897 -
898 - memcpy(&diff_queued_diff, &dq, sizeof(diff_queued_diff));
899 - }
907 + show_diff_of_diff(opt);
908 }
909
910 int log_tree_diff_flush(struct rev_info *opt)