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
690bf41c
Commit
690bf41c
authored
Jun 10, 2013
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
keep source similarity in rename detection
parent
bda3fbb1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
17 deletions
+23
-17
src/diff_tform.c
+23
-17
No files found.
src/diff_tform.c
View file @
690bf41c
...
...
@@ -684,7 +684,7 @@ int git_diff_find_similar(
git_diff_find_options
opts
;
size_t
num_rewrites
=
0
,
num_updates
=
0
;
void
**
cache
;
/* cache of similarity metric file signatures */
diff_find_match
*
match
e
s
;
/* cache of best matches */
diff_find_match
*
match
_sources
,
*
match_target
s
;
/* cache of best matches */
if
((
error
=
normalize_find_opts
(
diff
,
&
opts
,
given_opts
))
<
0
)
return
error
;
...
...
@@ -697,16 +697,18 @@ int git_diff_find_similar(
cache
=
git__calloc
(
cache_size
,
sizeof
(
void
*
));
GITERR_CHECK_ALLOC
(
cache
);
matches
=
git__calloc
(
diff
->
deltas
.
length
,
sizeof
(
diff_find_match
));
GITERR_CHECK_ALLOC
(
matches
);
match_sources
=
git__calloc
(
diff
->
deltas
.
length
,
sizeof
(
diff_find_match
));
match_targets
=
git__calloc
(
diff
->
deltas
.
length
,
sizeof
(
diff_find_match
));
GITERR_CHECK_ALLOC
(
match_sources
);
GITERR_CHECK_ALLOC
(
match_targets
);
/* next find the most similar delta for each rename / copy candidate */
git_vector_foreach
(
&
diff
->
deltas
,
i
,
to
)
{
size_t
tried_sources
=
0
;
match
e
s
[
i
].
idx
=
i
;
match
e
s
[
i
].
similarity
=
0
;
match
_target
s
[
i
].
idx
=
i
;
match
_target
s
[
i
].
similarity
=
0
;
/* skip things that are not rename targets */
if
(
!
is_rename_target
(
diff
,
&
opts
,
i
,
cache
))
...
...
@@ -734,9 +736,12 @@ int git_diff_find_similar(
continue
;
}
if
(
matches
[
i
].
similarity
<
(
uint32_t
)
similarity
)
{
matches
[
i
].
similarity
=
(
uint32_t
)
similarity
;
matches
[
i
].
idx
=
j
;
if
(
match_targets
[
i
].
similarity
<
(
uint32_t
)
similarity
&&
match_sources
[
j
].
similarity
<
(
uint32_t
)
similarity
)
{
match_targets
[
i
].
similarity
=
(
uint32_t
)
similarity
;
match_sources
[
j
].
similarity
=
(
uint32_t
)
similarity
;
match_targets
[
i
].
idx
=
j
;
match_sources
[
j
].
idx
=
i
;
}
}
}
...
...
@@ -744,13 +749,13 @@ int git_diff_find_similar(
/* next rewrite the diffs with renames / copies */
git_vector_foreach
(
&
diff
->
deltas
,
i
,
to
)
{
/* check if this delta was matched to another one */
if
((
similarity
=
(
int
)
matches
[
i
].
similarity
)
<=
0
)
/* check if this delta was the target of a similarity */
if
((
similarity
=
(
int
)
match_targets
[
i
].
similarity
)
<=
0
)
continue
;
assert
(
to
&&
(
to
->
flags
&
GIT_DIFF_FLAG__IS_RENAME_TARGET
)
!=
0
);
from
=
GIT_VECTOR_GET
(
&
diff
->
deltas
,
match
e
s
[
i
].
idx
);
from
=
GIT_VECTOR_GET
(
&
diff
->
deltas
,
match
_target
s
[
i
].
idx
);
assert
(
from
&&
(
from
->
flags
&
GIT_DIFF_FLAG__IS_RENAME_SOURCE
)
!=
0
);
/* possible scenarios:
...
...
@@ -847,14 +852,14 @@ int git_diff_find_similar(
/* in the off chance that we've just swapped the new
* element into the correct place, clear the SPLIT flag
*/
if
(
match
es
[
matche
s
[
i
].
idx
].
idx
==
i
&&
match
es
[
matche
s
[
i
].
idx
].
similarity
>
if
(
match
_targets
[
match_target
s
[
i
].
idx
].
idx
==
i
&&
match
_targets
[
match_target
s
[
i
].
idx
].
similarity
>
opts
.
rename_from_rewrite_threshold
)
{
from
->
status
=
GIT_DELTA_RENAMED
;
from
->
similarity
=
(
uint32_t
)
match
es
[
matche
s
[
i
].
idx
].
similarity
;
match
es
[
matche
s
[
i
].
idx
].
similarity
=
0
;
(
uint32_t
)
match
_targets
[
match_target
s
[
i
].
idx
].
similarity
;
match
_targets
[
match_target
s
[
i
].
idx
].
similarity
=
0
;
from
->
flags
&=
~
GIT_DIFF_FLAG__TO_SPLIT
;
num_rewrites
--
;
}
...
...
@@ -882,7 +887,8 @@ int git_diff_find_similar(
FLAG_SET
(
&
opts
,
GIT_DIFF_BREAK_REWRITES
));
cleanup:
git__free
(
matches
);
git__free
(
match_sources
);
git__free
(
match_targets
);
for
(
i
=
0
;
i
<
cache_size
;
++
i
)
{
if
(
cache
[
i
]
!=
NULL
)
...
...
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