diffcore-rename.c | 12 +++++++++--- 1 files changed, 9 insertions(+), 3 deletions(-) diff --git a/diffcore-rename.c b/diffcore-rename.c index df41be5..daa85e4 100644 --- a/diffcore-rename.c +++ b/diffcore-rename.c @@ -170,7 +170,7 @@ static int estimate_similarity(struct diff_filespec *src, * and the final score computation below would not have a * divide-by-zero issue. */ - if (base_size * (MAX_SCORE-minimum_score) < delta_size * MAX_SCORE) + if (max_size * (MAX_SCORE-minimum_score) < delta_size * MAX_SCORE) return 0; if (!src->cnt_data && diff_populate_filespec(src, 0)) @@ -246,6 +246,8 @@ struct file_similarity { struct file_similarity *next; }; +static int find_copies_too; + static int find_identical_files(struct file_similarity *src, struct file_similarity *dst) { @@ -277,6 +279,8 @@ static int find_identical_files(struct file_similarity *src, } /* Give higher scores to sources that haven't been used already */ score = !source->rename_used; + if (source->rename_used && !find_copies_too) + continue; score += basename_same(source, target); if (score > best_score) { best = p; @@ -377,11 +381,12 @@ static void insert_file_table(struct hash_table *table, int src_dst, int index, * and then during the second round we try to match * cache-dirty entries as well. */ -static int find_exact_renames(void) +static int find_exact_renames(int copies) { int i; struct hash_table file_table; + find_copies_too = copies; init_hash(&file_table); for (i = 0; i < rename_src_nr; i++) insert_file_table(&file_table, -1, i, rename_src[i].one); @@ -467,7 +472,7 @@ void diffcore_rename(struct diff_options *options) * We really want to cull the candidates list early * with cheap tests in order to avoid doing deltas. */ - rename_count = find_exact_renames(); + rename_count = find_exact_renames(detect_rename == DIFF_DETECT_COPY); /* Did we only want exact renames? */ if (minimum_score == MAX_SCORE) @@ -551,6 +556,7 @@ void diffcore_rename(struct diff_options *options) rename_count++; } + if (detect_rename == DIFF_DETECT_COPY) for (i = 0; i < dst_cnt * NUM_CANDIDATE_PER_DST; i++) { struct diff_rename_dst *dst;