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