Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
ef848891
Commit
ef848891
authored
Dec 31, 2021
by
Miguel Arroz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add `rename_threshold` to `git_status_options`.
parent
50b4d53e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
0 deletions
+72
-0
include/git2/status.h
+6
-0
src/status.c
+3
-0
tests/status/renames.c
+63
-0
No files found.
include/git2/status.h
View file @
ef848891
...
...
@@ -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
...
...
src/status.c
View file @
ef848891
...
...
@@ -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
)
...
...
tests/status/renames.c
View file @
ef848891
...
...
@@ -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
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment