Split out "exact content match" phase of rename detection
This makes the exact content match a separate function of its own. Partly to cut down a bit on the size of the diffcore_rename() function (which is too complex as it is), and partly because there are smarter ways to do this than an O(m*n) loop over it all, and that function should be rewritten to take that into account. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Linus Torvalds committed
Oct 25, 2007 at 11:17 UTC
cb1491b6bff20748532c9e50afc7f9d6896167a8
1 file changed
+56
-34
diffcore-rename.c
+56
-34
@@ -262,6 +262,58 @@ static int compute_stays(struct diff_queue_struct *q,
262
return 1;
263
}
264
265
+/*
266
+ * Find exact renames first.
267
+ *
268
+ * The first round matches up the up-to-date entries,
269
+ * and then during the second round we try to match
270
+ * cache-dirty entries as well.
271
+ *
272
+ * Note: the rest of the rename logic depends on this
273
+ * phase also populating all the filespecs for any
274
+ * entry that isn't matched up with an exact rename,
275
+ * see "is_exact_match()".
276
+ */
277
+static int find_exact_renames(void)
278
+{
279
+ int rename_count = 0;
280
+ int contents_too;
281
+
282
+ for (contents_too = 0; contents_too < 2; contents_too++) {
283
+ int i;
284
+
285
+ for (i = 0; i < rename_dst_nr; i++) {
286
+ struct diff_filespec *two = rename_dst[i].two;
287
+ int j;
288
+
289
+ if (rename_dst[i].pair)
290
+ continue; /* dealt with an earlier round */
291
+ for (j = 0; j < rename_src_nr; j++) {
292
+ int k;
293
+ struct diff_filespec *one = rename_src[j].one;
294
+ if (!is_exact_match(one, two, contents_too))
295
+ continue;
296
+
297
+ /* see if there is a basename match, too */
298
+ for (k = j; k < rename_src_nr; k++) {
299
+ one = rename_src[k].one;
300
+ if (basename_same(one, two) &&
301
+ is_exact_match(one, two,
302
+ contents_too)) {
303
+ j = k;
304
+ break;
305
+ }
306
+ }
307
+
308
+ record_rename_pair(i, j, (int)MAX_SCORE);
309
+ rename_count++;
310
+ break; /* we are done with this entry */
311
+ }
312
+ }
313
+ }
314
+ return rename_count;
315
+}
316
+
317
void diffcore_rename(struct diff_options *options)
318
{
319
int detect_rename = options->detect_rename;
@@ -270,12 +322,11 @@ void diffcore_rename(struct diff_options *options)
322
struct diff_queue_struct *q = &diff_queued_diff;
323
struct diff_queue_struct outq;
324
struct diff_score *mx;
273
- int i, j, rename_count, contents_too;
325
+ int i, j, rename_count;
326
int num_create, num_src, dst_cnt;
327
328
if (!minimum_score)
329
minimum_score = DEFAULT_RENAME_SCORE;
278
- rename_count = 0;
330
331
for (i = 0; i < q->nr; i++) {
332
struct diff_filepair *p = q->queue[i];
@@ -318,40 +369,11 @@ void diffcore_rename(struct diff_options *options)
369
if (rename_dst_nr * rename_src_nr > rename_limit * rename_limit)
370
goto cleanup;
371
321
- /* We really want to cull the candidates list early
372
+ /*
373
+ * We really want to cull the candidates list early
374
* with cheap tests in order to avoid doing deltas.
323
- * The first round matches up the up-to-date entries,
324
- * and then during the second round we try to match
325
- * cache-dirty entries as well.
375
*/
327
- for (contents_too = 0; contents_too < 2; contents_too++) {
328
- for (i = 0; i < rename_dst_nr; i++) {
329
- struct diff_filespec *two = rename_dst[i].two;
330
- if (rename_dst[i].pair)
331
- continue; /* dealt with an earlier round */
332
- for (j = 0; j < rename_src_nr; j++) {
333
- int k;
334
- struct diff_filespec *one = rename_src[j].one;
335
- if (!is_exact_match(one, two, contents_too))
336
- continue;
337
-
338
- /* see if there is a basename match, too */
339
- for (k = j; k < rename_src_nr; k++) {
340
- one = rename_src[k].one;
341
- if (basename_same(one, two) &&
342
- is_exact_match(one, two,
343
- contents_too)) {
344
- j = k;
345
- break;
346
- }
347
- }
348
-
349
- record_rename_pair(i, j, (int)MAX_SCORE);
350
- rename_count++;
351
- break; /* we are done with this entry */
352
- }
353
- }
354
- }
376
+ rename_count = find_exact_renames();
377
378
/* Have we run out the created file pool? If so we can avoid
379
* doing the delta matrix altogether.