git-compat-util.h: use "deprecated" for UNUSED variables
[git.git] / diff-merges.c
blob7f64156b8bfec6bb5ec17038eee0d73c68487988
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 set_separate(struct rev_info *revs)
25 suppress(revs);
26 revs->separate_merges = 1;
27 revs->simplify_history = 0;
30 static void set_first_parent(struct rev_info *revs)
32 set_separate(revs);
33 revs->first_parent_merges = 1;
36 static void set_combined(struct rev_info *revs)
38 suppress(revs);
39 revs->combine_merges = 1;
40 revs->dense_combined_merges = 0;
43 static void set_dense_combined(struct rev_info *revs)
45 suppress(revs);
46 revs->combine_merges = 1;
47 revs->dense_combined_merges = 1;
50 static void set_remerge_diff(struct rev_info *revs)
52 suppress(revs);
53 revs->remerge_diff = 1;
54 revs->simplify_history = 0;
57 static diff_merges_setup_func_t func_by_opt(const char *optarg)
59 if (!strcmp(optarg, "off") || !strcmp(optarg, "none"))
60 return suppress;
61 if (!strcmp(optarg, "1") || !strcmp(optarg, "first-parent"))
62 return set_first_parent;
63 else if (!strcmp(optarg, "separate"))
64 return set_separate;
65 else if (!strcmp(optarg, "c") || !strcmp(optarg, "combined"))
66 return set_combined;
67 else if (!strcmp(optarg, "cc") || !strcmp(optarg, "dense-combined"))
68 return set_dense_combined;
69 else if (!strcmp(optarg, "r") || !strcmp(optarg, "remerge"))
70 return set_remerge_diff;
71 else if (!strcmp(optarg, "m") || !strcmp(optarg, "on"))
72 return set_to_default;
73 return NULL;
76 static void set_diff_merges(struct rev_info *revs, const char *optarg)
78 diff_merges_setup_func_t func = func_by_opt(optarg);
80 if (!func)
81 die(_("invalid value for '%s': '%s'"), "--diff-merges", optarg);
83 func(revs);
85 /* NOTE: the merges_need_diff flag is cleared by func() call */
86 if (func != suppress)
87 revs->merges_need_diff = 1;
91 * Public functions. They are in the order they are called.
94 int diff_merges_config(const char *value)
96 diff_merges_setup_func_t func = func_by_opt(value);
98 if (!func)
99 return -1;
101 set_to_default = func;
102 return 0;
105 void diff_merges_suppress_m_parsing(void)
107 suppress_m_parsing = 1;
110 int diff_merges_parse_opts(struct rev_info *revs, const char **argv)
112 int argcount = 1;
113 const char *optarg;
114 const char *arg = argv[0];
116 if (!suppress_m_parsing && !strcmp(arg, "-m")) {
117 set_to_default(revs);
118 } else if (!strcmp(arg, "-c")) {
119 set_combined(revs);
120 revs->merges_imply_patch = 1;
121 } else if (!strcmp(arg, "--cc")) {
122 set_dense_combined(revs);
123 revs->merges_imply_patch = 1;
124 } else if (!strcmp(arg, "--remerge-diff")) {
125 set_remerge_diff(revs);
126 revs->merges_imply_patch = 1;
127 } else if (!strcmp(arg, "--no-diff-merges")) {
128 suppress(revs);
129 } else if (!strcmp(arg, "--combined-all-paths")) {
130 revs->combined_all_paths = 1;
131 } else if ((argcount = parse_long_opt("diff-merges", argv, &optarg))) {
132 set_diff_merges(revs, optarg);
133 } else
134 return 0;
136 revs->explicit_diff_merges = 1;
137 return argcount;
140 void diff_merges_suppress(struct rev_info *revs)
142 suppress(revs);
145 void diff_merges_default_to_first_parent(struct rev_info *revs)
147 if (!revs->explicit_diff_merges)
148 revs->separate_merges = 1;
149 if (revs->separate_merges)
150 revs->first_parent_merges = 1;
153 void diff_merges_default_to_dense_combined(struct rev_info *revs)
155 if (!revs->explicit_diff_merges)
156 set_dense_combined(revs);
159 void diff_merges_set_dense_combined_if_unset(struct rev_info *revs)
161 if (!revs->combine_merges)
162 set_dense_combined(revs);
165 void diff_merges_setup_revs(struct rev_info *revs)
167 if (revs->combine_merges == 0)
168 revs->dense_combined_merges = 0;
169 if (revs->separate_merges == 0)
170 revs->first_parent_merges = 0;
171 if (revs->combined_all_paths && !revs->combine_merges)
172 die("--combined-all-paths makes no sense without -c or --cc");
173 if (revs->merges_imply_patch)
174 revs->diff = 1;
175 if (revs->merges_imply_patch || revs->merges_need_diff) {
176 if (!revs->diffopt.output_format)
177 revs->diffopt.output_format = DIFF_FORMAT_PATCH;