summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVicent Martí <vicent@github.com>2013-06-12 14:54:32 -0700
committerVicent Martí <vicent@github.com>2013-06-12 14:54:32 -0700
commit88c401bec80f795775b50f5b1f1421cf1e6385a3 (patch)
tree6a8dd95414229477fadcf0a1e7cfc4af7e869c30 /src
parent93da7af707f7d6e9c466a319a7fa437883da7793 (diff)
parent690bf41ce5f700de787b019ed489cbdbd7f2b697 (diff)
downloadlibgit2-88c401bec80f795775b50f5b1f1421cf1e6385a3.tar.gz
Merge pull request #1643 from ethomson/rename_source
Keep data about source of similarity
Diffstat (limited to 'src')
-rw-r--r--src/diff_tform.c40
1 files changed, 23 insertions, 17 deletions
diff --git a/src/diff_tform.c b/src/diff_tform.c
index 597c240ae..53a7e63ff 100644
--- a/src/diff_tform.c
+++ b/src/diff_tform.c
@@ -688,7 +688,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 *matches; /* cache of best matches */
+ diff_find_match *match_sources, *match_targets; /* cache of best matches */
if ((error = normalize_find_opts(diff, &opts, given_opts)) < 0)
return error;
@@ -701,16 +701,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;
- matches[i].idx = i;
- matches[i].similarity = 0;
+ match_targets[i].idx = i;
+ match_targets[i].similarity = 0;
/* skip things that are not rename targets */
if (!is_rename_target(diff, &opts, i, cache))
@@ -738,9 +740,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;
}
}
}
@@ -748,13 +753,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, matches[i].idx);
+ from = GIT_VECTOR_GET(&diff->deltas, match_targets[i].idx);
assert(from && (from->flags & GIT_DIFF_FLAG__IS_RENAME_SOURCE) != 0);
/* possible scenarios:
@@ -851,14 +856,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 (matches[matches[i].idx].idx == i &&
- matches[matches[i].idx].similarity >
+ if (match_targets[match_targets[i].idx].idx == i &&
+ match_targets[match_targets[i].idx].similarity >
opts.rename_from_rewrite_threshold) {
from->status = GIT_DELTA_RENAMED;
from->similarity =
- (uint32_t)matches[matches[i].idx].similarity;
- matches[matches[i].idx].similarity = 0;
+ (uint32_t)match_targets[match_targets[i].idx].similarity;
+ match_targets[match_targets[i].idx].similarity = 0;
from->flags &= ~GIT_DIFF_FLAG__TO_SPLIT;
num_rewrites--;
}
@@ -886,7 +891,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)