Skip to content

Commit 9d8a5a5

Browse files
committed
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 <[email protected]> --- Rebased to 'master' as the logic to use the result of this logic was updated recently, together with the addition of eye-candy.
1 parent e7c3a59 commit 9d8a5a5

File tree

1 file changed

+29
-18
lines changed

1 file changed

+29
-18
lines changed

diffcore-rename.c

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,34 @@ static void record_if_better(struct diff_score m[], struct diff_score *o)
419419
m[worst] = *o;
420420
}
421421

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+
422450
static int find_renames(struct diff_score *mx, int dst_cnt, int minimum_score, int copies)
423451
{
424452
int count = 0, i;
@@ -444,7 +472,6 @@ void diffcore_rename(struct diff_options *options)
444472
{
445473
int detect_rename = options->detect_rename;
446474
int minimum_score = options->rename_score;
447-
int rename_limit = options->rename_limit;
448475
struct diff_queue_struct *q = &diff_queued_diff;
449476
struct diff_queue_struct outq;
450477
struct diff_score *mx;
@@ -511,24 +538,8 @@ void diffcore_rename(struct diff_options *options)
511538
if (!num_create)
512539
goto cleanup;
513540

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))
530542
goto cleanup;
531-
}
532543

533544
if (options->show_rename_progress) {
534545
progress = start_progress_delay(

0 commit comments

Comments
 (0)