2020-12-21 16:19:33 +01:00
|
|
|
#include "diff-merges.h"
|
|
|
|
|
|
|
|
#include "revision.h"
|
|
|
|
|
2021-04-13 13:41:14 +02:00
|
|
|
typedef void (*diff_merges_setup_func_t)(struct rev_info *);
|
|
|
|
static void set_separate(struct rev_info *revs);
|
|
|
|
|
|
|
|
static diff_merges_setup_func_t set_to_default = set_separate;
|
|
|
|
|
2020-12-21 16:19:38 +01:00
|
|
|
static void suppress(struct rev_info *revs)
|
|
|
|
{
|
2020-12-21 16:19:46 +01:00
|
|
|
revs->separate_merges = 0;
|
2020-12-21 16:19:38 +01:00
|
|
|
revs->first_parent_merges = 0;
|
|
|
|
revs->combine_merges = 0;
|
|
|
|
revs->dense_combined_merges = 0;
|
2020-12-21 16:19:50 +01:00
|
|
|
revs->combined_all_paths = 0;
|
2020-12-21 16:19:52 +01:00
|
|
|
revs->combined_imply_patch = 0;
|
2020-12-21 16:19:53 +01:00
|
|
|
revs->merges_need_diff = 0;
|
2020-12-21 16:19:38 +01:00
|
|
|
}
|
|
|
|
|
2020-12-21 16:19:49 +01:00
|
|
|
static void set_separate(struct rev_info *revs)
|
|
|
|
{
|
|
|
|
suppress(revs);
|
|
|
|
revs->separate_merges = 1;
|
|
|
|
}
|
|
|
|
|
2020-12-21 16:19:51 +01:00
|
|
|
static void set_first_parent(struct rev_info *revs)
|
|
|
|
{
|
|
|
|
set_separate(revs);
|
|
|
|
revs->first_parent_merges = 1;
|
|
|
|
}
|
|
|
|
|
2020-12-21 16:19:49 +01:00
|
|
|
static void set_m(struct rev_info *revs)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* To "diff-index", "-m" means "match missing", and to the "log"
|
|
|
|
* family of commands, it means "show full diff for merges". Set
|
|
|
|
* both fields appropriately.
|
|
|
|
*/
|
|
|
|
set_separate(revs);
|
|
|
|
revs->match_missing = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_combined(struct rev_info *revs)
|
|
|
|
{
|
2020-12-21 16:19:50 +01:00
|
|
|
suppress(revs);
|
2020-12-21 16:19:49 +01:00
|
|
|
revs->combine_merges = 1;
|
|
|
|
revs->dense_combined_merges = 0;
|
|
|
|
}
|
|
|
|
|
2020-12-21 16:19:39 +01:00
|
|
|
static void set_dense_combined(struct rev_info *revs)
|
|
|
|
{
|
2020-12-21 16:19:50 +01:00
|
|
|
suppress(revs);
|
2020-12-21 16:19:39 +01:00
|
|
|
revs->combine_merges = 1;
|
|
|
|
revs->dense_combined_merges = 1;
|
|
|
|
}
|
|
|
|
|
2021-04-13 13:41:15 +02:00
|
|
|
static diff_merges_setup_func_t func_by_opt(const char *optarg)
|
2020-12-21 16:19:49 +01:00
|
|
|
{
|
2021-04-13 13:41:15 +02:00
|
|
|
if (!strcmp(optarg, "off") || !strcmp(optarg, "none"))
|
|
|
|
return suppress;
|
2020-12-21 16:19:55 +01:00
|
|
|
if (!strcmp(optarg, "1") || !strcmp(optarg, "first-parent"))
|
2021-04-13 13:41:15 +02:00
|
|
|
return set_first_parent;
|
2020-12-21 16:19:54 +01:00
|
|
|
else if (!strcmp(optarg, "m") || !strcmp(optarg, "separate"))
|
2021-04-13 13:41:15 +02:00
|
|
|
return set_separate;
|
2020-12-21 16:19:54 +01:00
|
|
|
else if (!strcmp(optarg, "c") || !strcmp(optarg, "combined"))
|
2021-04-13 13:41:15 +02:00
|
|
|
return set_combined;
|
2020-12-21 16:19:54 +01:00
|
|
|
else if (!strcmp(optarg, "cc") || !strcmp(optarg, "dense-combined"))
|
2021-04-13 13:41:15 +02:00
|
|
|
return set_dense_combined;
|
2021-04-13 13:41:14 +02:00
|
|
|
else if (!strcmp(optarg, "on"))
|
2021-04-13 13:41:15 +02:00
|
|
|
return set_to_default;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_diff_merges(struct rev_info *revs, const char *optarg)
|
|
|
|
{
|
|
|
|
diff_merges_setup_func_t func = func_by_opt(optarg);
|
|
|
|
|
|
|
|
if (!func)
|
2020-12-21 16:19:49 +01:00
|
|
|
die(_("unknown value for --diff-merges: %s"), optarg);
|
2020-12-21 16:19:53 +01:00
|
|
|
|
2021-04-13 13:41:15 +02:00
|
|
|
func(revs);
|
|
|
|
|
|
|
|
/* NOTE: the merges_need_diff flag is cleared by func() call */
|
|
|
|
if (func != suppress)
|
|
|
|
revs->merges_need_diff = 1;
|
2020-12-21 16:19:49 +01:00
|
|
|
}
|
2020-12-21 16:19:39 +01:00
|
|
|
|
2020-12-21 16:19:37 +01:00
|
|
|
/*
|
|
|
|
* Public functions. They are in the order they are called.
|
|
|
|
*/
|
|
|
|
|
2020-12-21 16:19:34 +01:00
|
|
|
int diff_merges_parse_opts(struct rev_info *revs, const char **argv)
|
2020-12-21 16:19:33 +01:00
|
|
|
{
|
|
|
|
int argcount = 1;
|
|
|
|
const char *optarg;
|
|
|
|
const char *arg = argv[0];
|
|
|
|
|
2020-12-21 16:19:52 +01:00
|
|
|
if (!strcmp(arg, "-m")) {
|
2020-12-21 16:19:49 +01:00
|
|
|
set_m(revs);
|
2020-12-21 16:19:52 +01:00
|
|
|
} else if (!strcmp(arg, "-c")) {
|
2020-12-21 16:19:49 +01:00
|
|
|
set_combined(revs);
|
2020-12-21 16:19:52 +01:00
|
|
|
revs->combined_imply_patch = 1;
|
|
|
|
} else if (!strcmp(arg, "--cc")) {
|
2020-12-21 16:19:39 +01:00
|
|
|
set_dense_combined(revs);
|
2020-12-21 16:19:52 +01:00
|
|
|
revs->combined_imply_patch = 1;
|
|
|
|
} else if (!strcmp(arg, "--no-diff-merges")) {
|
2020-12-21 16:19:38 +01:00
|
|
|
suppress(revs);
|
2020-12-21 16:19:52 +01:00
|
|
|
} else if (!strcmp(arg, "--combined-all-paths")) {
|
2020-12-21 16:19:33 +01:00
|
|
|
revs->combined_all_paths = 1;
|
2020-12-21 16:19:52 +01:00
|
|
|
} else if ((argcount = parse_long_opt("diff-merges", argv, &optarg))) {
|
2020-12-21 16:19:49 +01:00
|
|
|
set_diff_merges(revs, optarg);
|
2020-12-21 16:19:52 +01:00
|
|
|
} else
|
2020-12-21 16:19:46 +01:00
|
|
|
return 0;
|
2020-12-21 16:19:33 +01:00
|
|
|
|
2020-12-21 16:19:46 +01:00
|
|
|
revs->explicit_diff_merges = 1;
|
2020-12-21 16:19:33 +01:00
|
|
|
return argcount;
|
|
|
|
}
|
|
|
|
|
2020-12-21 16:19:38 +01:00
|
|
|
void diff_merges_suppress(struct rev_info *revs)
|
|
|
|
{
|
|
|
|
suppress(revs);
|
|
|
|
}
|
|
|
|
|
2020-12-21 16:19:36 +01:00
|
|
|
void diff_merges_default_to_first_parent(struct rev_info *revs)
|
2020-12-21 16:19:33 +01:00
|
|
|
{
|
2020-12-21 16:19:46 +01:00
|
|
|
if (!revs->explicit_diff_merges)
|
|
|
|
revs->separate_merges = 1;
|
|
|
|
if (revs->separate_merges)
|
2020-12-21 16:19:40 +01:00
|
|
|
revs->first_parent_merges = 1;
|
2020-12-21 16:19:33 +01:00
|
|
|
}
|
|
|
|
|
2020-12-21 16:19:34 +01:00
|
|
|
void diff_merges_default_to_dense_combined(struct rev_info *revs)
|
2020-12-21 16:19:33 +01:00
|
|
|
{
|
2020-12-21 16:19:46 +01:00
|
|
|
if (!revs->explicit_diff_merges)
|
|
|
|
set_dense_combined(revs);
|
2020-12-21 16:19:33 +01:00
|
|
|
}
|
2020-12-21 16:19:37 +01:00
|
|
|
|
2020-12-21 16:19:39 +01:00
|
|
|
void diff_merges_set_dense_combined_if_unset(struct rev_info *revs)
|
|
|
|
{
|
|
|
|
if (!revs->combine_merges)
|
|
|
|
set_dense_combined(revs);
|
|
|
|
}
|
|
|
|
|
2020-12-21 16:19:37 +01:00
|
|
|
void diff_merges_setup_revs(struct rev_info *revs)
|
|
|
|
{
|
2020-12-21 16:19:46 +01:00
|
|
|
if (revs->combine_merges == 0)
|
|
|
|
revs->dense_combined_merges = 0;
|
|
|
|
if (revs->separate_merges == 0)
|
|
|
|
revs->first_parent_merges = 0;
|
2020-12-21 16:19:37 +01:00
|
|
|
if (revs->combined_all_paths && !revs->combine_merges)
|
|
|
|
die("--combined-all-paths makes no sense without -c or --cc");
|
2020-12-21 16:19:53 +01:00
|
|
|
if (revs->combined_imply_patch)
|
2020-12-21 16:19:42 +01:00
|
|
|
revs->diff = 1;
|
2020-12-21 16:19:53 +01:00
|
|
|
if (revs->combined_imply_patch || revs->merges_need_diff) {
|
2020-12-21 16:19:41 +01:00
|
|
|
if (!revs->diffopt.output_format)
|
|
|
|
revs->diffopt.output_format = DIFF_FORMAT_PATCH;
|
|
|
|
}
|
2020-12-21 16:19:37 +01:00
|
|
|
}
|