ci: remove the pipe after "p4 -V" to catch errors
[alt-git.git] / diff-merges.c
blob85cbefa5afd7c00e903232011ef3d2ff7aca4a8f
1 #include "diff-merges.h"
3 #include "revision.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;
9 static int suppress_m_parsing;
11 static void suppress(struct rev_info *revs)
13 revs->separate_merges = 0;
14 revs->first_parent_merges = 0;
15 revs->combine_merges = 0;
16 revs->dense_combined_merges = 0;
17 revs->combined_all_paths = 0;
18 revs->merges_imply_patch = 0;
19 revs->merges_need_diff = 0;
20 revs->remerge_diff = 0;
23 static void common_setup(struct rev_info *revs)
25 suppress(revs);
26 revs->merges_need_diff = 1;
29 static void set_none(struct rev_info *revs)
31 suppress(revs);
34 static void set_separate(struct rev_info *revs)
36 common_setup(revs);
37 revs->separate_merges = 1;
38 revs->simplify_history = 0;
41 static void set_first_parent(struct rev_info *revs)
43 set_separate(revs);
44 revs->first_parent_merges = 1;
47 static void set_combined(struct rev_info *revs)
49 common_setup(revs);
50 revs->combine_merges = 1;
51 revs->dense_combined_merges = 0;
54 static void set_dense_combined(struct rev_info *revs)
56 common_setup(revs);
57 revs->combine_merges = 1;
58 revs->dense_combined_merges = 1;
61 static void set_remerge_diff(struct rev_info *revs)
63 common_setup(revs);
64 revs->remerge_diff = 1;
65 revs->simplify_history = 0;
68 static diff_merges_setup_func_t func_by_opt(const char *optarg)
70 if (!strcmp(optarg, "off") || !strcmp(optarg, "none"))
71 return set_none;
72 if (!strcmp(optarg, "1") || !strcmp(optarg, "first-parent"))
73 return set_first_parent;
74 if (!strcmp(optarg, "separate"))
75 return set_separate;
76 if (!strcmp(optarg, "c") || !strcmp(optarg, "combined"))
77 return set_combined;
78 if (!strcmp(optarg, "cc") || !strcmp(optarg, "dense-combined"))
79 return set_dense_combined;
80 if (!strcmp(optarg, "r") || !strcmp(optarg, "remerge"))
81 return set_remerge_diff;
82 if (!strcmp(optarg, "m") || !strcmp(optarg, "on"))
83 return set_to_default;
84 return NULL;
87 static void set_diff_merges(struct rev_info *revs, const char *optarg)
89 diff_merges_setup_func_t func = func_by_opt(optarg);
91 if (!func)
92 die(_("invalid value for '%s': '%s'"), "--diff-merges", optarg);
94 func(revs);
98 * Public functions. They are in the order they are called.
101 int diff_merges_config(const char *value)
103 diff_merges_setup_func_t func = func_by_opt(value);
105 if (!func)
106 return -1;
108 set_to_default = func;
109 return 0;
112 void diff_merges_suppress_m_parsing(void)
114 suppress_m_parsing = 1;
117 int diff_merges_parse_opts(struct rev_info *revs, const char **argv)
119 int argcount = 1;
120 const char *optarg;
121 const char *arg = argv[0];
123 if (!suppress_m_parsing && !strcmp(arg, "-m")) {
124 set_to_default(revs);
125 revs->merges_need_diff = 0;
126 } else if (!strcmp(arg, "-c")) {
127 set_combined(revs);
128 revs->merges_imply_patch = 1;
129 } else if (!strcmp(arg, "--cc")) {
130 set_dense_combined(revs);
131 revs->merges_imply_patch = 1;
132 } else if (!strcmp(arg, "--remerge-diff")) {
133 set_remerge_diff(revs);
134 revs->merges_imply_patch = 1;
135 } else if (!strcmp(arg, "--no-diff-merges")) {
136 set_none(revs);
137 } else if (!strcmp(arg, "--combined-all-paths")) {
138 revs->combined_all_paths = 1;
139 } else if ((argcount = parse_long_opt("diff-merges", argv, &optarg))) {
140 set_diff_merges(revs, optarg);
141 } else
142 return 0;
144 revs->explicit_diff_merges = 1;
145 return argcount;
148 void diff_merges_suppress(struct rev_info *revs)
150 set_none(revs);
153 void diff_merges_default_to_first_parent(struct rev_info *revs)
155 if (!revs->explicit_diff_merges)
156 revs->separate_merges = 1;
157 if (revs->separate_merges)
158 revs->first_parent_merges = 1;
161 void diff_merges_default_to_dense_combined(struct rev_info *revs)
163 if (!revs->explicit_diff_merges)
164 set_dense_combined(revs);
167 void diff_merges_set_dense_combined_if_unset(struct rev_info *revs)
169 if (!revs->combine_merges)
170 set_dense_combined(revs);
173 void diff_merges_setup_revs(struct rev_info *revs)
175 if (revs->combine_merges == 0)
176 revs->dense_combined_merges = 0;
177 if (revs->separate_merges == 0)
178 revs->first_parent_merges = 0;
179 if (revs->combined_all_paths && !revs->combine_merges)
180 die("--combined-all-paths makes no sense without -c or --cc");
181 if (revs->merges_imply_patch)
182 revs->diff = 1;
183 if (revs->merges_imply_patch || revs->merges_need_diff) {
184 if (!revs->diffopt.output_format)
185 revs->diffopt.output_format = DIFF_FORMAT_PATCH;