merge-recursive: split out code for determining diff_filepairs
Create a new function, get_diffpairs() to compute the diff_filepairs between two trees. While these are currently only used in get_renames(), I want them to be available to some new functions. No actual logic changes yet. Reviewed-by: Stefan Beller <sbeller@google.com> Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Elijah Newren committed
Apr 19, 2018 at 10:58 UTC
e5257b2a0d72010cea8150a520347a206394efd0
1 file changed
+62
-22
merge-recursive.c
+62
-22
@@ -1322,24 +1322,15 @@ static int conflict_rename_rename_2to1(struct merge_options *o,
1322
}
1323
1324
/*
1325
- * Get information of all renames which occurred between 'o_tree' and
1326
- * 'tree'. We need the three trees in the merge ('o_tree', 'a_tree' and
1327
- * 'b_tree') to be able to associate the correct cache entries with
1328
- * the rename information. 'tree' is always equal to either a_tree or b_tree.
1325
+ * Get the diff_filepairs changed between o_tree and tree.
1326
*/
1330
-static struct string_list *get_renames(struct merge_options *o,
1331
- struct tree *tree,
1332
- struct tree *o_tree,
1333
- struct tree *a_tree,
1334
- struct tree *b_tree,
1335
- struct string_list *entries)
1327
+static struct diff_queue_struct *get_diffpairs(struct merge_options *o,
1328
+ struct tree *o_tree,
1329
+ struct tree *tree)
1330
{
1337
- int i;
1338
- struct string_list *renames;
1331
+ struct diff_queue_struct *ret;
1332
struct diff_options opts;
1333
1341
- renames = xcalloc(1, sizeof(struct string_list));
1342
-
1334
diff_setup(&opts);
1335
opts.flags.recursive = 1;
1336
opts.flags.rename_empty = 0;
@@ -1355,10 +1346,41 @@ static struct string_list *get_renames(struct merge_options *o,
1346
diffcore_std(&opts);
1347
if (opts.needed_rename_limit > o->needed_rename_limit)
1348
o->needed_rename_limit = opts.needed_rename_limit;
1358
- for (i = 0; i < diff_queued_diff.nr; ++i) {
1349
+
1350
+ ret = xmalloc(sizeof(*ret));
1351
+ *ret = diff_queued_diff;
1352
+
1353
+ opts.output_format = DIFF_FORMAT_NO_OUTPUT;
1354
+ diff_queued_diff.nr = 0;
1355
+ diff_queued_diff.queue = NULL;
1356
+ diff_flush(&opts);
1357
+ return ret;
1358
+}
1359
+
1360
+/*
1361
+ * Get information of all renames which occurred in 'pairs', making use of
1362
+ * any implicit directory renames inferred from the other side of history.
1363
+ * We need the three trees in the merge ('o_tree', 'a_tree' and 'b_tree')
1364
+ * to be able to associate the correct cache entries with the rename
1365
+ * information; tree is always equal to either a_tree or b_tree.
1366
+ */
1367
+static struct string_list *get_renames(struct merge_options *o,
1368
+ struct diff_queue_struct *pairs,
1369
+ struct tree *tree,
1370
+ struct tree *o_tree,
1371
+ struct tree *a_tree,
1372
+ struct tree *b_tree,
1373
+ struct string_list *entries)
1374
+{
1375
+ int i;
1376
+ struct string_list *renames;
1377
+
1378
+ renames = xcalloc(1, sizeof(struct string_list));
1379
+
1380
+ for (i = 0; i < pairs->nr; ++i) {
1381
struct string_list_item *item;
1382
struct rename *re;
1361
- struct diff_filepair *pair = diff_queued_diff.queue[i];
1383
+ struct diff_filepair *pair = pairs->queue[i];
1384
1385
if (pair->status != 'R') {
1386
diff_free_filepair(pair);
@@ -1383,9 +1405,6 @@ static struct string_list *get_renames(struct merge_options *o,
1405
item = string_list_insert(renames, pair->one->path);
1406
item->util = re;
1407
}
1386
- opts.output_format = DIFF_FORMAT_NO_OUTPUT;
1387
- diff_queued_diff.nr = 0;
1388
- diff_flush(&opts);
1408
return renames;
1409
}
1410
@@ -1656,15 +1675,36 @@ static int handle_renames(struct merge_options *o,
1675
struct string_list *entries,
1676
struct rename_info *ri)
1677
{
1678
+ struct diff_queue_struct *head_pairs, *merge_pairs;
1679
+ int clean;
1680
+
1681
ri->head_renames = NULL;
1682
ri->merge_renames = NULL;
1683
1684
if (!o->detect_rename)
1685
return 1;
1686
1665
- ri->head_renames = get_renames(o, head, common, head, merge, entries);
1666
- ri->merge_renames = get_renames(o, merge, common, head, merge, entries);
1667
- return process_renames(o, ri->head_renames, ri->merge_renames);
1687
+ head_pairs = get_diffpairs(o, common, head);
1688
+ merge_pairs = get_diffpairs(o, common, merge);
1689
+
1690
+ ri->head_renames = get_renames(o, head_pairs, head,
1691
+ common, head, merge, entries);
1692
+ ri->merge_renames = get_renames(o, merge_pairs, merge,
1693
+ common, head, merge, entries);
1694
+ clean = process_renames(o, ri->head_renames, ri->merge_renames);
1695
+
1696
+ /*
1697
+ * Some cleanup is deferred until cleanup_renames() because the
1698
+ * data structures are still needed and referenced in
1699
+ * process_entry(). But there are a few things we can free now.
1700
+ */
1701
+
1702
+ free(head_pairs->queue);
1703
+ free(head_pairs);
1704
+ free(merge_pairs->queue);
1705
+ free(merge_pairs);
1706
+
1707
+ return clean;
1708
}
1709
1710
static void cleanup_rename(struct string_list *rename)