1 #include "diff-merges.h"
5 static void suppress(struct rev_info
*revs
)
7 revs
->separate_merges
= 0;
8 revs
->first_parent_merges
= 0;
9 revs
->combine_merges
= 0;
10 revs
->dense_combined_merges
= 0;
11 revs
->combined_all_paths
= 0;
12 revs
->combined_imply_patch
= 0;
13 revs
->merges_need_diff
= 0;
16 static void set_separate(struct rev_info
*revs
)
19 revs
->separate_merges
= 1;
22 static void set_first_parent(struct rev_info
*revs
)
25 revs
->first_parent_merges
= 1;
28 static void set_m(struct rev_info
*revs
)
31 * To "diff-index", "-m" means "match missing", and to the "log"
32 * family of commands, it means "show full diff for merges". Set
33 * both fields appropriately.
36 revs
->match_missing
= 1;
39 static void set_combined(struct rev_info
*revs
)
42 revs
->combine_merges
= 1;
43 revs
->dense_combined_merges
= 0;
46 static void set_dense_combined(struct rev_info
*revs
)
49 revs
->combine_merges
= 1;
50 revs
->dense_combined_merges
= 1;
53 static void set_diff_merges(struct rev_info
*revs
, const char *optarg
)
55 if (!strcmp(optarg
, "off") || !strcmp(optarg
, "none")) {
57 /* Return early to leave revs->merges_need_diff unset */
61 if (!strcmp(optarg
, "1") || !strcmp(optarg
, "first-parent"))
62 set_first_parent(revs
);
63 else if (!strcmp(optarg
, "m") || !strcmp(optarg
, "separate"))
65 else if (!strcmp(optarg
, "c") || !strcmp(optarg
, "combined"))
67 else if (!strcmp(optarg
, "cc") || !strcmp(optarg
, "dense-combined"))
68 set_dense_combined(revs
);
70 die(_("unknown value for --diff-merges: %s"), optarg
);
72 /* The flag is cleared by set_xxx() functions, so don't move this up */
73 revs
->merges_need_diff
= 1;
77 * Public functions. They are in the order they are called.
80 int diff_merges_parse_opts(struct rev_info
*revs
, const char **argv
)
84 const char *arg
= argv
[0];
86 if (!strcmp(arg
, "-m")) {
88 } else if (!strcmp(arg
, "-c")) {
90 revs
->combined_imply_patch
= 1;
91 } else if (!strcmp(arg
, "--cc")) {
92 set_dense_combined(revs
);
93 revs
->combined_imply_patch
= 1;
94 } else if (!strcmp(arg
, "--no-diff-merges")) {
96 } else if (!strcmp(arg
, "--combined-all-paths")) {
97 revs
->combined_all_paths
= 1;
98 } else if ((argcount
= parse_long_opt("diff-merges", argv
, &optarg
))) {
99 set_diff_merges(revs
, optarg
);
103 revs
->explicit_diff_merges
= 1;
107 void diff_merges_suppress(struct rev_info
*revs
)
112 void diff_merges_default_to_first_parent(struct rev_info
*revs
)
114 if (!revs
->explicit_diff_merges
)
115 revs
->separate_merges
= 1;
116 if (revs
->separate_merges
)
117 revs
->first_parent_merges
= 1;
120 void diff_merges_default_to_dense_combined(struct rev_info
*revs
)
122 if (!revs
->explicit_diff_merges
)
123 set_dense_combined(revs
);
126 void diff_merges_set_dense_combined_if_unset(struct rev_info
*revs
)
128 if (!revs
->combine_merges
)
129 set_dense_combined(revs
);
132 void diff_merges_setup_revs(struct rev_info
*revs
)
134 if (revs
->combine_merges
== 0)
135 revs
->dense_combined_merges
= 0;
136 if (revs
->separate_merges
== 0)
137 revs
->first_parent_merges
= 0;
138 if (revs
->combined_all_paths
&& !revs
->combine_merges
)
139 die("--combined-all-paths makes no sense without -c or --cc");
140 if (revs
->combined_imply_patch
)
142 if (revs
->combined_imply_patch
|| revs
->merges_need_diff
) {
143 if (!revs
->diffopt
.output_format
)
144 revs
->diffopt
.output_format
= DIFF_FORMAT_PATCH
;