revision: provide implementation for diff merges tweaks

Use these implementations from show_setup_revisions_tweak() and log_setup_revisions_tweak() in builtin/log.c. This completes moving of management of diff merges parameters to a single place, where we can finally observe them simultaneously. Signed-off-by: Sergey Organov <sorganov@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Sergey Organov committed Dec 21, 2020 at 18:19 UTC 3d4fd9436337d1688e7e2c2b2da4f7b7e3e8591e
3 files changed +24 -11
builtin/log.c
+2 -11
@@ -598,15 +598,7 @@ static int show_tree_object(const struct object_id *oid,
598 static void show_setup_revisions_tweak(struct rev_info *rev,
599 struct setup_revision_opt *opt)
600 {
601 - if (rev->ignore_merges < 0) {
602 - /* There was no "-m" variant on the command line */
603 - rev->ignore_merges = 0;
604 - if (!rev->first_parent_only && !rev->combine_merges) {
605 - /* No "--first-parent", "-c", or "--cc" */
606 - rev->combine_merges = 1;
607 - rev->dense_combined_merges = 1;
608 - }
609 - }
601 + rev_diff_merges_default_to_dense_combined(rev);
602 if (!rev->diffopt.output_format)
603 rev->diffopt.output_format = DIFF_FORMAT_PATCH;
604 }
@@ -731,8 +723,7 @@ static void log_setup_revisions_tweak(struct rev_info *rev,
723 if (!rev->diffopt.output_format && rev->combine_merges)
724 rev->diffopt.output_format = DIFF_FORMAT_PATCH;
725
734 - if (rev->first_parent_only && rev->ignore_merges < 0)
735 - rev->ignore_merges = 0;
726 + rev_diff_merges_first_parent_defaults_to_enable(rev);
727 }
728
729 int cmd_log(int argc, const char **argv, const char *prefix)
revision.c
+19
@@ -2209,6 +2209,25 @@ static void setup_diff_merges_revs(struct rev_info *revs)
2209 die("--combined-all-paths makes no sense without -c or --cc");
2210 }
2211
2212 +void rev_diff_merges_first_parent_defaults_to_enable(struct rev_info *revs)
2213 +{
2214 + if (revs->first_parent_only && revs->ignore_merges < 0)
2215 + revs->ignore_merges = 0;
2216 +}
2217 +
2218 +void rev_diff_merges_default_to_dense_combined(struct rev_info *revs)
2219 +{
2220 + if (revs->ignore_merges < 0) {
2221 + /* There was no "-m" variant on the command line */
2222 + revs->ignore_merges = 0;
2223 + if (!revs->first_parent_only && !revs->combine_merges) {
2224 + /* No "--first-parent", "-c", or "--cc" */
2225 + revs->combine_merges = 1;
2226 + revs->dense_combined_merges = 1;
2227 + }
2228 + }
2229 +}
2230 +
2231 static int handle_revision_opt(struct rev_info *revs, int argc, const char **argv,
2232 int *unkc, const char **unkv,
2233 const struct setup_revision_opt* opt)
revision.h
+3
@@ -456,4 +456,7 @@ int rewrite_parents(struct rev_info *revs,
456 */
457 struct commit_list *get_saved_parents(struct rev_info *revs, const struct commit *commit);
458
459 +void rev_diff_merges_default_to_dense_combined(struct rev_info *revs);
460 +void rev_diff_merges_first_parent_defaults_to_enable(struct rev_info *revs);
461 +
462 #endif