1 #include "git-compat-util.h"
2 #include "diff-merges.h"
6 typedef void (*diff_merges_setup_func_t
)(struct rev_info
*);
7 static void set_separate(struct rev_info
*revs
);
9 static diff_merges_setup_func_t set_to_default
= set_separate
;
10 static int suppress_m_parsing
;
12 static void suppress(struct rev_info
*revs
)
14 revs
->separate_merges
= 0;
15 revs
->first_parent_merges
= 0;
16 revs
->combine_merges
= 0;
17 revs
->dense_combined_merges
= 0;
18 revs
->combined_all_paths
= 0;
19 revs
->merges_imply_patch
= 0;
20 revs
->merges_need_diff
= 0;
21 revs
->remerge_diff
= 0;
24 static void common_setup(struct rev_info
*revs
)
27 revs
->merges_need_diff
= 1;
30 static void set_none(struct rev_info
*revs
)
35 static void set_separate(struct rev_info
*revs
)
38 revs
->separate_merges
= 1;
39 revs
->simplify_history
= 0;
42 static void set_first_parent(struct rev_info
*revs
)
45 revs
->first_parent_merges
= 1;
48 static void set_combined(struct rev_info
*revs
)
51 revs
->combine_merges
= 1;
52 revs
->dense_combined_merges
= 0;
55 static void set_dense_combined(struct rev_info
*revs
)
58 revs
->combine_merges
= 1;
59 revs
->dense_combined_merges
= 1;
62 static void set_remerge_diff(struct rev_info
*revs
)
65 revs
->remerge_diff
= 1;
66 revs
->simplify_history
= 0;
69 static diff_merges_setup_func_t
func_by_opt(const char *optarg
)
71 if (!strcmp(optarg
, "off") || !strcmp(optarg
, "none"))
73 if (!strcmp(optarg
, "1") || !strcmp(optarg
, "first-parent"))
74 return set_first_parent
;
75 if (!strcmp(optarg
, "separate"))
77 if (!strcmp(optarg
, "c") || !strcmp(optarg
, "combined"))
79 if (!strcmp(optarg
, "cc") || !strcmp(optarg
, "dense-combined"))
80 return set_dense_combined
;
81 if (!strcmp(optarg
, "r") || !strcmp(optarg
, "remerge"))
82 return set_remerge_diff
;
83 if (!strcmp(optarg
, "m") || !strcmp(optarg
, "on"))
84 return set_to_default
;
88 static void set_diff_merges(struct rev_info
*revs
, const char *optarg
)
90 diff_merges_setup_func_t func
= func_by_opt(optarg
);
93 die(_("invalid value for '%s': '%s'"), "--diff-merges", optarg
);
99 * Public functions. They are in the order they are called.
102 int diff_merges_config(const char *value
)
104 diff_merges_setup_func_t func
= func_by_opt(value
);
109 set_to_default
= func
;
113 void diff_merges_suppress_m_parsing(void)
115 suppress_m_parsing
= 1;
118 int diff_merges_parse_opts(struct rev_info
*revs
, const char **argv
)
122 const char *arg
= argv
[0];
124 if (!suppress_m_parsing
&& !strcmp(arg
, "-m")) {
125 set_to_default(revs
);
126 revs
->merges_need_diff
= 0;
127 } else if (!strcmp(arg
, "-c")) {
129 revs
->merges_imply_patch
= 1;
130 } else if (!strcmp(arg
, "--cc")) {
131 set_dense_combined(revs
);
132 revs
->merges_imply_patch
= 1;
133 } else if (!strcmp(arg
, "--remerge-diff")) {
134 set_remerge_diff(revs
);
135 revs
->merges_imply_patch
= 1;
136 } else if (!strcmp(arg
, "--no-diff-merges")) {
138 } else if (!strcmp(arg
, "--combined-all-paths")) {
139 revs
->combined_all_paths
= 1;
140 } else if ((argcount
= parse_long_opt("diff-merges", argv
, &optarg
))) {
141 set_diff_merges(revs
, optarg
);
145 revs
->explicit_diff_merges
= 1;
149 void diff_merges_suppress(struct rev_info
*revs
)
154 void diff_merges_default_to_first_parent(struct rev_info
*revs
)
156 if (!revs
->explicit_diff_merges
)
157 revs
->separate_merges
= 1;
158 if (revs
->separate_merges
)
159 revs
->first_parent_merges
= 1;
162 void diff_merges_default_to_dense_combined(struct rev_info
*revs
)
164 if (!revs
->explicit_diff_merges
)
165 set_dense_combined(revs
);
168 void diff_merges_set_dense_combined_if_unset(struct rev_info
*revs
)
170 if (!revs
->combine_merges
)
171 set_dense_combined(revs
);
174 void diff_merges_setup_revs(struct rev_info
*revs
)
176 if (revs
->combine_merges
== 0)
177 revs
->dense_combined_merges
= 0;
178 if (revs
->separate_merges
== 0)
179 revs
->first_parent_merges
= 0;
180 if (revs
->combined_all_paths
&& !revs
->combine_merges
)
181 die("--combined-all-paths makes no sense without -c or --cc");
182 if (revs
->merges_imply_patch
)
184 if (revs
->merges_imply_patch
|| revs
->merges_need_diff
) {
185 if (!revs
->diffopt
.output_format
)
186 revs
->diffopt
.output_format
= DIFF_FORMAT_PATCH
;