2020-12-21 15:19:33 +00:00
|
|
|
#include "diff-merges.h"
|
|
|
|
|
|
|
|
#include "revision.h"
|
|
|
|
|
2020-12-21 15:19:38 +00:00
|
|
|
static void suppress(struct rev_info *revs)
|
|
|
|
{
|
2020-12-21 15:19:46 +00:00
|
|
|
revs->separate_merges = 0;
|
2020-12-21 15:19:38 +00:00
|
|
|
revs->first_parent_merges = 0;
|
|
|
|
revs->combine_merges = 0;
|
|
|
|
revs->dense_combined_merges = 0;
|
2020-12-21 15:19:50 +00:00
|
|
|
revs->combined_all_paths = 0;
|
2020-12-21 15:19:52 +00:00
|
|
|
revs->combined_imply_patch = 0;
|
2020-12-21 15:19:53 +00:00
|
|
|
revs->merges_need_diff = 0;
|
2020-12-21 15:19:38 +00:00
|
|
|
}
|
|
|
|
|
2020-12-21 15:19:49 +00:00
|
|
|
static void set_separate(struct rev_info *revs)
|
|
|
|
{
|
|
|
|
suppress(revs);
|
|
|
|
revs->separate_merges = 1;
|
|
|
|
}
|
|
|
|
|
2020-12-21 15:19:51 +00:00
|
|
|
static void set_first_parent(struct rev_info *revs)
|
|
|
|
{
|
|
|
|
set_separate(revs);
|
|
|
|
revs->first_parent_merges = 1;
|
|
|
|
}
|
|
|
|
|
2020-12-21 15:19:49 +00: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 15:19:50 +00:00
|
|
|
suppress(revs);
|
2020-12-21 15:19:49 +00:00
|
|
|
revs->combine_merges = 1;
|
|
|
|
revs->dense_combined_merges = 0;
|
|
|
|
}
|
|
|
|
|
2020-12-21 15:19:39 +00:00
|
|
|
static void set_dense_combined(struct rev_info *revs)
|
|
|
|
{
|
2020-12-21 15:19:50 +00:00
|
|
|
suppress(revs);
|
2020-12-21 15:19:39 +00:00
|
|
|
revs->combine_merges = 1;
|
|
|
|
revs->dense_combined_merges = 1;
|
|
|
|
}
|
|
|
|
|
2020-12-21 15:19:49 +00:00
|
|
|
static void set_diff_merges(struct rev_info *revs, const char *optarg)
|
|
|
|
{
|
2020-12-21 15:19:53 +00:00
|
|
|
if (!strcmp(optarg, "off") || !strcmp(optarg, "none")) {
|
2020-12-21 15:19:49 +00:00
|
|
|
suppress(revs);
|
2020-12-21 15:19:53 +00:00
|
|
|
/* Return early to leave revs->merges_need_diff unset */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-21 15:19:55 +00:00
|
|
|
if (!strcmp(optarg, "1") || !strcmp(optarg, "first-parent"))
|
2020-12-21 15:19:51 +00:00
|
|
|
set_first_parent(revs);
|
2020-12-21 15:19:54 +00:00
|
|
|
else if (!strcmp(optarg, "m") || !strcmp(optarg, "separate"))
|
2020-12-21 15:19:51 +00:00
|
|
|
set_separate(revs);
|
2020-12-21 15:19:54 +00:00
|
|
|
else if (!strcmp(optarg, "c") || !strcmp(optarg, "combined"))
|
2020-12-21 15:19:51 +00:00
|
|
|
set_combined(revs);
|
2020-12-21 15:19:54 +00:00
|
|
|
else if (!strcmp(optarg, "cc") || !strcmp(optarg, "dense-combined"))
|
2020-12-21 15:19:51 +00:00
|
|
|
set_dense_combined(revs);
|
|
|
|
else
|
2020-12-21 15:19:49 +00:00
|
|
|
die(_("unknown value for --diff-merges: %s"), optarg);
|
2020-12-21 15:19:53 +00:00
|
|
|
|
|
|
|
/* The flag is cleared by set_xxx() functions, so don't move this up */
|
|
|
|
revs->merges_need_diff = 1;
|
2020-12-21 15:19:49 +00:00
|
|
|
}
|
2020-12-21 15:19:39 +00:00
|
|
|
|
2020-12-21 15:19:37 +00:00
|
|
|
/*
|
|
|
|
* Public functions. They are in the order they are called.
|
|
|
|
*/
|
|
|
|
|
2020-12-21 15:19:34 +00:00
|
|
|
int diff_merges_parse_opts(struct rev_info *revs, const char **argv)
|
2020-12-21 15:19:33 +00:00
|
|
|
{
|
|
|
|
int argcount = 1;
|
|
|
|
const char *optarg;
|
|
|
|
const char *arg = argv[0];
|
|
|
|
|
2020-12-21 15:19:52 +00:00
|
|
|
if (!strcmp(arg, "-m")) {
|
2020-12-21 15:19:49 +00:00
|
|
|
set_m(revs);
|
2020-12-21 15:19:52 +00:00
|
|
|
} else if (!strcmp(arg, "-c")) {
|
2020-12-21 15:19:49 +00:00
|
|
|
set_combined(revs);
|
2020-12-21 15:19:52 +00:00
|
|
|
revs->combined_imply_patch = 1;
|
|
|
|
} else if (!strcmp(arg, "--cc")) {
|
2020-12-21 15:19:39 +00:00
|
|
|
set_dense_combined(revs);
|
2020-12-21 15:19:52 +00:00
|
|
|
revs->combined_imply_patch = 1;
|
|
|
|
} else if (!strcmp(arg, "--no-diff-merges")) {
|
2020-12-21 15:19:38 +00:00
|
|
|
suppress(revs);
|
2020-12-21 15:19:52 +00:00
|
|
|
} else if (!strcmp(arg, "--combined-all-paths")) {
|
2020-12-21 15:19:33 +00:00
|
|
|
revs->combined_all_paths = 1;
|
2020-12-21 15:19:52 +00:00
|
|
|
} else if ((argcount = parse_long_opt("diff-merges", argv, &optarg))) {
|
2020-12-21 15:19:49 +00:00
|
|
|
set_diff_merges(revs, optarg);
|
2020-12-21 15:19:52 +00:00
|
|
|
} else
|
2020-12-21 15:19:46 +00:00
|
|
|
return 0;
|
2020-12-21 15:19:33 +00:00
|
|
|
|
2020-12-21 15:19:46 +00:00
|
|
|
revs->explicit_diff_merges = 1;
|
2020-12-21 15:19:33 +00:00
|
|
|
return argcount;
|
|
|
|
}
|
|
|
|
|
2020-12-21 15:19:38 +00:00
|
|
|
void diff_merges_suppress(struct rev_info *revs)
|
|
|
|
{
|
|
|
|
suppress(revs);
|
|
|
|
}
|
|
|
|
|
2020-12-21 15:19:36 +00:00
|
|
|
void diff_merges_default_to_first_parent(struct rev_info *revs)
|
2020-12-21 15:19:33 +00:00
|
|
|
{
|
2020-12-21 15:19:46 +00:00
|
|
|
if (!revs->explicit_diff_merges)
|
|
|
|
revs->separate_merges = 1;
|
|
|
|
if (revs->separate_merges)
|
2020-12-21 15:19:40 +00:00
|
|
|
revs->first_parent_merges = 1;
|
2020-12-21 15:19:33 +00:00
|
|
|
}
|
|
|
|
|
2020-12-21 15:19:34 +00:00
|
|
|
void diff_merges_default_to_dense_combined(struct rev_info *revs)
|
2020-12-21 15:19:33 +00:00
|
|
|
{
|
2020-12-21 15:19:46 +00:00
|
|
|
if (!revs->explicit_diff_merges)
|
|
|
|
set_dense_combined(revs);
|
2020-12-21 15:19:33 +00:00
|
|
|
}
|
2020-12-21 15:19:37 +00:00
|
|
|
|
2020-12-21 15:19:39 +00:00
|
|
|
void diff_merges_set_dense_combined_if_unset(struct rev_info *revs)
|
|
|
|
{
|
|
|
|
if (!revs->combine_merges)
|
|
|
|
set_dense_combined(revs);
|
|
|
|
}
|
|
|
|
|
2020-12-21 15:19:37 +00:00
|
|
|
void diff_merges_setup_revs(struct rev_info *revs)
|
|
|
|
{
|
2020-12-21 15:19:46 +00:00
|
|
|
if (revs->combine_merges == 0)
|
|
|
|
revs->dense_combined_merges = 0;
|
|
|
|
if (revs->separate_merges == 0)
|
|
|
|
revs->first_parent_merges = 0;
|
2020-12-21 15:19:37 +00:00
|
|
|
if (revs->combined_all_paths && !revs->combine_merges)
|
|
|
|
die("--combined-all-paths makes no sense without -c or --cc");
|
2020-12-21 15:19:53 +00:00
|
|
|
if (revs->combined_imply_patch)
|
2020-12-21 15:19:42 +00:00
|
|
|
revs->diff = 1;
|
2020-12-21 15:19:53 +00:00
|
|
|
if (revs->combined_imply_patch || revs->merges_need_diff) {
|
2020-12-21 15:19:41 +00:00
|
|
|
if (!revs->diffopt.output_format)
|
|
|
|
revs->diffopt.output_format = DIFF_FORMAT_PATCH;
|
|
|
|
}
|
2020-12-21 15:19:37 +00:00
|
|
|
}
|