1 #include "diff-merges.h"
5 typedef void (*diff_merges_setup_func_t
)(struct rev_info
*);
6 static void set_separate(struct rev_info
*revs
);
8 static diff_merges_setup_func_t set_to_default
= set_separate
;
10 static void suppress(struct rev_info
*revs
)
12 revs
->separate_merges
= 0;
13 revs
->first_parent_merges
= 0;
14 revs
->combine_merges
= 0;
15 revs
->dense_combined_merges
= 0;
16 revs
->combined_all_paths
= 0;
17 revs
->combined_imply_patch
= 0;
18 revs
->merges_need_diff
= 0;
21 static void set_separate(struct rev_info
*revs
)
24 revs
->separate_merges
= 1;
27 static void set_first_parent(struct rev_info
*revs
)
30 revs
->first_parent_merges
= 1;
33 static void set_m(struct rev_info
*revs
)
36 * To "diff-index", "-m" means "match missing", and to the "log"
37 * family of commands, it means "show default diff for merges". Set
38 * both fields appropriately.
41 revs
->match_missing
= 1;
44 static void set_combined(struct rev_info
*revs
)
47 revs
->combine_merges
= 1;
48 revs
->dense_combined_merges
= 0;
51 static void set_dense_combined(struct rev_info
*revs
)
54 revs
->combine_merges
= 1;
55 revs
->dense_combined_merges
= 1;
58 static diff_merges_setup_func_t
func_by_opt(const char *optarg
)
60 if (!strcmp(optarg
, "off") || !strcmp(optarg
, "none"))
62 if (!strcmp(optarg
, "1") || !strcmp(optarg
, "first-parent"))
63 return set_first_parent
;
64 else if (!strcmp(optarg
, "separate"))
66 else if (!strcmp(optarg
, "c") || !strcmp(optarg
, "combined"))
68 else if (!strcmp(optarg
, "cc") || !strcmp(optarg
, "dense-combined"))
69 return set_dense_combined
;
70 else if (!strcmp(optarg
, "m") || !strcmp(optarg
, "on"))
71 return set_to_default
;
75 static void set_diff_merges(struct rev_info
*revs
, const char *optarg
)
77 diff_merges_setup_func_t func
= func_by_opt(optarg
);
80 die(_("unknown value for --diff-merges: %s"), optarg
);
84 /* NOTE: the merges_need_diff flag is cleared by func() call */
86 revs
->merges_need_diff
= 1;
90 * Public functions. They are in the order they are called.
93 int diff_merges_config(const char *value
)
95 diff_merges_setup_func_t func
= func_by_opt(value
);
100 set_to_default
= func
;
104 int diff_merges_parse_opts(struct rev_info
*revs
, const char **argv
)
108 const char *arg
= argv
[0];
110 if (!strcmp(arg
, "-m")) {
112 } else if (!strcmp(arg
, "-c")) {
114 revs
->combined_imply_patch
= 1;
115 } else if (!strcmp(arg
, "--cc")) {
116 set_dense_combined(revs
);
117 revs
->combined_imply_patch
= 1;
118 } else if (!strcmp(arg
, "--no-diff-merges")) {
120 } else if (!strcmp(arg
, "--combined-all-paths")) {
121 revs
->combined_all_paths
= 1;
122 } else if ((argcount
= parse_long_opt("diff-merges", argv
, &optarg
))) {
123 set_diff_merges(revs
, optarg
);
127 revs
->explicit_diff_merges
= 1;
131 void diff_merges_suppress(struct rev_info
*revs
)
136 void diff_merges_default_to_first_parent(struct rev_info
*revs
)
138 if (!revs
->explicit_diff_merges
)
139 revs
->separate_merges
= 1;
140 if (revs
->separate_merges
)
141 revs
->first_parent_merges
= 1;
144 void diff_merges_default_to_dense_combined(struct rev_info
*revs
)
146 if (!revs
->explicit_diff_merges
)
147 set_dense_combined(revs
);
150 void diff_merges_set_dense_combined_if_unset(struct rev_info
*revs
)
152 if (!revs
->combine_merges
)
153 set_dense_combined(revs
);
156 void diff_merges_setup_revs(struct rev_info
*revs
)
158 if (revs
->combine_merges
== 0)
159 revs
->dense_combined_merges
= 0;
160 if (revs
->separate_merges
== 0)
161 revs
->first_parent_merges
= 0;
162 if (revs
->combined_all_paths
&& !revs
->combine_merges
)
163 die("--combined-all-paths makes no sense without -c or --cc");
164 if (revs
->combined_imply_patch
)
166 if (revs
->combined_imply_patch
|| revs
->merges_need_diff
) {
167 if (!revs
->diffopt
.output_format
)
168 revs
->diffopt
.output_format
= DIFF_FORMAT_PATCH
;