@@ -1312,24 +1312,15 @@ static int conflict_rename_rename_2to1(struct merge_options *o,
1312
1312
}
1313
1313
1314
1314
/*
1315
- * Get information of all renames which occurred between 'o_tree' and
1316
- * 'tree'. We need the three trees in the merge ('o_tree', 'a_tree' and
1317
- * 'b_tree') to be able to associate the correct cache entries with
1318
- * the rename information. 'tree' is always equal to either a_tree or b_tree.
1315
+ * Get the diff_filepairs changed between o_tree and tree.
1319
1316
*/
1320
- static struct string_list * get_renames (struct merge_options * o ,
1321
- struct tree * tree ,
1322
- struct tree * o_tree ,
1323
- struct tree * a_tree ,
1324
- struct tree * b_tree ,
1325
- struct string_list * entries )
1317
+ static struct diff_queue_struct * get_diffpairs (struct merge_options * o ,
1318
+ struct tree * o_tree ,
1319
+ struct tree * tree )
1326
1320
{
1327
- int i ;
1328
- struct string_list * renames ;
1321
+ struct diff_queue_struct * ret ;
1329
1322
struct diff_options opts ;
1330
1323
1331
- renames = xcalloc (1 , sizeof (struct string_list ));
1332
-
1333
1324
diff_setup (& opts );
1334
1325
opts .flags .recursive = 1 ;
1335
1326
opts .flags .rename_empty = 0 ;
@@ -1345,10 +1336,41 @@ static struct string_list *get_renames(struct merge_options *o,
1345
1336
diffcore_std (& opts );
1346
1337
if (opts .needed_rename_limit > o -> needed_rename_limit )
1347
1338
o -> needed_rename_limit = opts .needed_rename_limit ;
1348
- for (i = 0 ; i < diff_queued_diff .nr ; ++ i ) {
1339
+
1340
+ ret = xmalloc (sizeof (* ret ));
1341
+ * ret = diff_queued_diff ;
1342
+
1343
+ opts .output_format = DIFF_FORMAT_NO_OUTPUT ;
1344
+ diff_queued_diff .nr = 0 ;
1345
+ diff_queued_diff .queue = NULL ;
1346
+ diff_flush (& opts );
1347
+ return ret ;
1348
+ }
1349
+
1350
+ /*
1351
+ * Get information of all renames which occurred in 'pairs', making use of
1352
+ * any implicit directory renames inferred from the other side of history.
1353
+ * We need the three trees in the merge ('o_tree', 'a_tree' and 'b_tree')
1354
+ * to be able to associate the correct cache entries with the rename
1355
+ * information; tree is always equal to either a_tree or b_tree.
1356
+ */
1357
+ static struct string_list * get_renames (struct merge_options * o ,
1358
+ struct diff_queue_struct * pairs ,
1359
+ struct tree * tree ,
1360
+ struct tree * o_tree ,
1361
+ struct tree * a_tree ,
1362
+ struct tree * b_tree ,
1363
+ struct string_list * entries )
1364
+ {
1365
+ int i ;
1366
+ struct string_list * renames ;
1367
+
1368
+ renames = xcalloc (1 , sizeof (struct string_list ));
1369
+
1370
+ for (i = 0 ; i < pairs -> nr ; ++ i ) {
1349
1371
struct string_list_item * item ;
1350
1372
struct rename * re ;
1351
- struct diff_filepair * pair = diff_queued_diff . queue [i ];
1373
+ struct diff_filepair * pair = pairs -> queue [i ];
1352
1374
1353
1375
if (pair -> status != 'R' ) {
1354
1376
diff_free_filepair (pair );
@@ -1373,9 +1395,6 @@ static struct string_list *get_renames(struct merge_options *o,
1373
1395
item = string_list_insert (renames , pair -> one -> path );
1374
1396
item -> util = re ;
1375
1397
}
1376
- opts .output_format = DIFF_FORMAT_NO_OUTPUT ;
1377
- diff_queued_diff .nr = 0 ;
1378
- diff_flush (& opts );
1379
1398
return renames ;
1380
1399
}
1381
1400
@@ -1646,15 +1665,36 @@ static int handle_renames(struct merge_options *o,
1646
1665
struct string_list * entries ,
1647
1666
struct rename_info * ri )
1648
1667
{
1668
+ struct diff_queue_struct * head_pairs , * merge_pairs ;
1669
+ int clean ;
1670
+
1649
1671
ri -> head_renames = NULL ;
1650
1672
ri -> merge_renames = NULL ;
1651
1673
1652
1674
if (!o -> detect_rename )
1653
1675
return 1 ;
1654
1676
1655
- ri -> head_renames = get_renames (o , head , common , head , merge , entries );
1656
- ri -> merge_renames = get_renames (o , merge , common , head , merge , entries );
1657
- return process_renames (o , ri -> head_renames , ri -> merge_renames );
1677
+ head_pairs = get_diffpairs (o , common , head );
1678
+ merge_pairs = get_diffpairs (o , common , merge );
1679
+
1680
+ ri -> head_renames = get_renames (o , head_pairs , head ,
1681
+ common , head , merge , entries );
1682
+ ri -> merge_renames = get_renames (o , merge_pairs , merge ,
1683
+ common , head , merge , entries );
1684
+ clean = process_renames (o , ri -> head_renames , ri -> merge_renames );
1685
+
1686
+ /*
1687
+ * Some cleanup is deferred until cleanup_renames() because the
1688
+ * data structures are still needed and referenced in
1689
+ * process_entry(). But there are a few things we can free now.
1690
+ */
1691
+
1692
+ free (head_pairs -> queue );
1693
+ free (head_pairs );
1694
+ free (merge_pairs -> queue );
1695
+ free (merge_pairs );
1696
+
1697
+ return clean ;
1658
1698
}
1659
1699
1660
1700
static void cleanup_rename (struct string_list * rename )
0 commit comments