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 Feb 14, 2018 at 10:51 UTC 84a548dedd6520b73eb8764a8bebd8ede81620c8
1 file changed +13 -10
merge-recursive.c
+13 -10
@@ -1658,6 +1658,12 @@ struct rename_info {
1658 struct string_list *merge_renames;
1659 };
1660
1661 +static void initial_cleanup_rename(struct diff_queue_struct *pairs)
1662 +{
1663 + free(pairs->queue);
1664 + free(pairs);
1665 +}
1666 +
1667 static int handle_renames(struct merge_options *o,
1668 struct tree *common,
1669 struct tree *head,
@@ -1688,16 +1694,13 @@ static int handle_renames(struct merge_options *o,
1694 * data structures are still needed and referenced in
1695 * process_entry(). But there are a few things we can free now.
1696 */
1691 -
1692 - free(head_pairs->queue);
1693 - free(head_pairs);
1694 - free(merge_pairs->queue);
1695 - free(merge_pairs);
1697 + initial_cleanup_rename(head_pairs);
1698 + initial_cleanup_rename(merge_pairs);
1699
1700 return clean;
1701 }
1702
1700 -static void cleanup_rename(struct string_list *rename)
1703 +static void final_cleanup_rename(struct string_list *rename)
1704 {
1705 const struct rename *re;
1706 int i;
@@ -1713,10 +1716,10 @@ static void cleanup_rename(struct string_list *rename)
1716 free(rename);
1717 }
1718
1716 -static void cleanup_renames(struct rename_info *re_info)
1719 +static void final_cleanup_renames(struct rename_info *re_info)
1720 {
1718 - cleanup_rename(re_info->head_renames);
1719 - cleanup_rename(re_info->merge_renames);
1721 + final_cleanup_rename(re_info->head_renames);
1722 + final_cleanup_rename(re_info->merge_renames);
1723 }
1724
1725 static struct object_id *stage_oid(const struct object_id *oid, unsigned mode)
@@ -2119,7 +2122,7 @@ int merge_trees(struct merge_options *o,
2122 }
2123
2124 cleanup:
2122 - cleanup_renames(&re_info);
2125 + final_cleanup_renames(&re_info);
2126
2127 string_list_clear(entries, 1);
2128 free(entries);