diff-merges: new function diff_merges_set_dense_combined_if_unset()
[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->ignore_merges = 1;
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         revs->ignore_merges = -1;
27 }
28
29 int diff_merges_parse_opts(struct rev_info *revs, const char **argv)
30 {
31         int argcount = 1;
32         const char *optarg;
33         const char *arg = argv[0];
34
35         if (!strcmp(arg, "-m")) {
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->ignore_merges = 0;
42                 revs->match_missing = 1;
43         } else if (!strcmp(arg, "-c")) {
44                 revs->diff = 1;
45                 revs->dense_combined_merges = 0;
46                 revs->combine_merges = 1;
47         } else if (!strcmp(arg, "--cc")) {
48                 revs->diff = 1;
49                 set_dense_combined(revs);
50         } else if (!strcmp(arg, "--no-diff-merges")) {
51                 suppress(revs);
52         } else if (!strcmp(arg, "--combined-all-paths")) {
53                 revs->diff = 1;
54                 revs->combined_all_paths = 1;
55         } else if ((argcount = parse_long_opt("diff-merges", argv, &optarg))) {
56                 if (!strcmp(optarg, "off")) {
57                         suppress(revs);
58                 } else {
59                         die(_("unknown value for --diff-merges: %s"), optarg);
60                 }
61         } else
62                 argcount = 0;
63
64         return argcount;
65 }
66
67 void diff_merges_suppress(struct rev_info *revs)
68 {
69         suppress(revs);
70 }
71
72 void diff_merges_default_to_first_parent(struct rev_info *revs)
73 {
74         if (revs->ignore_merges < 0)            /* No -m */
75                 revs->ignore_merges = 0;
76 }
77
78 void diff_merges_default_to_dense_combined(struct rev_info *revs)
79 {
80         if (revs->ignore_merges < 0) {          /* No -m */
81                 revs->ignore_merges = 0;
82                 if (!revs->combine_merges) {    /* No -c/--cc" */
83                         revs->combine_merges = 1;
84                         revs->dense_combined_merges = 1;
85                 }
86         }
87 }
88
89 void diff_merges_set_dense_combined_if_unset(struct rev_info *revs)
90 {
91         if (!revs->combine_merges)
92                 set_dense_combined(revs);
93 }
94
95 void diff_merges_setup_revs(struct rev_info *revs)
96 {
97         if (revs->combine_merges && revs->ignore_merges < 0)
98                 revs->ignore_merges = 0;
99         if (revs->ignore_merges < 0)
100                 revs->ignore_merges = 1;
101         if (revs->combined_all_paths && !revs->combine_merges)
102                 die("--combined-all-paths makes no sense without -c or --cc");
103 }