From: Ben Peart <Ben.Peart@microsoft.com>
To: "git@vger.kernel.org" <git@vger.kernel.org>
Cc: Ben Peart <Ben.Peart@microsoft.com>,
"newren@gmail.com" <newren@gmail.com>,
"peff@peff.net" <peff@peff.net>,
"gitster@pobox.com" <gitster@pobox.com>,
"pclouds@gmail.com" <pclouds@gmail.com>,
"vmiklos@frugalware.org" <vmiklos@frugalware.org>,
Kevin Willford <kewillf@microsoft.com>,
"Johannes.Schindelin@gmx.de" <Johannes.Schindelin@gmx.de>,
"eckhard.s.maass@googlemail.com" <eckhard.s.maass@googlemail.com>
Subject: [PATCH v3 2/3] merge: Add merge.renames config setting
Date: Thu, 26 Apr 2018 20:52:21 +0000 [thread overview]
Message-ID: <20180426205202.23056-3-benpeart@microsoft.com> (raw)
In-Reply-To: <20180426205202.23056-1-benpeart@microsoft.com>
Add the ability to control rename detection for merge via a config setting.
This setting behaves the same and defaults to the value of diff.renames but only
applies to merge.
Reviewed-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Ben Peart <benpeart@microsoft.com>
---
Documentation/merge-config.txt | 6 ++++++
Documentation/merge-strategies.txt | 6 ++++--
diff.c | 2 +-
diff.h | 2 ++
merge-recursive.c | 23 +++++++++++++++++------
merge-recursive.h | 8 +++++++-
t/t3034-merge-recursive-rename-options.sh | 18 ++++++++++++++++++
7 files changed, 55 insertions(+), 10 deletions(-)
diff --git a/Documentation/merge-config.txt b/Documentation/merge-config.txt
index 48ee3bce77..59848e5634 100644
--- a/Documentation/merge-config.txt
+++ b/Documentation/merge-config.txt
@@ -38,6 +38,12 @@ merge.renameLimit::
diff.renameLimit. This setting has no effect if rename detection
is turned off.
+merge.renames::
+ Whether and how Git detects renames. If set to "false",
+ rename detection is disabled. If set to "true", basic rename
+ detection is enabled. If set to "copies" or "copy", Git will
+ detect copies, as well. Defaults to the value of diff.renames.
+
merge.renormalize::
Tell Git that canonical representation of files in the
repository has changed over time (e.g. earlier commits record
diff --git a/Documentation/merge-strategies.txt b/Documentation/merge-strategies.txt
index 4a58aad4b8..1e0728aa12 100644
--- a/Documentation/merge-strategies.txt
+++ b/Documentation/merge-strategies.txt
@@ -84,12 +84,14 @@ no-renormalize;;
`merge.renormalize` configuration variable.
no-renames;;
- Turn off rename detection.
+ Turn off rename detection. This overrides the `merge.renames`
+ configuration variable.
See also linkgit:git-diff[1] `--no-renames`.
find-renames[=<n>];;
Turn on rename detection, optionally setting the similarity
- threshold. This is the default.
+ threshold. This is the default. This overrides the
+ 'merge.renames' configuration variable.
See also linkgit:git-diff[1] `--find-renames`.
rename-threshold=<n>;;
diff --git a/diff.c b/diff.c
index 1289df4b1f..5dfc24aa6d 100644
--- a/diff.c
+++ b/diff.c
@@ -177,7 +177,7 @@ static int parse_submodule_params(struct diff_options *options, const char *valu
return 0;
}
-static int git_config_rename(const char *var, const char *value)
+int git_config_rename(const char *var, const char *value)
{
if (!value)
return DIFF_DETECT_RENAME;
diff --git a/diff.h b/diff.h
index d29560f822..806faee2b3 100644
--- a/diff.h
+++ b/diff.h
@@ -324,6 +324,8 @@ extern int git_diff_ui_config(const char *var, const char *value, void *cb);
extern void diff_setup(struct diff_options *);
extern int diff_opt_parse(struct diff_options *, const char **, int, const char *);
extern void diff_setup_done(struct diff_options *);
+extern int git_config_rename(const char *var, const char *value);
+
#define DIFF_DETECT_RENAME 1
#define DIFF_DETECT_COPY 2
diff --git a/merge-recursive.c b/merge-recursive.c
index 0c0d48624d..2637d34d87 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -555,13 +555,13 @@ static struct string_list *get_renames(struct merge_options *o,
struct diff_options opts;
renames = xcalloc(1, sizeof(struct string_list));
- if (!o->detect_rename)
+ if (!merge_detect_rename(o))
return renames;
diff_setup(&opts);
opts.flags.recursive = 1;
opts.flags.rename_empty = 0;
- opts.detect_rename = DIFF_DETECT_RENAME;
+ opts.detect_rename = merge_detect_rename(o);
opts.rename_limit = o->merge_rename_limit >= 0 ? o->merge_rename_limit :
o->diff_rename_limit >= 0 ? o->diff_rename_limit :
1000;
@@ -2232,9 +2232,18 @@ int merge_recursive_generic(struct merge_options *o,
static void merge_recursive_config(struct merge_options *o)
{
+ char *value = NULL;
git_config_get_int("merge.verbosity", &o->verbosity);
git_config_get_int("diff.renamelimit", &o->diff_rename_limit);
git_config_get_int("merge.renamelimit", &o->merge_rename_limit);
+ if (!git_config_get_string("diff.renames", &value)) {
+ o->diff_detect_rename = git_config_rename("diff.renames", value);
+ free(value);
+ }
+ if (!git_config_get_string("merge.renames", &value)) {
+ o->merge_detect_rename = git_config_rename("merge.renames", value);
+ free(value);
+ }
git_config(git_xmerge_config, NULL);
}
@@ -2244,10 +2253,11 @@ void init_merge_options(struct merge_options *o)
memset(o, 0, sizeof(struct merge_options));
o->verbosity = 2;
o->buffer_output = 1;
+ o->diff_detect_rename = -1;
+ o->merge_detect_rename = -1;
o->diff_rename_limit = -1;
o->merge_rename_limit = -1;
o->renormalize = 0;
- o->detect_rename = 1;
merge_recursive_config(o);
merge_verbosity = getenv("GIT_MERGE_VERBOSITY");
if (merge_verbosity)
@@ -2298,18 +2308,19 @@ int parse_merge_opt(struct merge_options *o, const char *s)
else if (!strcmp(s, "no-renormalize"))
o->renormalize = 0;
else if (!strcmp(s, "no-renames"))
- o->detect_rename = 0;
+ o->merge_detect_rename = 0;
else if (!strcmp(s, "find-renames")) {
- o->detect_rename = 1;
+ o->merge_detect_rename = 1;
o->rename_score = 0;
}
else if (skip_prefix(s, "find-renames=", &arg) ||
skip_prefix(s, "rename-threshold=", &arg)) {
if ((o->rename_score = parse_rename_score(&arg)) == -1 || *arg != 0)
return -1;
- o->detect_rename = 1;
+ o->merge_detect_rename = 1;
}
else
return -1;
+
return 0;
}
diff --git a/merge-recursive.h b/merge-recursive.h
index 80d69d1401..0c5f7eff98 100644
--- a/merge-recursive.h
+++ b/merge-recursive.h
@@ -17,7 +17,8 @@ struct merge_options {
unsigned renormalize : 1;
long xdl_opts;
int verbosity;
- int detect_rename;
+ int diff_detect_rename;
+ int merge_detect_rename;
int diff_rename_limit;
int merge_rename_limit;
int rename_score;
@@ -28,6 +29,11 @@ struct merge_options {
struct hashmap current_file_dir_set;
struct string_list df_conflict_file_set;
};
+inline int merge_detect_rename(struct merge_options *o)
+{
+ return o->merge_detect_rename >= 0 ? o->merge_detect_rename :
+ o->diff_detect_rename >= 0 ? o->diff_detect_rename : 1;
+}
/* merge_trees() but with recursive ancestor consolidation */
int merge_recursive(struct merge_options *o,
diff --git a/t/t3034-merge-recursive-rename-options.sh b/t/t3034-merge-recursive-rename-options.sh
index b9c4028496..3d9fae68c4 100755
--- a/t/t3034-merge-recursive-rename-options.sh
+++ b/t/t3034-merge-recursive-rename-options.sh
@@ -309,4 +309,22 @@ test_expect_success 'last wins in --find-renames=<m> --rename-threshold=<n>' '
check_threshold_0
'
+test_expect_success 'merge.renames disables rename detection' '
+ git read-tree --reset -u HEAD &&
+ git -c merge.renames=false merge-recursive $tail &&
+ check_no_renames
+'
+
+test_expect_success 'merge.renames defaults to diff.renames' '
+ git read-tree --reset -u HEAD &&
+ git -c diff.renames=false merge-recursive $tail &&
+ check_no_renames
+'
+
+test_expect_success 'merge.renames overrides diff.renames' '
+ git read-tree --reset -u HEAD &&
+ test_must_fail git -c diff.renames=false -c merge.renames=true merge-recursive $tail &&
+ $check_50
+'
+
test_done
--
2.17.0.windows.1
next prev parent reply other threads:[~2018-04-26 20:52 UTC|newest]
Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-20 13:36 [PATCH v1 0/2] add additional config settings for merge Ben Peart
2018-04-20 13:36 ` [PATCH v1 1/2] merge: Add merge.renames config setting Ben Peart
2018-04-20 17:02 ` Elijah Newren
2018-04-20 17:26 ` Elijah Newren
2018-04-23 12:57 ` Ben Peart
2018-04-20 17:59 ` Ben Peart
2018-04-20 18:34 ` Elijah Newren
2018-04-21 4:23 ` Junio C Hamano
2018-04-23 16:00 ` Ben Peart
2018-04-23 23:23 ` Junio C Hamano
2018-04-24 11:58 ` Johannes Schindelin
2018-04-24 17:47 ` Elijah Newren
2018-04-25 8:20 ` Johannes Schindelin
2018-04-22 12:07 ` Eckhard Maaß
2018-04-23 13:15 ` Ben Peart
2018-04-23 21:32 ` Eckhard Maaß
2018-04-24 16:53 ` Ben Peart
2018-04-23 13:22 ` Ben Peart
2018-04-20 13:36 ` [PATCH v1 2/2] merge: Add merge.aggressive " Ben Peart
2018-04-20 17:22 ` Elijah Newren
2018-04-24 16:45 ` Ben Peart
2018-04-24 17:36 ` Elijah Newren
2018-04-24 23:57 ` Junio C Hamano
2018-04-25 14:47 ` Ben Peart
2018-04-20 17:34 ` [PATCH v1 0/2] add additional config settings for merge Elijah Newren
2018-04-20 18:19 ` Ben Peart
2018-04-24 17:11 ` [PATCH v2 " Ben Peart
2018-04-24 17:11 ` [PATCH v2 1/2] merge: Add merge.renames config setting Ben Peart
2018-04-24 18:11 ` Elijah Newren
2018-04-24 18:59 ` Elijah Newren
2018-04-24 20:31 ` Ben Peart
2018-04-25 16:01 ` Elijah Newren
2018-04-24 17:11 ` [PATCH v2 2/2] merge: Add merge.aggressive " Ben Peart
2018-04-25 0:13 ` [PATCH v2 0/2] add additional config settings for merge Junio C Hamano
2018-04-25 15:22 ` Ben Peart
2018-04-26 1:48 ` Junio C Hamano
2018-04-26 20:52 ` [PATCH v3 0/3] add merge.renames config setting Ben Peart
2018-04-26 20:52 ` [PATCH v3 1/3] merge: update documentation for {merge,diff}.renameLimit Ben Peart
2018-04-26 23:11 ` Elijah Newren
2018-04-26 23:23 ` Jonathan Tan
2018-04-26 20:52 ` Ben Peart [this message]
2018-04-26 22:52 ` [PATCH v3 2/3] merge: Add merge.renames config setting Elijah Newren
2018-04-27 0:54 ` Ben Peart
2018-04-27 2:23 ` Junio C Hamano
2018-04-27 3:28 ` Elijah Newren
2018-04-27 7:23 ` Johannes Schindelin
2018-04-27 14:32 ` Elijah Newren
2018-04-27 18:37 ` Eckhard Maaß
2018-04-27 20:23 ` Elijah Newren
2018-04-30 8:03 ` Eckhard Maaß
2018-04-30 16:54 ` Elijah Newren
2018-04-27 4:17 ` Elijah Newren
2018-04-27 18:19 ` Elijah Newren
2018-04-30 13:11 ` Ben Peart
2018-04-30 16:12 ` Re: Elijah Newren
2018-05-02 14:33 ` Re: Ben Peart
2018-04-26 20:52 ` [PATCH v3 3/3] merge: pass aggressive when rename detection is turned off Ben Peart
2018-04-26 23:00 ` Elijah Newren
2018-04-26 22:08 ` [PATCH v3 0/3] add merge.renames config setting Elijah Newren
2018-05-02 16:01 ` [PATCH v4 0/3] add additional config settings for merge Ben Peart
2018-05-02 16:01 ` [PATCH v4 1/3] merge: update documentation for {merge,diff}.renameLimit Ben Peart
2018-05-02 16:01 ` [PATCH v4 2/3] merge: Add merge.renames config setting Ben Peart
2018-05-04 3:07 ` Junio C Hamano
2018-05-02 16:01 ` [PATCH v4 3/3] merge: pass aggressive when rename detection is turned off Ben Peart
2018-05-02 17:20 ` [PATCH v4 0/3] add additional config settings for merge Elijah Newren
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180426205202.23056-3-benpeart@microsoft.com \
--to=ben.peart@microsoft.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=eckhard.s.maass@googlemail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=kewillf@microsoft.com \
--cc=newren@gmail.com \
--cc=pclouds@gmail.com \
--cc=peff@peff.net \
--cc=vmiklos@frugalware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).