From: Junio C Hamano Date: Wed, 9 Apr 2008 07:46:40 +0000 (-0700) Subject: Merge branch 'jc/rename' X-Git-Tag: v1.5.6-rc0~154 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=2a5fe2545882721d6841bad11dae0f15b454bf0d;p=git.git Merge branch 'jc/rename' * 'jc/rename' (early part): Optimize rename detection for a huge diff --- 2a5fe2545882721d6841bad11dae0f15b454bf0d diff --cc diffcore-rename.c index 31941bcbb,5974362d3..1369a5ec4 --- a/diffcore-rename.c +++ b/diffcore-rename.c @@@ -468,26 -490,32 +490,33 @@@ void diffcore_rename(struct diff_option */ if (rename_limit <= 0 || rename_limit > 32767) rename_limit = 32767; - if (num_create > rename_limit && num_src > rename_limit) - goto cleanup; - if (num_create * num_src > rename_limit * rename_limit) + if ((num_create > rename_limit && num_src > rename_limit) || + (num_create * num_src > rename_limit * rename_limit)) { + warning("too many files, skipping inexact rename detection"); goto cleanup; + } - mx = xmalloc(sizeof(*mx) * num_create * num_src); + mx = xcalloc(num_create * NUM_CANDIDATE_PER_DST, sizeof(*mx)); for (dst_cnt = i = 0; i < rename_dst_nr; i++) { - int base = dst_cnt * num_src; struct diff_filespec *two = rename_dst[i].two; + struct diff_score *m; + if (rename_dst[i].pair) continue; /* dealt with exact match already. */ + + m = &mx[dst_cnt * NUM_CANDIDATE_PER_DST]; + for (j = 0; j < NUM_CANDIDATE_PER_DST; j++) + m[j].dst = -1; + for (j = 0; j < rename_src_nr; j++) { struct diff_filespec *one = rename_src[j].one; - struct diff_score *m = &mx[base+j]; - m->src = j; - m->dst = i; - m->score = estimate_similarity(one, two, - minimum_score); - m->name_score = basename_same(one, two); + struct diff_score this_src; + this_src.score = estimate_similarity(one, two, + minimum_score); + this_src.name_score = basename_same(one, two); + this_src.dst = i; + this_src.src = j; + record_if_better(m, &this_src); diff_free_filespec_blob(one); } /* We do not need the text anymore */