527
}
528
529
static void initialize_dir_rename_info(struct dir_rename_info *info,
530
+ struct strset *relevant_sources,
531
struct strset *dirs_removed,
532
struct strmap *dir_rename_count)
533
{
535
struct strmap_entry *entry;
536
int i;
537
537
- if (!dirs_removed) {
538
+ if (!dirs_removed && !relevant_sources) {
539
info->setup = 0;
540
return;
541
}
550
strmap_init_with_options(&info->dir_rename_guess, NULL, 0);
551
552
/* Setup info->relevant_source_dirs */
552
- info->relevant_source_dirs = dirs_removed;
553
+ info->relevant_source_dirs = NULL;
554
+ if (dirs_removed || !relevant_sources) {
555
+ info->relevant_source_dirs = dirs_removed; /* might be NULL */
556
+ } else {
557
+ info->relevant_source_dirs = xmalloc(sizeof(struct strintmap));
558
+ strset_init(info->relevant_source_dirs);
559
+ strset_for_each_entry(relevant_sources, &iter, entry) {
560
+ char *dirname = get_dirname(entry->key);
561
+ if (!dirs_removed ||
562
+ strset_contains(dirs_removed, dirname))
563
+ strset_add(info->relevant_source_dirs, dirname);
564
+ free(dirname);
565
+ }
566
+ }
567
568
/*
569
* Loop setting up both info->idx_map, and doing setup of
641
/* dir_rename_guess */
642
strmap_clear(&info->dir_rename_guess, 1);
643
644
+ /* relevant_source_dirs */
645
+ if (info->relevant_source_dirs &&
646
+ info->relevant_source_dirs != dirs_removed) {
647
+ strset_clear(info->relevant_source_dirs);
648
+ FREE_AND_NULL(info->relevant_source_dirs);
649
+ }
650
+
651
/* dir_rename_count */
652
if (!keep_dir_rename_count) {
653
partial_clear_dir_rename_count(info->dir_rename_count);
770
static int find_basename_matches(struct diff_options *options,
771
int minimum_score,
772
struct dir_rename_info *info,
773
+ struct strset *relevant_sources,
774
struct strset *dirs_removed)
775
{
776
/*
861
intptr_t src_index;
862
intptr_t dst_index;
863
864
+ /* Skip irrelevant sources */
865
+ if (relevant_sources &&
866
+ !strset_contains(relevant_sources, filename))
867
+ continue;
868
+
869
/*
870
* If the basename is unique among remaining sources, then
871
* src_index will equal 'i' and we can attempt to match it
1191
1192
/* Preparation for basename-driven matching. */
1193
trace2_region_enter("diff", "dir rename setup", options->repo);
1167
- initialize_dir_rename_info(&info,
1194
+ initialize_dir_rename_info(&info, relevant_sources,
1195
dirs_removed, dir_rename_count);
1196
trace2_region_leave("diff", "dir rename setup", options->repo);
1197
1199
trace2_region_enter("diff", "basename matches", options->repo);
1200
rename_count += find_basename_matches(options,
1201
min_basename_score,
1175
- &info, dirs_removed);
1202
+ &info,
1203
+ relevant_sources,
1204
+ dirs_removed);
1205
trace2_region_leave("diff", "basename matches", options->repo);
1206
1207
/*