diff-merges: rename diff_merges_default_to_enable() to match semantics
[git] / diff-merges.c
1 #include "diff-merges.h"
2
3 #include "revision.h"
4
5 void diff_merges_init_revs(struct rev_info *revs)
6 {
7         revs->ignore_merges = -1;
8 }
9
10 int diff_merges_parse_opts(struct rev_info *revs, const char **argv)
11 {
12         int argcount = 1;
13         const char *optarg;
14         const char *arg = argv[0];
15
16         if (!strcmp(arg, "-m")) {
17                 /*
18                  * To "diff-index", "-m" means "match missing", and to the "log"
19                  * family of commands, it means "show full diff for merges". Set
20                  * both fields appropriately.
21                  */
22                 revs->ignore_merges = 0;
23                 revs->match_missing = 1;
24         } else if (!strcmp(arg, "-c")) {
25                 revs->diff = 1;
26                 revs->dense_combined_merges = 0;
27                 revs->combine_merges = 1;
28         } else if (!strcmp(arg, "--cc")) {
29                 revs->diff = 1;
30                 revs->dense_combined_merges = 1;
31                 revs->combine_merges = 1;
32         } else if (!strcmp(arg, "--no-diff-merges")) {
33                 revs->ignore_merges = 1;
34         } else if (!strcmp(arg, "--combined-all-paths")) {
35                 revs->diff = 1;
36                 revs->combined_all_paths = 1;
37         } else if ((argcount = parse_long_opt("diff-merges", argv, &optarg))) {
38                 if (!strcmp(optarg, "off")) {
39                         revs->ignore_merges = 1;
40                 } else {
41                         die(_("unknown value for --diff-merges: %s"), optarg);
42                 }
43         } else
44                 argcount = 0;
45
46         return argcount;
47 }
48
49 void diff_merges_setup_revs(struct rev_info *revs)
50 {
51         if (revs->combine_merges && revs->ignore_merges < 0)
52                 revs->ignore_merges = 0;
53         if (revs->ignore_merges < 0)
54                 revs->ignore_merges = 1;
55         if (revs->combined_all_paths && !revs->combine_merges)
56                 die("--combined-all-paths makes no sense without -c or --cc");
57 }
58
59 void diff_merges_default_to_first_parent(struct rev_info *revs)
60 {
61         if (revs->ignore_merges < 0)            /* No -m */
62                 revs->ignore_merges = 0;
63 }
64
65 void diff_merges_default_to_dense_combined(struct rev_info *revs)
66 {
67         if (revs->ignore_merges < 0) {          /* No -m */
68                 revs->ignore_merges = 0;
69                 if (!revs->combine_merges) {    /* No -c/--cc" */
70                         revs->combine_merges = 1;
71                         revs->dense_combined_merges = 1;
72                 }
73         }
74 }