2020-12-21 18:19:33 +03:00
|
|
|
#include "diff-merges.h"
|
|
|
|
|
|
|
|
#include "revision.h"
|
|
|
|
|
2021-04-13 14:41:14 +03: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;
|
2021-09-01 19:52:20 +03:00
|
|
|
static int suppress_m_parsing;
|
2021-04-13 14:41:14 +03:00
|
|
|
|
2020-12-21 18:19:38 +03:00
|
|
|
static void suppress(struct rev_info *revs)
|
|
|
|
{
|
2020-12-21 18:19:46 +03:00
|
|
|
revs->separate_merges = 0;
|
2020-12-21 18:19:38 +03:00
|
|
|
revs->first_parent_merges = 0;
|
|
|
|
revs->combine_merges = 0;
|
|
|
|
revs->dense_combined_merges = 0;
|
2020-12-21 18:19:50 +03:00
|
|
|
revs->combined_all_paths = 0;
|
2021-05-21 00:47:02 +03:00
|
|
|
revs->merges_imply_patch = 0;
|
2020-12-21 18:19:53 +03:00
|
|
|
revs->merges_need_diff = 0;
|
2020-12-21 18:19:38 +03:00
|
|
|
}
|
|
|
|
|
2020-12-21 18:19:49 +03:00
|
|
|
static void set_separate(struct rev_info *revs)
|
|
|
|
{
|
|
|
|
suppress(revs);
|
|
|
|
revs->separate_merges = 1;
|
|
|
|
}
|
|
|
|
|
2020-12-21 18:19:51 +03:00
|
|
|
static void set_first_parent(struct rev_info *revs)
|
|
|
|
{
|
|
|
|
set_separate(revs);
|
|
|
|
revs->first_parent_merges = 1;
|
|
|
|
}
|
|
|
|
|
2020-12-21 18:19:49 +03:00
|
|
|
static void set_combined(struct rev_info *revs)
|
|
|
|
{
|
2020-12-21 18:19:50 +03:00
|
|
|
suppress(revs);
|
2020-12-21 18:19:49 +03:00
|
|
|
revs->combine_merges = 1;
|
|
|
|
revs->dense_combined_merges = 0;
|
|
|
|
}
|
|
|
|
|
2020-12-21 18:19:39 +03:00
|
|
|
static void set_dense_combined(struct rev_info *revs)
|
|
|
|
{
|
2020-12-21 18:19:50 +03:00
|
|
|
suppress(revs);
|
2020-12-21 18:19:39 +03:00
|
|
|
revs->combine_merges = 1;
|
|
|
|
revs->dense_combined_merges = 1;
|
|
|
|
}
|
|
|
|
|
2021-04-13 14:41:15 +03:00
|
|
|
static diff_merges_setup_func_t func_by_opt(const char *optarg)
|
2020-12-21 18:19:49 +03:00
|
|
|
{
|
2021-04-13 14:41:15 +03:00
|
|
|
if (!strcmp(optarg, "off") || !strcmp(optarg, "none"))
|
|
|
|
return suppress;
|
2020-12-21 18:19:55 +03:00
|
|
|
if (!strcmp(optarg, "1") || !strcmp(optarg, "first-parent"))
|
2021-04-13 14:41:15 +03:00
|
|
|
return set_first_parent;
|
2021-04-13 14:41:16 +03:00
|
|
|
else if (!strcmp(optarg, "separate"))
|
2021-04-13 14:41:15 +03:00
|
|
|
return set_separate;
|
2020-12-21 18:19:54 +03:00
|
|
|
else if (!strcmp(optarg, "c") || !strcmp(optarg, "combined"))
|
2021-04-13 14:41:15 +03:00
|
|
|
return set_combined;
|
2020-12-21 18:19:54 +03:00
|
|
|
else if (!strcmp(optarg, "cc") || !strcmp(optarg, "dense-combined"))
|
2021-04-13 14:41:15 +03:00
|
|
|
return set_dense_combined;
|
2021-04-13 14:41:16 +03:00
|
|
|
else if (!strcmp(optarg, "m") || !strcmp(optarg, "on"))
|
2021-04-13 14:41:15 +03: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 18:19:49 +03:00
|
|
|
die(_("unknown value for --diff-merges: %s"), optarg);
|
2020-12-21 18:19:53 +03:00
|
|
|
|
2021-04-13 14:41:15 +03: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 18:19:49 +03:00
|
|
|
}
|
2020-12-21 18:19:39 +03:00
|
|
|
|
2020-12-21 18:19:37 +03:00
|
|
|
/*
|
|
|
|
* Public functions. They are in the order they are called.
|
|
|
|
*/
|
|
|
|
|
2021-04-13 14:41:17 +03:00
|
|
|
int diff_merges_config(const char *value)
|
|
|
|
{
|
|
|
|
diff_merges_setup_func_t func = func_by_opt(value);
|
|
|
|
|
|
|
|
if (!func)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
set_to_default = func;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-09-01 19:52:20 +03:00
|
|
|
void diff_merges_suppress_m_parsing(void)
|
2021-05-21 00:46:59 +03:00
|
|
|
{
|
2021-09-01 19:52:20 +03:00
|
|
|
suppress_m_parsing = 1;
|
2021-05-21 00:46:59 +03:00
|
|
|
}
|
|
|
|
|
2020-12-21 18:19:34 +03:00
|
|
|
int diff_merges_parse_opts(struct rev_info *revs, const char **argv)
|
2020-12-21 18:19:33 +03:00
|
|
|
{
|
|
|
|
int argcount = 1;
|
|
|
|
const char *optarg;
|
|
|
|
const char *arg = argv[0];
|
|
|
|
|
2021-09-01 19:52:20 +03:00
|
|
|
if (!suppress_m_parsing && !strcmp(arg, "-m")) {
|
2021-05-21 00:46:59 +03:00
|
|
|
set_to_default(revs);
|
2020-12-21 18:19:52 +03:00
|
|
|
} else if (!strcmp(arg, "-c")) {
|
2020-12-21 18:19:49 +03:00
|
|
|
set_combined(revs);
|
2021-05-21 00:47:02 +03:00
|
|
|
revs->merges_imply_patch = 1;
|
2020-12-21 18:19:52 +03:00
|
|
|
} else if (!strcmp(arg, "--cc")) {
|
2020-12-21 18:19:39 +03:00
|
|
|
set_dense_combined(revs);
|
2021-05-21 00:47:02 +03:00
|
|
|
revs->merges_imply_patch = 1;
|
2020-12-21 18:19:52 +03:00
|
|
|
} else if (!strcmp(arg, "--no-diff-merges")) {
|
2020-12-21 18:19:38 +03:00
|
|
|
suppress(revs);
|
2020-12-21 18:19:52 +03:00
|
|
|
} else if (!strcmp(arg, "--combined-all-paths")) {
|
2020-12-21 18:19:33 +03:00
|
|
|
revs->combined_all_paths = 1;
|
2020-12-21 18:19:52 +03:00
|
|
|
} else if ((argcount = parse_long_opt("diff-merges", argv, &optarg))) {
|
2020-12-21 18:19:49 +03:00
|
|
|
set_diff_merges(revs, optarg);
|
2020-12-21 18:19:52 +03:00
|
|
|
} else
|
2020-12-21 18:19:46 +03:00
|
|
|
return 0;
|
2020-12-21 18:19:33 +03:00
|
|
|
|
2020-12-21 18:19:46 +03:00
|
|
|
revs->explicit_diff_merges = 1;
|
2020-12-21 18:19:33 +03:00
|
|
|
return argcount;
|
|
|
|
}
|
|
|
|
|
2020-12-21 18:19:38 +03:00
|
|
|
void diff_merges_suppress(struct rev_info *revs)
|
|
|
|
{
|
|
|
|
suppress(revs);
|
|
|
|
}
|
|
|
|
|
2020-12-21 18:19:36 +03:00
|
|
|
void diff_merges_default_to_first_parent(struct rev_info *revs)
|
2020-12-21 18:19:33 +03:00
|
|
|
{
|
2020-12-21 18:19:46 +03:00
|
|
|
if (!revs->explicit_diff_merges)
|
|
|
|
revs->separate_merges = 1;
|
|
|
|
if (revs->separate_merges)
|
2020-12-21 18:19:40 +03:00
|
|
|
revs->first_parent_merges = 1;
|
2020-12-21 18:19:33 +03:00
|
|
|
}
|
|
|
|
|
2020-12-21 18:19:34 +03:00
|
|
|
void diff_merges_default_to_dense_combined(struct rev_info *revs)
|
2020-12-21 18:19:33 +03:00
|
|
|
{
|
2020-12-21 18:19:46 +03:00
|
|
|
if (!revs->explicit_diff_merges)
|
|
|
|
set_dense_combined(revs);
|
2020-12-21 18:19:33 +03:00
|
|
|
}
|
2020-12-21 18:19:37 +03:00
|
|
|
|
2020-12-21 18:19:39 +03:00
|
|
|
void diff_merges_set_dense_combined_if_unset(struct rev_info *revs)
|
|
|
|
{
|
|
|
|
if (!revs->combine_merges)
|
|
|
|
set_dense_combined(revs);
|
|
|
|
}
|
|
|
|
|
2020-12-21 18:19:37 +03:00
|
|
|
void diff_merges_setup_revs(struct rev_info *revs)
|
|
|
|
{
|
2020-12-21 18:19:46 +03:00
|
|
|
if (revs->combine_merges == 0)
|
|
|
|
revs->dense_combined_merges = 0;
|
|
|
|
if (revs->separate_merges == 0)
|
|
|
|
revs->first_parent_merges = 0;
|
2020-12-21 18:19:37 +03:00
|
|
|
if (revs->combined_all_paths && !revs->combine_merges)
|
|
|
|
die("--combined-all-paths makes no sense without -c or --cc");
|
2021-05-21 00:47:02 +03:00
|
|
|
if (revs->merges_imply_patch)
|
2020-12-21 18:19:42 +03:00
|
|
|
revs->diff = 1;
|
2021-05-21 00:47:02 +03:00
|
|
|
if (revs->merges_imply_patch || revs->merges_need_diff) {
|
2020-12-21 18:19:41 +03:00
|
|
|
if (!revs->diffopt.output_format)
|
|
|
|
revs->diffopt.output_format = DIFF_FORMAT_PATCH;
|
|
|
|
}
|
2020-12-21 18:19:37 +03:00
|
|
|
}
|