merge-recursive: honor diff.algorithm

The documentation claims that "recursive defaults to the diff.algorithm
config setting", but this is currently not the case. This fixes it,
ensuring that diff.algorithm is used when -Xdiff-algorithm is not
supplied. This affects the following porcelain commands: "merge",
"rebase", "cherry-pick", "pull", "stash", "log", "am" and "checkout".
It also affects the "merge-tree" ancillary interrogator.

This change refactors the initialization of merge options to introduce
two functions, "init_merge_ui_options" and "init_merge_basic_options"
instead of just one "init_merge_options". This design follows the
approach used in diff.c, providing initialization methods for
porcelain and plumbing commands respectively. Thanks to that, the
"replay" and "merge-recursive" plumbing commands remain unaffected by
diff.algorithm.

Signed-off-by: Antonin Delpeuch <antonin@delpeuch.eu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Antonin Delpeuch
2024-07-13 16:51:46 +00:00
committed by Junio C Hamano
parent 557ae147e6
commit 9c93ba4d0a
15 changed files with 150 additions and 15 deletions

View File

@ -3921,7 +3921,7 @@ int merge_recursive_generic(struct merge_options *opt,
return clean ? 0 : 1;
}
static void merge_recursive_config(struct merge_options *opt)
static void merge_recursive_config(struct merge_options *opt, int ui)
{
char *value = NULL;
int renormalize = 0;
@ -3950,11 +3950,20 @@ static void merge_recursive_config(struct merge_options *opt)
} /* avoid erroring on values from future versions of git */
free(value);
}
if (ui) {
if (!git_config_get_string("diff.algorithm", &value)) {
long diff_algorithm = parse_algorithm_value(value);
if (diff_algorithm < 0)
die(_("unknown value for config '%s': %s"), "diff.algorithm", value);
opt->xdl_opts = (opt->xdl_opts & ~XDF_DIFF_ALGORITHM_MASK) | diff_algorithm;
free(value);
}
}
git_config(git_xmerge_config, NULL);
}
void init_merge_options(struct merge_options *opt,
struct repository *repo)
static void init_merge_options(struct merge_options *opt,
struct repository *repo, int ui)
{
const char *merge_verbosity;
memset(opt, 0, sizeof(struct merge_options));
@ -3973,7 +3982,7 @@ void init_merge_options(struct merge_options *opt,
opt->conflict_style = -1;
merge_recursive_config(opt);
merge_recursive_config(opt, ui);
merge_verbosity = getenv("GIT_MERGE_VERBOSITY");
if (merge_verbosity)
opt->verbosity = strtol(merge_verbosity, NULL, 10);
@ -3981,6 +3990,18 @@ void init_merge_options(struct merge_options *opt,
opt->buffer_output = 0;
}
void init_ui_merge_options(struct merge_options *opt,
struct repository *repo)
{
init_merge_options(opt, repo, 1);
}
void init_basic_merge_options(struct merge_options *opt,
struct repository *repo)
{
init_merge_options(opt, repo, 0);
}
/*
* For now, members of merge_options do not need deep copying, but
* it may change in the future, in which case we would need to update