mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-06 11:19:47 +00:00
Minor improvements to find_similar code
This moves a couple of checks outside of the inner loop of the find_similar rename/copy detection phase that are only dependent on the "from" side of a detection. Also, this replaces the inefficient initialization of the options structure when a value is not provided explicitly by the user.
This commit is contained in:
parent
f827589067
commit
0a0089131f
@ -210,7 +210,6 @@ static int normalize_find_opts(
|
|||||||
git_diff_find_options *given)
|
git_diff_find_options *given)
|
||||||
{
|
{
|
||||||
git_config *cfg = NULL;
|
git_config *cfg = NULL;
|
||||||
const char *val;
|
|
||||||
|
|
||||||
if (diff->repo != NULL &&
|
if (diff->repo != NULL &&
|
||||||
git_repository_config__weakptr(&cfg, diff->repo) < 0)
|
git_repository_config__weakptr(&cfg, diff->repo) < 0)
|
||||||
@ -219,8 +218,9 @@ static int normalize_find_opts(
|
|||||||
if (given != NULL)
|
if (given != NULL)
|
||||||
memcpy(opts, given, sizeof(*opts));
|
memcpy(opts, given, sizeof(*opts));
|
||||||
else {
|
else {
|
||||||
git_diff_find_options init = GIT_DIFF_FIND_OPTIONS_INIT;
|
const char *val = NULL;
|
||||||
memmove(opts, &init, sizeof(init));
|
|
||||||
|
GIT_INIT_STRUCTURE(opts, GIT_DIFF_FIND_OPTIONS_VERSION);
|
||||||
|
|
||||||
opts->flags = GIT_DIFF_FIND_RENAMES;
|
opts->flags = GIT_DIFF_FIND_RENAMES;
|
||||||
|
|
||||||
@ -486,6 +486,17 @@ int git_diff_find_similar(
|
|||||||
GIT_MODE_TYPE(GIT_FILEMODE_BLOB))
|
GIT_MODE_TYPE(GIT_FILEMODE_BLOB))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
/* don't check UNMODIFIED files as source unless given option */
|
||||||
|
if (from->status == GIT_DELTA_UNMODIFIED &&
|
||||||
|
!FLAG_SET(opts, GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* skip all but DELETED files unless copy detection is on */
|
||||||
|
if (!FLAG_SET(opts, GIT_DIFF_FIND_COPIES) &&
|
||||||
|
from->status != GIT_DELTA_DELETED &&
|
||||||
|
(from->flags & GIT_DIFF_FLAG__TO_SPLIT) == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
git_vector_foreach(&diff->deltas, j, to) {
|
git_vector_foreach(&diff->deltas, j, to) {
|
||||||
if (i == j)
|
if (i == j)
|
||||||
continue;
|
continue;
|
||||||
@ -510,18 +521,7 @@ int git_diff_find_similar(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* skip all but DELETED files unless copy detection is on */
|
/* cap on maximum files we'll examine (per "from" file) */
|
||||||
if (!FLAG_SET(opts, GIT_DIFF_FIND_COPIES) &&
|
|
||||||
from->status != GIT_DELTA_DELETED &&
|
|
||||||
(from->flags & GIT_DIFF_FLAG__TO_SPLIT) == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
/* don't check UNMODIFIED files as source unless given option */
|
|
||||||
if (from->status == GIT_DELTA_UNMODIFIED &&
|
|
||||||
!FLAG_SET(opts, GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
/* cap on maximum files we'll examine */
|
|
||||||
if (++tried_targets > opts.target_limit)
|
if (++tried_targets > opts.target_limit)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user