Skip to content

Commit 8599ab4

Browse files
newrengitster
authored andcommitted
merge-recursive: consolidate unnecessary fields in merge_options
We provided users with the ability to state whether they wanted rename detection, and to put a limit on how much CPU would be spent. Both of these fields had multiple configuration parameters for setting them, with one being a fallback and the other being an override. However, instead of implementing the logic for how to combine the multiple source locations into the appropriate setting at config loading time, we loaded and tracked both values and then made the code combine them every time it wanted to check the overall value. This had a few minor drawbacks: * it seems more complicated than necessary * it runs the risk of people using the independent settings in the future and breaking the intent of how the options are used together * it makes merge_options more complicated than necessary for other potential users of the API Fix these problems by moving the logic for combining the pairs of options into a single value; make it apply at time-of-config-loading instead of each-time-of-use. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7c0a6c8 commit 8599ab4

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

merge-recursive.c

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,7 @@ static int add_cacheinfo(struct merge_options *opt,
385385

386386
static inline int merge_detect_rename(struct merge_options *opt)
387387
{
388-
return opt->merge_detect_rename >= 0 ? opt->merge_detect_rename :
389-
opt->diff_detect_rename >= 0 ? opt->diff_detect_rename : 1;
388+
return (opt->detect_renames >= 0) ? opt->detect_renames : 1;
390389
}
391390

392391
static void init_tree_desc_from_tree(struct tree_desc *desc, struct tree *tree)
@@ -1883,9 +1882,7 @@ static struct diff_queue_struct *get_diffpairs(struct merge_options *opt,
18831882
*/
18841883
if (opts.detect_rename > DIFF_DETECT_RENAME)
18851884
opts.detect_rename = DIFF_DETECT_RENAME;
1886-
opts.rename_limit = opt->merge_rename_limit >= 0 ? opt->merge_rename_limit :
1887-
opt->diff_rename_limit >= 0 ? opt->diff_rename_limit :
1888-
1000;
1885+
opts.rename_limit = (opt->rename_limit >= 0) ? opt->rename_limit : 1000;
18891886
opts.rename_score = opt->rename_score;
18901887
opts.show_rename_progress = opt->show_rename_progress;
18911888
opts.output_format = DIFF_FORMAT_NO_OUTPUT;
@@ -3727,14 +3724,14 @@ static void merge_recursive_config(struct merge_options *opt)
37273724
{
37283725
char *value = NULL;
37293726
git_config_get_int("merge.verbosity", &opt->verbosity);
3730-
git_config_get_int("diff.renamelimit", &opt->diff_rename_limit);
3731-
git_config_get_int("merge.renamelimit", &opt->merge_rename_limit);
3727+
git_config_get_int("diff.renamelimit", &opt->rename_limit);
3728+
git_config_get_int("merge.renamelimit", &opt->rename_limit);
37323729
if (!git_config_get_string("diff.renames", &value)) {
3733-
opt->diff_detect_rename = git_config_rename("diff.renames", value);
3730+
opt->detect_renames = git_config_rename("diff.renames", value);
37343731
free(value);
37353732
}
37363733
if (!git_config_get_string("merge.renames", &value)) {
3737-
opt->merge_detect_rename = git_config_rename("merge.renames", value);
3734+
opt->detect_renames = git_config_rename("merge.renames", value);
37383735
free(value);
37393736
}
37403737
if (!git_config_get_string("merge.directoryrenames", &value)) {
@@ -3760,11 +3757,9 @@ void init_merge_options(struct merge_options *opt,
37603757
opt->repo = repo;
37613758
opt->verbosity = 2;
37623759
opt->buffer_output = 1;
3763-
opt->diff_rename_limit = -1;
3764-
opt->merge_rename_limit = -1;
3760+
opt->rename_limit = -1;
37653761
opt->renormalize = 0;
3766-
opt->diff_detect_rename = -1;
3767-
opt->merge_detect_rename = -1;
3762+
opt->detect_renames = -1;
37683763
opt->detect_directory_renames = MERGE_DIRECTORY_RENAMES_CONFLICT;
37693764
merge_recursive_config(opt);
37703765
merge_verbosity = getenv("GIT_MERGE_VERBOSITY");
@@ -3816,16 +3811,16 @@ int parse_merge_opt(struct merge_options *opt, const char *s)
38163811
else if (!strcmp(s, "no-renormalize"))
38173812
opt->renormalize = 0;
38183813
else if (!strcmp(s, "no-renames"))
3819-
opt->merge_detect_rename = 0;
3814+
opt->detect_renames = 0;
38203815
else if (!strcmp(s, "find-renames")) {
3821-
opt->merge_detect_rename = 1;
3816+
opt->detect_renames = 1;
38223817
opt->rename_score = 0;
38233818
}
38243819
else if (skip_prefix(s, "find-renames=", &arg) ||
38253820
skip_prefix(s, "rename-threshold=", &arg)) {
38263821
if ((opt->rename_score = parse_rename_score(&arg)) == -1 || *arg != 0)
38273822
return -1;
3828-
opt->merge_detect_rename = 1;
3823+
opt->detect_renames = 1;
38293824
}
38303825
/*
38313826
* Please update $__git_merge_strategy_options in

merge-recursive.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@ struct merge_options {
2727
MERGE_DIRECTORY_RENAMES_CONFLICT = 1,
2828
MERGE_DIRECTORY_RENAMES_TRUE = 2
2929
} detect_directory_renames;
30-
int diff_detect_rename;
31-
int merge_detect_rename;
32-
int diff_rename_limit;
33-
int merge_rename_limit;
30+
int detect_renames;
31+
int rename_limit;
3432
int rename_score;
3533
int needed_rename_limit;
3634
int show_rename_progress;

0 commit comments

Comments
 (0)