Commit 2854e61956871f7b26ee38040e70f6db92796c1a

Carlos Martín Nieto 2017-01-14T17:12:23

Merge pull request #4061 from libgit2/ethomson/merge_opts merge: set default rename threshold

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3a8db06..6137efd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,10 @@ v0.25 + 1
 
 ### Changes or improvements
 
+* `GIT_MERGE_OPTIONS_INIT` now includes a setting to perform rename detection.
+  This aligns this structure with the default by `git_merge` and
+  `git_merge_trees` when `NULL` was provided for the options.
+
 ### API additions
 
 ### API removals
diff --git a/include/git2/merge.h b/include/git2/merge.h
index c6f6cba..94ac8b5 100644
--- a/include/git2/merge.h
+++ b/include/git2/merge.h
@@ -290,7 +290,8 @@ typedef struct {
 } git_merge_options;
 
 #define GIT_MERGE_OPTIONS_VERSION 1
-#define GIT_MERGE_OPTIONS_INIT {GIT_MERGE_OPTIONS_VERSION}
+#define GIT_MERGE_OPTIONS_INIT { \
+	GIT_MERGE_OPTIONS_VERSION, GIT_MERGE_FIND_RENAMES }
 
 /**
  * Initializes a `git_merge_options` with default values. Equivalent to
diff --git a/src/merge.c b/src/merge.c
index 4d812da..087178a 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -1713,15 +1713,15 @@ static int merge_normalize_opts(
 	if ((error = git_repository_config__weakptr(&cfg, repo)) < 0)
 		return error;
 
-	if (given != NULL)
+	if (given != NULL) {
 		memcpy(opts, given, sizeof(git_merge_options));
-	else {
+	} else {
 		git_merge_options init = GIT_MERGE_OPTIONS_INIT;
 		memcpy(opts, &init, sizeof(init));
+	}
 
-		opts->flags = GIT_MERGE_FIND_RENAMES;
+	if ((opts->flags & GIT_MERGE_FIND_RENAMES) && !opts->rename_threshold)
 		opts->rename_threshold = GIT_MERGE_DEFAULT_RENAME_THRESHOLD;
-	}
 
 	if (given && given->default_driver) {
 		opts->default_driver = git__strdup(given->default_driver);
diff --git a/tests/merge/trees/renames.c b/tests/merge/trees/renames.c
index d7721c8..6f5c36b 100644
--- a/tests/merge/trees/renames.c
+++ b/tests/merge/trees/renames.c
@@ -242,6 +242,8 @@ void test_merge_trees_renames__no_rename_index(void)
 		{ 0100644, "b69fe837e4cecfd4c9a40cdca7c138468687df07", 3, "7-both-renamed.txt" },
 	};
 
+	opts.flags &= ~GIT_MERGE_FIND_RENAMES;
+
 	cl_git_pass(merge_trees_from_branches(&index, repo,
 		BRANCH_RENAME_OURS, BRANCH_RENAME_THEIRS,
 		&opts));