diffcore-rename: move dir_rename_counts into dir_rename_info struct

This continues the migration of the directory rename detection code into diffcore-rename, now taking the simple step of combining it with the dir_rename_info struct. Future commits will then make dir_rename_counts be computed in stages, and add computation of dir_rename_guess. Reviewed-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Feb 27, 2021 at 00:30 UTC b6e3d2743410b0cfa749c1690de7f59683c0f372
1 file changed +16 -11
diffcore-rename.c
+16 -11
@@ -388,7 +388,7 @@ static void dirname_munge(char *filename)
388 *slash = '\0';
389 }
390
391 -static void increment_count(struct strmap *dir_rename_count,
391 +static void increment_count(struct dir_rename_info *info,
392 char *old_dir,
393 char *new_dir)
394 {
@@ -396,20 +396,20 @@ static void increment_count(struct strmap *dir_rename_count,
396 struct strmap_entry *e;
397
398 /* Get the {new_dirs -> counts} mapping using old_dir */
399 - e = strmap_get_entry(dir_rename_count, old_dir);
399 + e = strmap_get_entry(info->dir_rename_count, old_dir);
400 if (e) {
401 counts = e->value;
402 } else {
403 counts = xmalloc(sizeof(*counts));
404 strintmap_init_with_options(counts, 0, NULL, 1);
405 - strmap_put(dir_rename_count, old_dir, counts);
405 + strmap_put(info->dir_rename_count, old_dir, counts);
406 }
407
408 /* Increment the count for new_dir */
409 strintmap_incr(counts, new_dir, 1);
410 }
411
412 -static void update_dir_rename_counts(struct strmap *dir_rename_count,
412 +static void update_dir_rename_counts(struct dir_rename_info *info,
413 struct strset *dirs_removed,
414 const char *oldname,
415 const char *newname)
@@ -463,7 +463,7 @@ static void update_dir_rename_counts(struct strmap *dir_rename_count,
463 }
464
465 if (strset_contains(dirs_removed, old_dir))
466 - increment_count(dir_rename_count, old_dir, new_dir);
466 + increment_count(info, old_dir, new_dir);
467 else
468 break;
469
@@ -479,12 +479,15 @@ static void update_dir_rename_counts(struct strmap *dir_rename_count,
479 free(new_dir);
480 }
481
482 -static void compute_dir_rename_counts(struct strmap *dir_rename_count,
483 - struct strset *dirs_removed)
482 +static void compute_dir_rename_counts(struct dir_rename_info *info,
483 + struct strset *dirs_removed,
484 + struct strmap *dir_rename_count)
485 {
486 int i;
487
487 - /* Set up dir_rename_count */
488 + info->setup = 1;
489 + info->dir_rename_count = dir_rename_count;
490 +
491 for (i = 0; i < rename_dst_nr; ++i) {
492 /* File not part of directory rename counts if not a rename */
493 if (!rename_dst[i].is_rename)
@@ -497,7 +500,7 @@ static void compute_dir_rename_counts(struct strmap *dir_rename_count,
500 * the old filename and the new filename and count how many
501 * times that pairing occurs.
502 */
500 - update_dir_rename_counts(dir_rename_count, dirs_removed,
503 + update_dir_rename_counts(info, dirs_removed,
504 rename_dst[i].p->one->path,
505 rename_dst[i].p->two->path);
506 }
@@ -551,7 +554,9 @@ static void cleanup_dir_rename_info(struct dir_rename_info *info)
554 /* dir_rename_guess */
555 strmap_clear(&info->dir_rename_guess, 1);
556
554 - /* Nothing to do for dir_rename_count, yet */
557 + /* dir_rename_count */
558 + partial_clear_dir_rename_count(info->dir_rename_count);
559 + strmap_clear(info->dir_rename_count, 1);
560 }
561
562 static const char *get_basename(const char *filename)
@@ -1140,7 +1145,7 @@ void diffcore_rename_extended(struct diff_options *options,
1145 /*
1146 * Now that renames have been computed, compute dir_rename_count */
1147 if (dirs_removed && dir_rename_count)
1143 - compute_dir_rename_counts(dir_rename_count, dirs_removed);
1148 + compute_dir_rename_counts(&info, dirs_removed, dir_rename_count);
1149
1150 /* At this point, we have found some renames and copies and they
1151 * are recorded in rename_dst. The original list is still in *q.