diff-merges: split 'ignore_merges' field
[git] / diff-merges.c
1 #include "diff-merges.h"
2
3 #include "revision.h"
4
5 static void suppress(struct rev_info *revs)
6 {
7         revs->separate_merges = 0;
8         revs->first_parent_merges = 0;
9         revs->combine_merges = 0;
10         revs->dense_combined_merges = 0;
11 }
12
13 static void set_dense_combined(struct rev_info *revs)
14 {
15         revs->combine_merges = 1;
16         revs->dense_combined_merges = 1;
17 }
18
19
20 /*
21  * Public functions. They are in the order they are called.
22  */
23
24 void diff_merges_init_revs(struct rev_info *revs)
25 {
26 }
27
28 int diff_merges_parse_opts(struct rev_info *revs, const char **argv)
29 {
30         int argcount = 1;
31         const char *optarg;
32         const char *arg = argv[0];
33
34         if (!strcmp(arg, "-m")) {
35                 suppress(revs);
36                 /*
37                  * To "diff-index", "-m" means "match missing", and to the "log"
38                  * family of commands, it means "show full diff for merges". Set
39                  * both fields appropriately.
40                  */
41                 revs->separate_merges = 1;
42                 revs->match_missing = 1;
43         } else if (!strcmp(arg, "-c")) {
44                 revs->dense_combined_merges = 0;
45                 revs->combine_merges = 1;
46         } else if (!strcmp(arg, "--cc")) {
47                 set_dense_combined(revs);
48         } else if (!strcmp(arg, "--no-diff-merges")) {
49                 suppress(revs);
50         } else if (!strcmp(arg, "--combined-all-paths")) {
51                 revs->combined_all_paths = 1;
52         } else if ((argcount = parse_long_opt("diff-merges", argv, &optarg))) {
53                 if (!strcmp(optarg, "off")) {
54                         suppress(revs);
55                 } else {
56                         die(_("unknown value for --diff-merges: %s"), optarg);
57                 }
58         } else
59                 return 0;
60
61         revs->explicit_diff_merges = 1;
62         return argcount;
63 }
64
65 void diff_merges_suppress(struct rev_info *revs)
66 {
67         suppress(revs);
68 }
69
70 void diff_merges_default_to_first_parent(struct rev_info *revs)
71 {
72         if (!revs->explicit_diff_merges)
73                 revs->separate_merges = 1;
74         if (revs->separate_merges)
75                 revs->first_parent_merges = 1;
76 }
77
78 void diff_merges_default_to_dense_combined(struct rev_info *revs)
79 {
80         if (!revs->explicit_diff_merges)
81                 set_dense_combined(revs);
82 }
83
84 void diff_merges_set_dense_combined_if_unset(struct rev_info *revs)
85 {
86         if (!revs->combine_merges)
87                 set_dense_combined(revs);
88 }
89
90 void diff_merges_setup_revs(struct rev_info *revs)
91 {
92         if (revs->combine_merges == 0)
93                 revs->dense_combined_merges = 0;
94         if (revs->separate_merges == 0)
95                 revs->first_parent_merges = 0;
96         if (revs->combined_all_paths && !revs->combine_merges)
97                 die("--combined-all-paths makes no sense without -c or --cc");
98         if (revs->combine_merges) {
99                 revs->diff = 1;
100                 /* Turn --cc/-c into -p --cc/-c when -p was not given */
101                 if (!revs->diffopt.output_format)
102                         revs->diffopt.output_format = DIFF_FORMAT_PATCH;
103         }
104 }