Code

Merge branch 'jc/rename'
authorJunio C Hamano <gitster@pobox.com>
Wed, 9 Apr 2008 07:46:40 +0000 (00:46 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 9 Apr 2008 08:09:12 +0000 (01:09 -0700)
* 'jc/rename' (early part):
  Optimize rename detection for a huge diff

1  2 
diffcore-rename.c

index 31941bcbbf457fe02097f8c46d25f1f9fc7c4f9f,5974362d3b38a1445f02c35130f52c0661861b5e..1369a5ec45349c1ef04e4df2d7d7d4dd28cd3596
@@@ -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 */