1 #include "git-compat-util.h"
2 #include "diff-merges.h"
7 typedef void (*diff_merges_setup_func_t
)(struct rev_info
*);
8 static void set_separate(struct rev_info
*revs
);
10 static diff_merges_setup_func_t set_to_default
= set_separate
;
11 static int suppress_m_parsing
;
13 static void suppress(struct rev_info
*revs
)
15 revs
->separate_merges
= 0;
16 revs
->first_parent_merges
= 0;
17 revs
->combine_merges
= 0;
18 revs
->dense_combined_merges
= 0;
19 revs
->combined_all_paths
= 0;
20 revs
->merges_imply_patch
= 0;
21 revs
->merges_need_diff
= 0;
22 revs
->remerge_diff
= 0;
25 static void common_setup(struct rev_info
*revs
)
28 revs
->merges_need_diff
= 1;
31 static void set_none(struct rev_info
*revs
)
36 static void set_separate(struct rev_info
*revs
)
39 revs
->separate_merges
= 1;
40 revs
->simplify_history
= 0;
43 static void set_first_parent(struct rev_info
*revs
)
46 revs
->first_parent_merges
= 1;
49 static void set_combined(struct rev_info
*revs
)
52 revs
->combine_merges
= 1;
53 revs
->dense_combined_merges
= 0;
56 static void set_dense_combined(struct rev_info
*revs
)
59 revs
->combine_merges
= 1;
60 revs
->dense_combined_merges
= 1;
63 static void set_remerge_diff(struct rev_info
*revs
)
66 revs
->remerge_diff
= 1;
67 revs
->simplify_history
= 0;
70 static diff_merges_setup_func_t
func_by_opt(const char *optarg
)
72 if (!strcmp(optarg
, "off") || !strcmp(optarg
, "none"))
74 if (!strcmp(optarg
, "1") || !strcmp(optarg
, "first-parent"))
75 return set_first_parent
;
76 if (!strcmp(optarg
, "separate"))
78 if (!strcmp(optarg
, "c") || !strcmp(optarg
, "combined"))
80 if (!strcmp(optarg
, "cc") || !strcmp(optarg
, "dense-combined"))
81 return set_dense_combined
;
82 if (!strcmp(optarg
, "r") || !strcmp(optarg
, "remerge"))
83 return set_remerge_diff
;
84 if (!strcmp(optarg
, "m") || !strcmp(optarg
, "on"))
85 return set_to_default
;
89 static void set_diff_merges(struct rev_info
*revs
, const char *optarg
)
91 diff_merges_setup_func_t func
= func_by_opt(optarg
);
94 die(_("invalid value for '%s': '%s'"), "--diff-merges", optarg
);
100 * Public functions. They are in the order they are called.
103 int diff_merges_config(const char *value
)
105 diff_merges_setup_func_t func
= func_by_opt(value
);
110 set_to_default
= func
;
114 void diff_merges_suppress_m_parsing(void)
116 suppress_m_parsing
= 1;
119 int diff_merges_parse_opts(struct rev_info
*revs
, const char **argv
)
123 const char *arg
= argv
[0];
125 if (!suppress_m_parsing
&& !strcmp(arg
, "-m")) {
126 set_to_default(revs
);
127 revs
->merges_need_diff
= 0;
128 } else if (!strcmp(arg
, "-c")) {
130 revs
->merges_imply_patch
= 1;
131 } else if (!strcmp(arg
, "--cc")) {
132 set_dense_combined(revs
);
133 revs
->merges_imply_patch
= 1;
134 } else if (!strcmp(arg
, "--dd")) {
135 set_first_parent(revs
);
136 revs
->merges_imply_patch
= 1;
137 } else if (!strcmp(arg
, "--remerge-diff")) {
138 set_remerge_diff(revs
);
139 revs
->merges_imply_patch
= 1;
140 } else if (!strcmp(arg
, "--no-diff-merges")) {
142 } else if (!strcmp(arg
, "--combined-all-paths")) {
143 revs
->combined_all_paths
= 1;
144 } else if ((argcount
= parse_long_opt("diff-merges", argv
, &optarg
))) {
145 set_diff_merges(revs
, optarg
);
149 revs
->explicit_diff_merges
= 1;
153 void diff_merges_suppress(struct rev_info
*revs
)
158 void diff_merges_default_to_first_parent(struct rev_info
*revs
)
160 if (!revs
->explicit_diff_merges
)
161 revs
->separate_merges
= 1;
162 if (revs
->separate_merges
)
163 revs
->first_parent_merges
= 1;
166 void diff_merges_default_to_dense_combined(struct rev_info
*revs
)
168 if (!revs
->explicit_diff_merges
)
169 set_dense_combined(revs
);
172 void diff_merges_set_dense_combined_if_unset(struct rev_info
*revs
)
174 if (!revs
->combine_merges
)
175 set_dense_combined(revs
);
178 void diff_merges_setup_revs(struct rev_info
*revs
)
180 if (revs
->combine_merges
== 0)
181 revs
->dense_combined_merges
= 0;
182 if (revs
->separate_merges
== 0)
183 revs
->first_parent_merges
= 0;
184 if (revs
->combined_all_paths
&& !revs
->combine_merges
)
185 die("--combined-all-paths makes no sense without -c or --cc");
186 if (revs
->merges_imply_patch
)
188 if (revs
->merges_imply_patch
|| revs
->merges_need_diff
) {
189 if (!revs
->diffopt
.output_format
)
190 revs
->diffopt
.output_format
= DIFF_FORMAT_PATCH
;