diffcore-rename: refactor "too many candidates" logic
Move the logic to a separate function, to be enhanced by later patches in the series. While at it, swap the condition used in the if statement from "if it is too big then do this" to "if it would fit then do this". Signed-off-by: Junio C Hamano <gitster@pobox.com> --- Rebased to 'master' as the logic to use the result of this logic was updated recently, together with the addition of eye-candy.
Junio C Hamano committed
Jan 6, 2011 at 13:50 UTC
9d8a5a50b7e30d85aff3deac2a6994bf0178983d
1 file changed
+29
-18
diffcore-rename.c
+29
-18
@@ -419,6 +419,34 @@ static void record_if_better(struct diff_score m[], struct diff_score *o)
419
m[worst] = *o;
420
}
421
422
+static int too_many_rename_candidates(int num_create,
423
+ struct diff_options *options)
424
+{
425
+ int rename_limit = options->rename_limit;
426
+ int num_src = rename_src_nr;
427
+
428
+ options->needed_rename_limit = 0;
429
+
430
+ /*
431
+ * This basically does a test for the rename matrix not
432
+ * growing larger than a "rename_limit" square matrix, ie:
433
+ *
434
+ * num_create * num_src > rename_limit * rename_limit
435
+ *
436
+ * but handles the potential overflow case specially (and we
437
+ * assume at least 32-bit integers)
438
+ */
439
+ if (rename_limit <= 0 || rename_limit > 32767)
440
+ rename_limit = 32767;
441
+ if ((num_create <= rename_limit || num_src <= rename_limit) &&
442
+ (num_create * num_src <= rename_limit * rename_limit))
443
+ return 0;
444
+
445
+ options->needed_rename_limit =
446
+ num_src > num_create ? num_src : num_create;
447
+ return 1;
448
+}
449
+
450
static int find_renames(struct diff_score *mx, int dst_cnt, int minimum_score, int copies)
451
{
452
int count = 0, i;
@@ -444,7 +472,6 @@ void diffcore_rename(struct diff_options *options)
472
{
473
int detect_rename = options->detect_rename;
474
int minimum_score = options->rename_score;
447
- int rename_limit = options->rename_limit;
475
struct diff_queue_struct *q = &diff_queued_diff;
476
struct diff_queue_struct outq;
477
struct diff_score *mx;
@@ -511,24 +538,8 @@ void diffcore_rename(struct diff_options *options)
538
if (!num_create)
539
goto cleanup;
540
514
- /*
515
- * This basically does a test for the rename matrix not
516
- * growing larger than a "rename_limit" square matrix, ie:
517
- *
518
- * num_create * num_src > rename_limit * rename_limit
519
- *
520
- * but handles the potential overflow case specially (and we
521
- * assume at least 32-bit integers)
522
- */
523
- options->needed_rename_limit = 0;
524
- if (rename_limit <= 0 || rename_limit > 32767)
525
- rename_limit = 32767;
526
- if ((num_create > rename_limit && num_src > rename_limit) ||
527
- (num_create * num_src > rename_limit * rename_limit)) {
528
- options->needed_rename_limit =
529
- num_src > num_create ? num_src : num_create;
541
+ if (too_many_rename_candidates(num_create, options))
542
goto cleanup;
531
- }
543
544
if (options->show_rename_progress) {
545
progress = start_progress_delay(