Skip to content

Commit 00b8ccc

Browse files
newrengitster
authored andcommitted
diffcore-rename: avoid usage of global in too_many_rename_candidates()
too_many_rename_candidates() got the number of rename destinations via an argument to the function, but the number of rename sources via a global variable. That felt rather inconsistent. Pass in the number of rename sources as an argument as well. While we are at it... We had a local variable, num_src, that served two purposes. Initially it was set to the global value, but later was used for counting a subset of the number of sources. Since we now have a function argument for the former usage, introduce a clearer variable name for the latter usage. This patch has no behavioral changes; it's just renaming and passing an argument instead of grabbing it from the global namespace. (You may find it easier to view the patch using git diff's --color-words option.) Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 26a66a6 commit 00b8ccc

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

diffcore-rename.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -434,43 +434,42 @@ static void record_if_better(struct diff_score m[], struct diff_score *o)
434434
* 1 if we need to disable inexact rename detection;
435435
* 2 if we would be under the limit if we were given -C instead of -C -C.
436436
*/
437-
static int too_many_rename_candidates(int num_destinations,
437+
static int too_many_rename_candidates(int num_destinations, int num_sources,
438438
struct diff_options *options)
439439
{
440440
int rename_limit = options->rename_limit;
441-
int num_src = rename_src_nr;
442-
int i;
441+
int i, limited_sources;
443442

444443
options->needed_rename_limit = 0;
445444

446445
/*
447446
* This basically does a test for the rename matrix not
448447
* growing larger than a "rename_limit" square matrix, ie:
449448
*
450-
* num_destinations * num_src > rename_limit * rename_limit
449+
* num_destinations * num_sources > rename_limit * rename_limit
451450
*/
452451
if (rename_limit <= 0)
453452
rename_limit = 32767;
454-
if ((num_destinations <= rename_limit || num_src <= rename_limit) &&
455-
((uint64_t)num_destinations * (uint64_t)num_src
453+
if ((num_destinations <= rename_limit || num_sources <= rename_limit) &&
454+
((uint64_t)num_destinations * (uint64_t)num_sources
456455
<= (uint64_t)rename_limit * (uint64_t)rename_limit))
457456
return 0;
458457

459458
options->needed_rename_limit =
460-
num_src > num_destinations ? num_src : num_destinations;
459+
num_sources > num_destinations ? num_sources : num_destinations;
461460

462461
/* Are we running under -C -C? */
463462
if (!options->flags.find_copies_harder)
464463
return 1;
465464

466465
/* Would we bust the limit if we were running under -C? */
467-
for (num_src = i = 0; i < rename_src_nr; i++) {
466+
for (limited_sources = i = 0; i < num_sources; i++) {
468467
if (diff_unmodified_pair(rename_src[i].p))
469468
continue;
470-
num_src++;
469+
limited_sources++;
471470
}
472-
if ((num_destinations <= rename_limit || num_src <= rename_limit) &&
473-
((uint64_t)num_destinations * (uint64_t)num_src
471+
if ((num_destinations <= rename_limit || limited_sources <= rename_limit) &&
472+
((uint64_t)num_destinations * (uint64_t)limited_sources
474473
<= (uint64_t)rename_limit * (uint64_t)rename_limit))
475474
return 2;
476475
return 1;
@@ -576,7 +575,8 @@ void diffcore_rename(struct diff_options *options)
576575
if (!num_destinations)
577576
goto cleanup;
578577

579-
switch (too_many_rename_candidates(num_destinations, options)) {
578+
switch (too_many_rename_candidates(num_destinations, rename_src_nr,
579+
options)) {
580580
case 1:
581581
goto cleanup;
582582
case 2:

0 commit comments

Comments
 (0)