389
*slash = '\0';
390
}
391
392
+static const char *get_highest_rename_path(struct strintmap *counts)
393
+{
394
+ int highest_count = 0;
395
+ const char *highest_destination_dir = NULL;
396
+ struct hashmap_iter iter;
397
+ struct strmap_entry *entry;
398
+
399
+ strintmap_for_each_entry(counts, &iter, entry) {
400
+ const char *destination_dir = entry->key;
401
+ intptr_t count = (intptr_t)entry->value;
402
+ if (count > highest_count) {
403
+ highest_count = count;
404
+ highest_destination_dir = destination_dir;
405
+ }
406
+ }
407
+ return highest_destination_dir;
408
+}
409
+
410
static void increment_count(struct dir_rename_info *info,
411
char *old_dir,
412
char *new_dir)
530
struct strset *dirs_removed,
531
struct strmap *dir_rename_count)
532
{
533
+ struct hashmap_iter iter;
534
+ struct strmap_entry *entry;
535
int i;
536
537
if (!dirs_removed) {
578
rename_dst[i].p->one->path,
579
rename_dst[i].p->two->path);
580
}
581
+
582
+ /*
583
+ * Now we collapse
584
+ * dir_rename_count: old_directory -> {new_directory -> count}
585
+ * down to
586
+ * dir_rename_guess: old_directory -> best_new_directory
587
+ * where best_new_directory is the one with the highest count.
588
+ */
589
+ strmap_for_each_entry(info->dir_rename_count, &iter, entry) {
590
+ /* entry->key is source_dir */
591
+ struct strintmap *counts = entry->value;
592
+ char *best_newdir;
593
+
594
+ best_newdir = xstrdup(get_highest_rename_path(counts));
595
+ strmap_put(&info->dir_rename_guess, entry->key,
596
+ best_newdir);
597
+ }
598
}
599
600
void partial_clear_dir_rename_count(struct strmap *dir_rename_count)
719
* rename.
720
*
721
* This function, idx_possible_rename(), is only responsible for (4).
685
- * The conditions/steps in (1)-(3) will be handled via setting up
686
- * dir_rename_count and dir_rename_guess in a future
687
- * initialize_dir_rename_info() function. Steps (0) and (5) are
688
- * handled by the caller of this function.
722
+ * The conditions/steps in (1)-(3) are handled via setting up
723
+ * dir_rename_count and dir_rename_guess in
724
+ * initialize_dir_rename_info(). Steps (0) and (5) are handled by
725
+ * the caller of this function.
726
*/
727
char *old_dir, *new_dir;
728
struct strbuf new_path = STRBUF_INIT;