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
ca901e7b
Commit
ca901e7b
authored
Nov 29, 2012
by
Ben Straub
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Deploy GIT_DIFF_FIND_OPTIONS_INIT
parent
2f8d30be
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
3 deletions
+50
-3
src/diff_tform.c
+17
-1
tests-clar/diff/rename.c
+33
-2
No files found.
src/diff_tform.c
View file @
ca901e7b
...
@@ -168,6 +168,18 @@ int git_diff_merge(
...
@@ -168,6 +168,18 @@ int git_diff_merge(
return
error
;
return
error
;
}
}
static
bool
find_opts_has_valid_version
(
const
git_diff_find_options
*
opts
)
{
if
(
!
opts
)
return
true
;
if
(
opts
->
version
>
0
&&
opts
->
version
<=
GIT_DIFF_FIND_OPTIONS_VERSION
)
return
true
;
giterr_set
(
GITERR_INVALID
,
"Invalid version %d on git_diff_find_options"
,
opts
->
version
);
return
false
;
}
#define DEFAULT_THRESHOLD 50
#define DEFAULT_THRESHOLD 50
#define DEFAULT_BREAK_REWRITE_THRESHOLD 60
#define DEFAULT_BREAK_REWRITE_THRESHOLD 60
#define DEFAULT_TARGET_LIMIT 200
#define DEFAULT_TARGET_LIMIT 200
...
@@ -187,7 +199,8 @@ static int normalize_find_opts(
...
@@ -187,7 +199,8 @@ static int normalize_find_opts(
if
(
given
!=
NULL
)
if
(
given
!=
NULL
)
memcpy
(
opts
,
given
,
sizeof
(
*
opts
));
memcpy
(
opts
,
given
,
sizeof
(
*
opts
));
else
{
else
{
memset
(
opts
,
0
,
sizeof
(
*
opts
));
git_diff_find_options
init
=
GIT_DIFF_FIND_OPTIONS_INIT
;
memmove
(
opts
,
&
init
,
sizeof
(
init
));
opts
->
flags
=
GIT_DIFF_FIND_RENAMES
;
opts
->
flags
=
GIT_DIFF_FIND_RENAMES
;
...
@@ -198,6 +211,9 @@ static int normalize_find_opts(
...
@@ -198,6 +211,9 @@ static int normalize_find_opts(
opts
->
flags
=
GIT_DIFF_FIND_RENAMES
|
GIT_DIFF_FIND_COPIES
;
opts
->
flags
=
GIT_DIFF_FIND_RENAMES
|
GIT_DIFF_FIND_COPIES
;
}
}
if
(
!
find_opts_has_valid_version
(
opts
))
return
-
1
;
/* some flags imply others */
/* some flags imply others */
if
(
opts
->
flags
&
GIT_DIFF_FIND_RENAMES_FROM_REWRITES
)
if
(
opts
->
flags
&
GIT_DIFF_FIND_RENAMES_FROM_REWRITES
)
...
...
tests-clar/diff/rename.c
View file @
ca901e7b
...
@@ -34,7 +34,7 @@ void test_diff_rename__match_oid(void)
...
@@ -34,7 +34,7 @@ void test_diff_rename__match_oid(void)
git_tree
*
old_tree
,
*
new_tree
;
git_tree
*
old_tree
,
*
new_tree
;
git_diff_list
*
diff
;
git_diff_list
*
diff
;
git_diff_options
diffopts
=
GIT_DIFF_OPTIONS_INIT
;
git_diff_options
diffopts
=
GIT_DIFF_OPTIONS_INIT
;
git_diff_find_options
opts
;
git_diff_find_options
opts
=
GIT_DIFF_FIND_OPTIONS_INIT
;
diff_expects
exp
;
diff_expects
exp
;
old_tree
=
resolve_commit_oid_to_tree
(
g_repo
,
old_sha
);
old_tree
=
resolve_commit_oid_to_tree
(
g_repo
,
old_sha
);
...
@@ -84,7 +84,6 @@ void test_diff_rename__match_oid(void)
...
@@ -84,7 +84,6 @@ void test_diff_rename__match_oid(void)
* 31e47d8c1fa36d7f8d537b96158e3f024de0a9f2 \
* 31e47d8c1fa36d7f8d537b96158e3f024de0a9f2 \
* 2bc7f351d20b53f1c72c16c4b036e491c478c49a
* 2bc7f351d20b53f1c72c16c4b036e491c478c49a
*/
*/
memset
(
&
opts
,
0
,
sizeof
(
opts
));
opts
.
flags
=
GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED
;
opts
.
flags
=
GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED
;
cl_git_pass
(
git_diff_find_similar
(
diff
,
&
opts
));
cl_git_pass
(
git_diff_find_similar
(
diff
,
&
opts
));
...
@@ -102,3 +101,35 @@ void test_diff_rename__match_oid(void)
...
@@ -102,3 +101,35 @@ void test_diff_rename__match_oid(void)
git_tree_free
(
old_tree
);
git_tree_free
(
old_tree
);
git_tree_free
(
new_tree
);
git_tree_free
(
new_tree
);
}
}
void
test_diff_rename__checks_options_version
(
void
)
{
const
char
*
old_sha
=
"31e47d8c1fa36d7f8d537b96158e3f024de0a9f2"
;
const
char
*
new_sha
=
"2bc7f351d20b53f1c72c16c4b036e491c478c49a"
;
git_tree
*
old_tree
,
*
new_tree
;
git_diff_list
*
diff
;
git_diff_options
diffopts
=
GIT_DIFF_OPTIONS_INIT
;
git_diff_find_options
opts
=
GIT_DIFF_FIND_OPTIONS_INIT
;
const
git_error
*
err
;
old_tree
=
resolve_commit_oid_to_tree
(
g_repo
,
old_sha
);
new_tree
=
resolve_commit_oid_to_tree
(
g_repo
,
new_sha
);
diffopts
.
flags
|=
GIT_DIFF_INCLUDE_UNMODIFIED
;
cl_git_pass
(
git_diff_tree_to_tree
(
&
diff
,
g_repo
,
old_tree
,
new_tree
,
&
diffopts
));
opts
.
version
=
0
;
cl_git_fail
(
git_diff_find_similar
(
diff
,
&
opts
));
err
=
giterr_last
();
cl_assert_equal_i
(
GITERR_INVALID
,
err
->
klass
);
giterr_clear
();
opts
.
version
=
1024
;
cl_git_fail
(
git_diff_find_similar
(
diff
,
&
opts
));
err
=
giterr_last
();
cl_assert_equal_i
(
GITERR_INVALID
,
err
->
klass
);
git_diff_list_free
(
diff
);
git_tree_free
(
old_tree
);
git_tree_free
(
new_tree
);
}
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