merge-recursive: make a helper function for cleanup for handle_renames

In anticipation of more involved cleanup to come, make a helper function for doing the cleanup at the end of handle_renames. Rename the already existing cleanup_rename[s]() to final_cleanup_rename[s](), name the new helper initial_cleanup_rename(), and leave the big comment in the code about why we can't do all the cleanup at once. 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 ffc16c490ad533bc07e6d8ec0226b426166e8442
1 file changed +13 -10
merge-recursive.c
+13 -10
@@ -1668,6 +1668,12 @@ struct rename_info {
1668 struct string_list *merge_renames;
1669 };
1670
1671 +static void initial_cleanup_rename(struct diff_queue_struct *pairs)
1672 +{
1673 + free(pairs->queue);
1674 + free(pairs);
1675 +}
1676 +
1677 static int handle_renames(struct merge_options *o,
1678 struct tree *common,
1679 struct tree *head,
@@ -1698,16 +1704,13 @@ static int handle_renames(struct merge_options *o,
1704 * data structures are still needed and referenced in
1705 * process_entry(). But there are a few things we can free now.
1706 */
1701 -
1702 - free(head_pairs->queue);
1703 - free(head_pairs);
1704 - free(merge_pairs->queue);
1705 - free(merge_pairs);
1707 + initial_cleanup_rename(head_pairs);
1708 + initial_cleanup_rename(merge_pairs);
1709
1710 return clean;
1711 }
1712
1710 -static void cleanup_rename(struct string_list *rename)
1713 +static void final_cleanup_rename(struct string_list *rename)
1714 {
1715 const struct rename *re;
1716 int i;
@@ -1723,10 +1726,10 @@ static void cleanup_rename(struct string_list *rename)
1726 free(rename);
1727 }
1728
1726 -static void cleanup_renames(struct rename_info *re_info)
1729 +static void final_cleanup_renames(struct rename_info *re_info)
1730 {
1728 - cleanup_rename(re_info->head_renames);
1729 - cleanup_rename(re_info->merge_renames);
1731 + final_cleanup_rename(re_info->head_renames);
1732 + final_cleanup_rename(re_info->merge_renames);
1733 }
1734
1735 static struct object_id *stage_oid(const struct object_id *oid, unsigned mode)
@@ -2129,7 +2132,7 @@ int merge_trees(struct merge_options *o,
2132 }
2133
2134 cleanup:
2132 - cleanup_renames(&re_info);
2135 + final_cleanup_renames(&re_info);
2136
2137 string_list_clear(entries, 1);
2138 free(entries);