Skip to content

Commit 3f64687

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 e7f04a3 commit 3f64687

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
@@ -1312,24 +1312,15 @@ static int conflict_rename_rename_2to1(struct merge_options *o,
13121312
}
13131313

13141314
/*
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.
13191316
*/
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)
13261320
{
1327-
int i;
1328-
struct string_list *renames;
1321+
struct diff_queue_struct *ret;
13291322
struct diff_options opts;
13301323

1331-
renames = xcalloc(1, sizeof(struct string_list));
1332-
13331324
diff_setup(&opts);
13341325
opts.flags.recursive = 1;
13351326
opts.flags.rename_empty = 0;
@@ -1345,10 +1336,41 @@ static struct string_list *get_renames(struct merge_options *o,
13451336
diffcore_std(&opts);
13461337
if (opts.needed_rename_limit > o->needed_rename_limit)
13471338
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) {
13491371
struct string_list_item *item;
13501372
struct rename *re;
1351-
struct diff_filepair *pair = diff_queued_diff.queue[i];
1373+
struct diff_filepair *pair = pairs->queue[i];
13521374

13531375
if (pair->status != 'R') {
13541376
diff_free_filepair(pair);
@@ -1373,9 +1395,6 @@ static struct string_list *get_renames(struct merge_options *o,
13731395
item = string_list_insert(renames, pair->one->path);
13741396
item->util = re;
13751397
}
1376-
opts.output_format = DIFF_FORMAT_NO_OUTPUT;
1377-
diff_queued_diff.nr = 0;
1378-
diff_flush(&opts);
13791398
return renames;
13801399
}
13811400

@@ -1646,15 +1665,36 @@ static int handle_renames(struct merge_options *o,
16461665
struct string_list *entries,
16471666
struct rename_info *ri)
16481667
{
1668+
struct diff_queue_struct *head_pairs, *merge_pairs;
1669+
int clean;
1670+
16491671
ri->head_renames = NULL;
16501672
ri->merge_renames = NULL;
16511673

16521674
if (!o->detect_rename)
16531675
return 1;
16541676

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;
16581698
}
16591699

16601700
static void cleanup_rename(struct string_list *rename)

0 commit comments

Comments
 (0)