Add `rename_threshold` to `git_status_options`.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
diff --git a/include/git2/status.h b/include/git2/status.h
index 526df63..d8f9663 100644
--- a/include/git2/status.h
+++ b/include/git2/status.h
@@ -250,6 +250,12 @@ typedef struct {
* working directory and index; defaults to HEAD.
*/
git_tree *baseline;
+
+ /**
+ * Threshold above which similar files will be considered renames.
+ * This is equivalent to the -M option. Defaults to 50.
+ */
+ uint16_t rename_threshold;
} git_status_options;
#define GIT_STATUS_OPTIONS_VERSION 1
diff --git a/src/status.c b/src/status.c
index c985646..b321e0e 100644
--- a/src/status.c
+++ b/src/status.c
@@ -336,6 +336,9 @@ int git_status_list_new(
GIT_DIFF_FIND_RENAMES_FROM_REWRITES |
GIT_DIFF_BREAK_REWRITES_FOR_RENAMES_ONLY;
+ if (opts != NULL && opts->rename_threshold != 0)
+ findopt.rename_threshold = opts->rename_threshold;
+
if (show != GIT_STATUS_SHOW_WORKDIR_ONLY) {
if ((error = git_diff_tree_to_index(
&status->head2idx, repo, head, index, &diffopt)) < 0)
diff --git a/tests/status/renames.c b/tests/status/renames.c
index e69dbcc..d17a94c 100644
--- a/tests/status/renames.c
+++ b/tests/status/renames.c
@@ -718,3 +718,66 @@ void test_status_renames__precomposed_unicode_toggle_is_rename(void)
#endif
}
+void test_status_renames__rename_threshold(void)
+{
+ git_index *index;
+ git_status_list *statuslist;
+ git_status_options opts = GIT_STATUS_OPTIONS_INIT;
+
+ _rename_helper(g_repo, "ikeepsix.txt", "newname.txt",
+ "Line 1\n" \
+ "Line 2\n" \
+ "Line 3\n" \
+ "Line 4\n" \
+ "Line 5\n" \
+ "Line 6\n" \
+ "Line 7\n" \
+ "Line 8\n" \
+ "Line 9\n"
+ );
+
+ opts.flags |= GIT_STATUS_OPT_RENAMES_INDEX_TO_WORKDIR;
+ opts.flags |= GIT_STATUS_OPT_INCLUDE_UNTRACKED;
+
+ cl_git_pass(git_repository_index(&index, g_repo));
+
+ // Default threshold
+ {
+ struct status_entry expected[] = {
+ { GIT_STATUS_WT_RENAMED | GIT_STATUS_WT_MODIFIED, "ikeepsix.txt", "newname.txt" },
+ };
+
+ cl_git_pass(git_status_list_new(&statuslist, g_repo, &opts));
+ check_status(statuslist, expected, 1);
+ git_status_list_free(statuslist);
+ }
+
+ // Threshold set to 90
+ {
+ struct status_entry expected[] = {
+ { GIT_STATUS_WT_DELETED, "ikeepsix.txt", NULL },
+ { GIT_STATUS_WT_NEW, "newname.txt", NULL }
+ };
+
+ opts.rename_threshold = 90;
+
+ cl_git_pass(git_status_list_new(&statuslist, g_repo, &opts));
+ check_status(statuslist, expected, 2);
+ git_status_list_free(statuslist);
+ }
+
+ // Threshold set to 25
+ {
+ struct status_entry expected[] = {
+ { GIT_STATUS_WT_RENAMED | GIT_STATUS_WT_MODIFIED, "ikeepsix.txt", "newname.txt" },
+ };
+
+ opts.rename_threshold = 25;
+
+ cl_git_pass(git_status_list_new(&statuslist, g_repo, &opts));
+ check_status(statuslist, expected, 1);
+ git_status_list_free(statuslist);
+ }
+
+ git_index_free(index);
+}