merge-ort: modify collect_renames() for directory rename handling
collect_renames() is similar to merge-recursive.c's get_renames(), but lacks the directory rename handling found in the latter. Port that code structure over to merge-ort. This introduces three new die-not-yet-implemented functions that will be defined in future commits. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Elijah Newren committed
Jan 19, 2021 at 19:53 UTC
fa5e06d6902003f5f115b7497030b5c66537726e
1 file changed
+74
-4
merge-ort.c
+74
-4
@@ -721,6 +721,11 @@ static int handle_content_merge(struct merge_options *opt,
721
722
/*** Function Grouping: functions related to directory rename detection ***/
723
724
+struct collision_info {
725
+ struct string_list source_files;
726
+ unsigned reported_already:1;
727
+};
728
+
729
static void get_renamed_dir_portion(const char *old_path, const char *new_path,
730
char **old_dir, char **new_dir)
731
{
@@ -959,6 +964,31 @@ static void handle_directory_level_conflicts(struct merge_options *opt)
964
string_list_clear(&duplicated, 0);
965
}
966
967
+static void compute_collisions(struct strmap *collisions,
968
+ struct strmap *dir_renames,
969
+ struct diff_queue_struct *pairs)
970
+{
971
+ die("Not yet implemented.");
972
+}
973
+
974
+static char *check_for_directory_rename(struct merge_options *opt,
975
+ const char *path,
976
+ unsigned side_index,
977
+ struct strmap *dir_renames,
978
+ struct strmap *dir_rename_exclusions,
979
+ struct strmap *collisions,
980
+ int *clean_merge)
981
+{
982
+ die("Not yet implemented.");
983
+}
984
+
985
+static void apply_directory_rename_modifications(struct merge_options *opt,
986
+ struct diff_filepair *pair,
987
+ char *new_path)
988
+{
989
+ die("Not yet implemented.");
990
+}
991
+
992
/*** Function Grouping: functions related to regular rename detection ***/
993
994
static int process_renames(struct merge_options *opt,
@@ -1284,22 +1314,44 @@ static void detect_regular_renames(struct merge_options *opt,
1314
*/
1315
static int collect_renames(struct merge_options *opt,
1316
struct diff_queue_struct *result,
1287
- unsigned side_index)
1317
+ unsigned side_index,
1318
+ struct strmap *dir_renames_for_side,
1319
+ struct strmap *rename_exclusions)
1320
{
1321
int i, clean = 1;
1322
+ struct strmap collisions;
1323
struct diff_queue_struct *side_pairs;
1324
+ struct hashmap_iter iter;
1325
+ struct strmap_entry *entry;
1326
struct rename_info *renames = &opt->priv->renames;
1327
1328
side_pairs = &renames->pairs[side_index];
1329
+ compute_collisions(&collisions, dir_renames_for_side, side_pairs);
1330
1331
for (i = 0; i < side_pairs->nr; ++i) {
1332
struct diff_filepair *p = side_pairs->queue[i];
1333
+ char *new_path; /* non-NULL only with directory renames */
1334
1298
- if (p->status != 'R') {
1335
+ if (p->status != 'A' && p->status != 'R') {
1336
diff_free_filepair(p);
1337
continue;
1338
}
1339
1340
+ new_path = check_for_directory_rename(opt, p->two->path,
1341
+ side_index,
1342
+ dir_renames_for_side,
1343
+ rename_exclusions,
1344
+ &collisions,
1345
+ &clean);
1346
+
1347
+ if (p->status != 'R' && !new_path) {
1348
+ diff_free_filepair(p);
1349
+ continue;
1350
+ }
1351
+
1352
+ if (new_path)
1353
+ apply_directory_rename_modifications(opt, p, new_path);
1354
+
1355
/*
1356
* p->score comes back from diffcore_rename_extended() with
1357
* the similarity of the renamed file. The similarity is
@@ -1314,6 +1366,20 @@ static int collect_renames(struct merge_options *opt,
1366
result->queue[result->nr++] = p;
1367
}
1368
1369
+ /* Free each value in the collisions map */
1370
+ strmap_for_each_entry(&collisions, &iter, entry) {
1371
+ struct collision_info *info = entry->value;
1372
+ string_list_clear(&info->source_files, 0);
1373
+ }
1374
+ /*
1375
+ * In compute_collisions(), we set collisions.strdup_strings to 0
1376
+ * so that we wouldn't have to make another copy of the new_path
1377
+ * allocated by apply_dir_rename(). But now that we've used them
1378
+ * and have no other references to these strings, it is time to
1379
+ * deallocate them.
1380
+ */
1381
+ free_strmap_strings(&collisions);
1382
+ strmap_clear(&collisions, 1);
1383
return clean;
1384
}
1385
@@ -1345,8 +1411,12 @@ static int detect_and_process_renames(struct merge_options *opt,
1411
ALLOC_GROW(combined.queue,
1412
renames->pairs[1].nr + renames->pairs[2].nr,
1413
combined.alloc);
1348
- clean &= collect_renames(opt, &combined, MERGE_SIDE1);
1349
- clean &= collect_renames(opt, &combined, MERGE_SIDE2);
1414
+ clean &= collect_renames(opt, &combined, MERGE_SIDE1,
1415
+ &renames->dir_renames[2],
1416
+ &renames->dir_renames[1]);
1417
+ clean &= collect_renames(opt, &combined, MERGE_SIDE2,
1418
+ &renames->dir_renames[1],
1419
+ &renames->dir_renames[2]);
1420
QSORT(combined.queue, combined.nr, compare_pairs);
1421
1422
clean &= process_renames(opt, &combined);