merge-ort: shuffle the computation and cleanup of potential collisions
Run compute_collisions() for renames on both sides of history before any calls to collect_renames(), and do not free the computed collisions until after both calls to collect_renames(). This is just a code reorganization at this point that doesn't make sense on its own, but will permit us to use the computed collision info from both sides within each call to collect_renames() in a subsequent commit. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Elijah Newren committed
Jul 5, 2022 at 01:33 UTC
3ffbe5a223aa1ed46d6f20da607d42341a8c2bf4
1 file changed
+15
-5
merge-ort.c
+15
-5
@@ -2335,7 +2335,8 @@ static char *check_for_directory_rename(struct merge_options *opt,
2335
}
2336
2337
new_path = handle_path_level_conflicts(opt, path, side_index,
2338
- rename_info, collisions);
2338
+ rename_info,
2339
+ &collisions[side_index]);
2340
*clean_merge &= (new_path != NULL);
2341
2342
return new_path;
@@ -3044,16 +3045,15 @@ static int detect_regular_renames(struct merge_options *opt,
3045
static int collect_renames(struct merge_options *opt,
3046
struct diff_queue_struct *result,
3047
unsigned side_index,
3048
+ struct strmap *collisions,
3049
struct strmap *dir_renames_for_side,
3050
struct strmap *rename_exclusions)
3051
{
3052
int i, clean = 1;
3051
- struct strmap collisions;
3053
struct diff_queue_struct *side_pairs;
3054
struct rename_info *renames = &opt->priv->renames;
3055
3056
side_pairs = &renames->pairs[side_index];
3056
- compute_collisions(&collisions, dir_renames_for_side, side_pairs);
3057
3058
for (i = 0; i < side_pairs->nr; ++i) {
3059
struct diff_filepair *p = side_pairs->queue[i];
@@ -3069,7 +3069,7 @@ static int collect_renames(struct merge_options *opt,
3069
side_index,
3070
dir_renames_for_side,
3071
rename_exclusions,
3072
- &collisions,
3072
+ collisions,
3073
&clean);
3074
3075
possibly_cache_new_pair(renames, p, side_index, new_path);
@@ -3095,7 +3095,6 @@ static int collect_renames(struct merge_options *opt,
3095
result->queue[result->nr++] = p;
3096
}
3097
3098
- free_collisions(&collisions);
3098
return clean;
3099
}
3100
@@ -3106,6 +3105,7 @@ static int detect_and_process_renames(struct merge_options *opt,
3105
{
3106
struct diff_queue_struct combined = { 0 };
3107
struct rename_info *renames = &opt->priv->renames;
3108
+ struct strmap collisions[3];
3109
int need_dir_renames, s, i, clean = 1;
3110
unsigned detection_run = 0;
3111
@@ -3155,12 +3155,22 @@ static int detect_and_process_renames(struct merge_options *opt,
3155
ALLOC_GROW(combined.queue,
3156
renames->pairs[1].nr + renames->pairs[2].nr,
3157
combined.alloc);
3158
+ for (i = MERGE_SIDE1; i <= MERGE_SIDE2; i++) {
3159
+ int other_side = 3 - i;
3160
+ compute_collisions(&collisions[i],
3161
+ &renames->dir_renames[other_side],
3162
+ &renames->pairs[i]);
3163
+ }
3164
clean &= collect_renames(opt, &combined, MERGE_SIDE1,
3165
+ collisions,
3166
&renames->dir_renames[2],
3167
&renames->dir_renames[1]);
3168
clean &= collect_renames(opt, &combined, MERGE_SIDE2,
3169
+ collisions,
3170
&renames->dir_renames[1],
3171
&renames->dir_renames[2]);
3172
+ for (i = MERGE_SIDE1; i <= MERGE_SIDE2; i++)
3173
+ free_collisions(&collisions[i]);
3174
STABLE_QSORT(combined.queue, combined.nr, compare_pairs);
3175
trace2_region_leave("merge", "directory renames", opt->repo);
3176