Skip to content

Commit ae8cf74

Browse files
newrengitster
authored andcommitted
diffcore-rename: add a mapping of destination names to their indices
Compute a mapping of full filename to the index within rename_dst where that filename is found, and store it in idx_map. idx_possible_rename() needs this to quickly finding an array entry in rename_dst given the pathname. While at it, add placeholder initializations for dir_rename_count and dir_rename_guess; these will be more fully populated in subsequent commits. Reviewed-by: Derrick Stolee <[email protected]> Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bde8b9f commit ae8cf74

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

diffcore-rename.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,45 @@ static char *get_dirname(const char *filename)
380380
return slash ? xstrndup(filename, slash - filename) : xstrdup("");
381381
}
382382

383+
static void initialize_dir_rename_info(struct dir_rename_info *info)
384+
{
385+
int i;
386+
387+
info->setup = 1;
388+
389+
strintmap_init_with_options(&info->idx_map, -1, NULL, 0);
390+
strmap_init_with_options(&info->dir_rename_guess, NULL, 0);
391+
info->dir_rename_count = NULL;
392+
393+
/*
394+
* Loop setting up both info->idx_map.
395+
*/
396+
for (i = 0; i < rename_dst_nr; ++i) {
397+
/*
398+
* For non-renamed files, make idx_map contain mapping of
399+
* filename -> index (index within rename_dst, that is)
400+
*/
401+
if (!rename_dst[i].is_rename) {
402+
char *filename = rename_dst[i].p->two->path;
403+
strintmap_set(&info->idx_map, filename, i);
404+
}
405+
}
406+
}
407+
408+
static void cleanup_dir_rename_info(struct dir_rename_info *info)
409+
{
410+
if (!info->setup)
411+
return;
412+
413+
/* idx_map */
414+
strintmap_clear(&info->idx_map);
415+
416+
/* dir_rename_guess */
417+
strmap_clear(&info->dir_rename_guess, 1);
418+
419+
/* Nothing to do for dir_rename_count, yet */
420+
}
421+
383422
static const char *get_basename(const char *filename)
384423
{
385424
/*
@@ -858,6 +897,11 @@ void diffcore_rename(struct diff_options *options)
858897
remove_unneeded_paths_from_src(want_copies);
859898
trace2_region_leave("diff", "cull after exact", options->repo);
860899

900+
/* Preparation for basename-driven matching. */
901+
trace2_region_enter("diff", "dir rename setup", options->repo);
902+
initialize_dir_rename_info(&info);
903+
trace2_region_leave("diff", "dir rename setup", options->repo);
904+
861905
/* Utilize file basenames to quickly find renames. */
862906
trace2_region_enter("diff", "basename matches", options->repo);
863907
rename_count += find_basename_matches(options,
@@ -1026,6 +1070,7 @@ void diffcore_rename(struct diff_options *options)
10261070
if (rename_dst[i].filespec_to_free)
10271071
free_filespec(rename_dst[i].filespec_to_free);
10281072

1073+
cleanup_dir_rename_info(&info);
10291074
FREE_AND_NULL(rename_dst);
10301075
rename_dst_nr = rename_dst_alloc = 0;
10311076
FREE_AND_NULL(rename_src);

0 commit comments

Comments
 (0)