Skip to content

Commit e5257b2

Browse files
newrengitster
authored andcommitted
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 <[email protected]> Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3992ff0 commit e5257b2

File tree

1 file changed

+62
-22
lines changed

1 file changed

+62
-22
lines changed

merge-recursive.c

Lines changed: 62 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,24 +1322,15 @@ static int conflict_rename_rename_2to1(struct merge_options *o,
13221322
}
13231323

13241324
/*
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.
13291326
*/
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)
13361330
{
1337-
int i;
1338-
struct string_list *renames;
1331+
struct diff_queue_struct *ret;
13391332
struct diff_options opts;
13401333

1341-
renames = xcalloc(1, sizeof(struct string_list));
1342-
13431334
diff_setup(&opts);
13441335
opts.flags.recursive = 1;
13451336
opts.flags.rename_empty = 0;
@@ -1355,10 +1346,41 @@ static struct string_list *get_renames(struct merge_options *o,
13551346
diffcore_std(&opts);
13561347
if (opts.needed_rename_limit > o->needed_rename_limit)
13571348
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) {
13591381
struct string_list_item *item;
13601382
struct rename *re;
1361-
struct diff_filepair *pair = diff_queued_diff.queue[i];
1383+
struct diff_filepair *pair = pairs->queue[i];
13621384

13631385
if (pair->status != 'R') {
13641386
diff_free_filepair(pair);
@@ -1383,9 +1405,6 @@ static struct string_list *get_renames(struct merge_options *o,
13831405
item = string_list_insert(renames, pair->one->path);
13841406
item->util = re;
13851407
}
1386-
opts.output_format = DIFF_FORMAT_NO_OUTPUT;
1387-
diff_queued_diff.nr = 0;
1388-
diff_flush(&opts);
13891408
return renames;
13901409
}
13911410

@@ -1656,15 +1675,36 @@ static int handle_renames(struct merge_options *o,
16561675
struct string_list *entries,
16571676
struct rename_info *ri)
16581677
{
1678+
struct diff_queue_struct *head_pairs, *merge_pairs;
1679+
int clean;
1680+
16591681
ri->head_renames = NULL;
16601682
ri->merge_renames = NULL;
16611683

16621684
if (!o->detect_rename)
16631685
return 1;
16641686

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;
16681708
}
16691709

16701710
static void cleanup_rename(struct string_list *rename)

0 commit comments

Comments
 (0)