@@ -721,6 +721,11 @@ static int handle_content_merge(struct merge_options *opt,
721
721
722
722
/*** Function Grouping: functions related to directory rename detection ***/
723
723
724
+ struct collision_info {
725
+ struct string_list source_files ;
726
+ unsigned reported_already :1 ;
727
+ };
728
+
724
729
static void get_renamed_dir_portion (const char * old_path , const char * new_path ,
725
730
char * * old_dir , char * * new_dir )
726
731
{
@@ -959,6 +964,31 @@ static void handle_directory_level_conflicts(struct merge_options *opt)
959
964
string_list_clear (& duplicated , 0 );
960
965
}
961
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
+
962
992
/*** Function Grouping: functions related to regular rename detection ***/
963
993
964
994
static int process_renames (struct merge_options * opt ,
@@ -1284,22 +1314,44 @@ static void detect_regular_renames(struct merge_options *opt,
1284
1314
*/
1285
1315
static int collect_renames (struct merge_options * opt ,
1286
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 )
1288
1320
{
1289
1321
int i , clean = 1 ;
1322
+ struct strmap collisions ;
1290
1323
struct diff_queue_struct * side_pairs ;
1324
+ struct hashmap_iter iter ;
1325
+ struct strmap_entry * entry ;
1291
1326
struct rename_info * renames = & opt -> priv -> renames ;
1292
1327
1293
1328
side_pairs = & renames -> pairs [side_index ];
1329
+ compute_collisions (& collisions , dir_renames_for_side , side_pairs );
1294
1330
1295
1331
for (i = 0 ; i < side_pairs -> nr ; ++ i ) {
1296
1332
struct diff_filepair * p = side_pairs -> queue [i ];
1333
+ char * new_path ; /* non-NULL only with directory renames */
1297
1334
1298
- if (p -> status != 'R' ) {
1335
+ if (p -> status != 'A' && p -> status != ' R' ) {
1299
1336
diff_free_filepair (p );
1300
1337
continue ;
1301
1338
}
1302
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
+
1303
1355
/*
1304
1356
* p->score comes back from diffcore_rename_extended() with
1305
1357
* the similarity of the renamed file. The similarity is
@@ -1314,6 +1366,20 @@ static int collect_renames(struct merge_options *opt,
1314
1366
result -> queue [result -> nr ++ ] = p ;
1315
1367
}
1316
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 );
1317
1383
return clean ;
1318
1384
}
1319
1385
@@ -1345,8 +1411,12 @@ static int detect_and_process_renames(struct merge_options *opt,
1345
1411
ALLOC_GROW (combined .queue ,
1346
1412
renames -> pairs [1 ].nr + renames -> pairs [2 ].nr ,
1347
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 ]);
1350
1420
QSORT (combined .queue , combined .nr , compare_pairs );
1351
1421
1352
1422
clean &= process_renames (opt , & combined );
0 commit comments