@matheusbsbs / matheus-bagliano / commits / 17e6019a2a
Fork 0

diffcore-rename: try matching up renames without populating filespec first.

Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Jul 6, 2006 at 00:35 UTC 17e6019a2ac9ad392c2e1c7fb6ce9c53d3d45acf
1 file changed +22 -11
diffcore-rename.c
+22 -11
@@ -96,11 +96,15 @@ static struct diff_rename_src *register_rename_src(struct diff_filespec *one,
96 return &(rename_src[first]);
97 }
98
99 -static int is_exact_match(struct diff_filespec *src, struct diff_filespec *dst)
99 +static int is_exact_match(struct diff_filespec *src,
100 + struct diff_filespec *dst,
101 + int contents_too)
102 {
103 if (src->sha1_valid && dst->sha1_valid &&
104 !memcmp(src->sha1, dst->sha1, 20))
105 return 1;
106 + if (!contents_too)
107 + return 0;
108 if (diff_populate_filespec(src, 1) || diff_populate_filespec(dst, 1))
109 return 0;
110 if (src->size != dst->size)
@@ -242,7 +246,7 @@ void diffcore_rename(struct diff_options *options)
246 struct diff_queue_struct *q = &diff_queued_diff;
247 struct diff_queue_struct outq;
248 struct diff_score *mx;
245 - int i, j, rename_count;
249 + int i, j, rename_count, contents_too;
250 int num_create, num_src, dst_cnt;
251
252 if (!minimum_score)
@@ -273,16 +277,23 @@ void diffcore_rename(struct diff_options *options)
277
278 /* We really want to cull the candidates list early
279 * with cheap tests in order to avoid doing deltas.
280 + * The first round matches up the up-to-date entries,
281 + * and then during the second round we try to match
282 + * cache-dirty entries as well.
283 */
277 - for (i = 0; i < rename_dst_nr; i++) {
278 - struct diff_filespec *two = rename_dst[i].two;
279 - for (j = 0; j < rename_src_nr; j++) {
280 - struct diff_filespec *one = rename_src[j].one;
281 - if (!is_exact_match(one, two))
282 - continue;
283 - record_rename_pair(i, j, MAX_SCORE);
284 - rename_count++;
285 - break; /* we are done with this entry */
284 + for (contents_too = 0; contents_too < 2; contents_too++) {
285 + for (i = 0; i < rename_dst_nr; i++) {
286 + struct diff_filespec *two = rename_dst[i].two;
287 + if (rename_dst[i].pair)
288 + continue; /* dealt with an earlier round */
289 + for (j = 0; j < rename_src_nr; j++) {
290 + struct diff_filespec *one = rename_src[j].one;
291 + if (!is_exact_match(one, two, contents_too))
292 + continue;
293 + record_rename_pair(i, j, MAX_SCORE);
294 + rename_count++;
295 + break; /* we are done with this entry */
296 + }
297 }
298 }
299