merge-ort: preserve cached renames for the appropriate side

Previous commits created an in-memory cache of the results of rename detection, and added logic to detect when that cache could appropriately be used in a subsequent merge operation -- but we were still unconditionally clearing the cache with each new merge operation anyway. If it is valid to reuse the cache from one of the two sides of history, preserve that side. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed May 20, 2021 at 06:09 UTC d509802993e8423d459a05fcd6151ca1782caa07
1 file changed +11 -9
merge-ort.c
+11 -9
@@ -486,17 +486,18 @@ static void clear_or_reinit_internal_opts(struct merge_options_internal *opti,
486 /* Free memory used by various renames maps */
487 for (i = MERGE_SIDE1; i <= MERGE_SIDE2; ++i) {
488 strintmap_func(&renames->dirs_removed[i]);
489 -
490 - partial_clear_dir_rename_count(&renames->dir_rename_count[i]);
491 - if (!reinitialize)
492 - strmap_clear(&renames->dir_rename_count[i], 1);
493 -
489 strmap_func(&renames->dir_renames[i], 0);
495 -
490 strintmap_func(&renames->relevant_sources[i]);
497 - strset_func(&renames->cached_target_names[i]);
498 - strmap_func(&renames->cached_pairs[i], 1);
499 - strset_func(&renames->cached_irrelevant[i]);
491 + if (!reinitialize)
492 + assert(renames->cached_pairs_valid_side == 0);
493 + if (i != renames->cached_pairs_valid_side) {
494 + strset_func(&renames->cached_target_names[i]);
495 + strmap_func(&renames->cached_pairs[i], 1);
496 + strset_func(&renames->cached_irrelevant[i]);
497 + partial_clear_dir_rename_count(&renames->dir_rename_count[i]);
498 + if (!reinitialize)
499 + strmap_clear(&renames->dir_rename_count[i], 1);
500 + }
501 }
502 renames->cached_pairs_valid_side = 0;
503 renames->dir_rename_mask = 0;
@@ -2456,6 +2457,7 @@ static void detect_regular_renames(struct merge_options *opt,
2457 return;
2458 }
2459
2460 + partial_clear_dir_rename_count(&renames->dir_rename_count[side_index]);
2461 repo_diff_setup(opt->repo, &diff_opts);
2462 diff_opts.flags.recursive = 1;
2463 diff_opts.flags.rename_empty = 0;