Skip to content

Commit f172589

Browse files
newrengitster
authored andcommitted
merge-recursive: introduce new functions to handle rename logic
The amount of logic in merge_trees() relative to renames was just a few lines, but split it out into new handle_renames() and cleanup_renames() functions to prepare for additional logic to be added to each. No code or logic changes, just a new place to put stuff for when the rename detection gains additional checks. Note that process_renames() records pointers to various information (such as diff_filepairs) into rename_conflict_info structs. Even though the rename string_lists are not directly used once handle_renames() completes, we should not immediately free the lists at the end of that function because they store the information referenced in the rename_conflict_info, which is used later in process_entry(). Thus the reason for a separate cleanup_renames(). Reviewed-by: Stefan Beller <[email protected]> Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9ba9155 commit f172589

File tree

1 file changed

+33
-10
lines changed

1 file changed

+33
-10
lines changed

merge-recursive.c

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,6 +1646,32 @@ static int process_renames(struct merge_options *o,
16461646
return clean_merge;
16471647
}
16481648

1649+
struct rename_info {
1650+
struct string_list *head_renames;
1651+
struct string_list *merge_renames;
1652+
};
1653+
1654+
static int handle_renames(struct merge_options *o,
1655+
struct tree *common,
1656+
struct tree *head,
1657+
struct tree *merge,
1658+
struct string_list *entries,
1659+
struct rename_info *ri)
1660+
{
1661+
ri->head_renames = get_renames(o, head, common, head, merge, entries);
1662+
ri->merge_renames = get_renames(o, merge, common, head, merge, entries);
1663+
return process_renames(o, ri->head_renames, ri->merge_renames);
1664+
}
1665+
1666+
static void cleanup_renames(struct rename_info *re_info)
1667+
{
1668+
string_list_clear(re_info->head_renames, 0);
1669+
string_list_clear(re_info->merge_renames, 0);
1670+
1671+
free(re_info->head_renames);
1672+
free(re_info->merge_renames);
1673+
}
1674+
16491675
static struct object_id *stage_oid(const struct object_id *oid, unsigned mode)
16501676
{
16511677
return (is_null_oid(oid) || mode == 0) ? NULL: (struct object_id *)oid;
@@ -2005,7 +2031,8 @@ int merge_trees(struct merge_options *o,
20052031
}
20062032

20072033
if (unmerged_cache()) {
2008-
struct string_list *entries, *re_head, *re_merge;
2034+
struct string_list *entries;
2035+
struct rename_info re_info;
20092036
int i;
20102037
/*
20112038
* Only need the hashmap while processing entries, so
@@ -2019,9 +2046,8 @@ int merge_trees(struct merge_options *o,
20192046
get_files_dirs(o, merge);
20202047

20212048
entries = get_unmerged();
2022-
re_head = get_renames(o, head, common, head, merge, entries);
2023-
re_merge = get_renames(o, merge, common, head, merge, entries);
2024-
clean = process_renames(o, re_head, re_merge);
2049+
clean = handle_renames(o, common, head, merge, entries,
2050+
&re_info);
20252051
record_df_conflict_files(o, entries);
20262052
if (clean < 0)
20272053
goto cleanup;
@@ -2046,16 +2072,13 @@ int merge_trees(struct merge_options *o,
20462072
}
20472073

20482074
cleanup:
2049-
string_list_clear(re_merge, 0);
2050-
string_list_clear(re_head, 0);
2075+
cleanup_renames(&re_info);
2076+
20512077
string_list_clear(entries, 1);
2078+
free(entries);
20522079

20532080
hashmap_free(&o->current_file_dir_set, 1);
20542081

2055-
free(re_merge);
2056-
free(re_head);
2057-
free(entries);
2058-
20592082
if (clean < 0)
20602083
return clean;
20612084
}

0 commit comments

Comments
 (0)