Skip to content

Commit b6e3d27

Browse files
newrengitster
authored andcommitted
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 <[email protected]> Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cd52e00 commit b6e3d27

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

diffcore-rename.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -388,28 +388,28 @@ static void dirname_munge(char *filename)
388388
*slash = '\0';
389389
}
390390

391-
static void increment_count(struct strmap *dir_rename_count,
391+
static void increment_count(struct dir_rename_info *info,
392392
char *old_dir,
393393
char *new_dir)
394394
{
395395
struct strintmap *counts;
396396
struct strmap_entry *e;
397397

398398
/* 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);
400400
if (e) {
401401
counts = e->value;
402402
} else {
403403
counts = xmalloc(sizeof(*counts));
404404
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);
406406
}
407407

408408
/* Increment the count for new_dir */
409409
strintmap_incr(counts, new_dir, 1);
410410
}
411411

412-
static void update_dir_rename_counts(struct strmap *dir_rename_count,
412+
static void update_dir_rename_counts(struct dir_rename_info *info,
413413
struct strset *dirs_removed,
414414
const char *oldname,
415415
const char *newname)
@@ -463,7 +463,7 @@ static void update_dir_rename_counts(struct strmap *dir_rename_count,
463463
}
464464

465465
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);
467467
else
468468
break;
469469

@@ -479,12 +479,15 @@ static void update_dir_rename_counts(struct strmap *dir_rename_count,
479479
free(new_dir);
480480
}
481481

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)
484485
{
485486
int i;
486487

487-
/* Set up dir_rename_count */
488+
info->setup = 1;
489+
info->dir_rename_count = dir_rename_count;
490+
488491
for (i = 0; i < rename_dst_nr; ++i) {
489492
/* File not part of directory rename counts if not a rename */
490493
if (!rename_dst[i].is_rename)
@@ -497,7 +500,7 @@ static void compute_dir_rename_counts(struct strmap *dir_rename_count,
497500
* the old filename and the new filename and count how many
498501
* times that pairing occurs.
499502
*/
500-
update_dir_rename_counts(dir_rename_count, dirs_removed,
503+
update_dir_rename_counts(info, dirs_removed,
501504
rename_dst[i].p->one->path,
502505
rename_dst[i].p->two->path);
503506
}
@@ -551,7 +554,9 @@ static void cleanup_dir_rename_info(struct dir_rename_info *info)
551554
/* dir_rename_guess */
552555
strmap_clear(&info->dir_rename_guess, 1);
553556

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);
555560
}
556561

557562
static const char *get_basename(const char *filename)
@@ -1140,7 +1145,7 @@ void diffcore_rename_extended(struct diff_options *options,
11401145
/*
11411146
* Now that renames have been computed, compute dir_rename_count */
11421147
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);
11441149

11451150
/* At this point, we have found some renames and copies and they
11461151
* are recorded in rename_dst. The original list is still in *q.

0 commit comments

Comments
 (0)