On Mon, Apr 23, 2018 at 09:15:09AM -0400, Ben Peart wrote: > In commit 2a2ac926547 when merge.renamelimit was added, it was decided to > have separate settings for merge and diff to give users the ability to > control that behavior. In this particular case, it will default to the > value of diff.renamelimit when it isn't set. That isn't consistent with the > other merge settings. However, it seems like a desirable way to do it. Maybe let me throw in some code for discussion (test and documentation is missing, mainly to form an idea what the change in options should be). I admit the patch below is concerned only with diff.renames, but whatever we come up with for merge should be reflected there, too, doesn't it? Greetings, Eckhard -- >8 -- >From e8a88111f2aaf338a4c19e83251c7178f7152129 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eckhard=20S=2E=20Maa=C3=9F?= <eckhard.s.maass@xxxxxxxxx> Date: Sun, 22 Apr 2018 23:29:08 +0200 Subject: [PATCH] diff: enhance diff.renames to be able to set rename score MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Eckhard S. Maaß <eckhard.s.maass@xxxxxxxxx> --- diff.c | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/diff.c b/diff.c index 1289df4b1f..a3cedad5cf 100644 --- a/diff.c +++ b/diff.c @@ -30,6 +30,7 @@ #endif static int diff_detect_rename_default; +static int diff_rename_score_default; static int diff_indent_heuristic = 1; static int diff_rename_limit_default = 400; static int diff_suppress_blank_empty; @@ -177,13 +178,33 @@ static int parse_submodule_params(struct diff_options *options, const char *valu return 0; } +int parse_rename_score(const char **cp_p); + +static int git_config_rename_score(const char *value) +{ + int parsed_rename_score = parse_rename_score(&value); + if (parsed_rename_score == -1) + return error("invalid argument to diff.renamescore: %s", value); + diff_rename_score_default = parsed_rename_score; + return 0; +} + static int git_config_rename(const char *var, const char *value) { - if (!value) - return DIFF_DETECT_RENAME; - if (!strcasecmp(value, "copies") || !strcasecmp(value, "copy")) - return DIFF_DETECT_COPY; - return git_config_bool(var,value) ? DIFF_DETECT_RENAME : 0; + if (!value) { + diff_detect_rename_default = DIFF_DETECT_RENAME; + return 0; + } + if (skip_to_optional_arg(value, "copies", &value) || skip_to_optional_arg(value, "copy", &value)) { + diff_detect_rename_default = DIFF_DETECT_COPY; + return git_config_rename_score(value); + } + if (skip_to_optional_arg(value, "renames", &value) || skip_to_optional_arg(value, "rename", &value)) { + diff_detect_rename_default = DIFF_DETECT_RENAME; + return git_config_rename_score(value); + } + diff_detect_rename_default = git_config_bool(var,value) ? DIFF_DETECT_RENAME : 0; + return 0; } long parse_algorithm_value(const char *value) @@ -307,8 +328,7 @@ int git_diff_ui_config(const char *var, const char *value, void *cb) return 0; } if (!strcmp(var, "diff.renames")) { - diff_detect_rename_default = git_config_rename(var, value); - return 0; + return git_config_rename(var, value); } if (!strcmp(var, "diff.autorefreshindex")) { diff_auto_refresh_index = git_config_bool(var, value); @@ -4116,6 +4136,7 @@ void diff_setup(struct diff_options *options) options->add_remove = diff_addremove; options->use_color = diff_use_color_default; options->detect_rename = diff_detect_rename_default; + options->rename_score = diff_rename_score_default; options->xdl_opts |= diff_algorithm; if (diff_indent_heuristic) DIFF_XDL_SET(options, INDENT_HEURISTIC); -- 2.17.0.252.gfe0a9eaf31