merge-ort: add a clear_internal_opts helper

Move most of merge_finalize() into a new helper function, clear_internal_opts(). This is a step to facilitate recursive merges, as well as some future optimizations. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Dec 3, 2020 at 15:59 UTC 101bc5bc2d73484d288a43fdcf1c00bc04b080e4
1 file changed +24 -16
merge-ort.c
+24 -16
@@ -221,6 +221,29 @@ static void free_strmap_strings(struct strmap *map)
221 }
222 }
223
224 +static void clear_internal_opts(struct merge_options_internal *opti,
225 + int reinitialize)
226 +{
227 + assert(!reinitialize);
228 +
229 + /*
230 + * We marked opti->paths with strdup_strings = 0, so that we
231 + * wouldn't have to make another copy of the fullpath created by
232 + * make_traverse_path from setup_path_info(). But, now that we've
233 + * used it and have no other references to these strings, it is time
234 + * to deallocate them.
235 + */
236 + free_strmap_strings(&opti->paths);
237 + strmap_clear(&opti->paths, 1);
238 +
239 + /*
240 + * All keys and values in opti->conflicted are a subset of those in
241 + * opti->paths. We don't want to deallocate anything twice, so we
242 + * don't free the keys and we pass 0 for free_values.
243 + */
244 + strmap_clear(&opti->conflicted, 0);
245 +}
246 +
247 static int err(struct merge_options *opt, const char *err, ...)
248 {
249 va_list params;
@@ -1169,22 +1192,7 @@ void merge_finalize(struct merge_options *opt,
1192
1193 assert(opt->priv == NULL);
1194
1172 - /*
1173 - * We marked opti->paths with strdup_strings = 0, so that we
1174 - * wouldn't have to make another copy of the fullpath created by
1175 - * make_traverse_path from setup_path_info(). But, now that we've
1176 - * used it and have no other references to these strings, it is time
1177 - * to deallocate them.
1178 - */
1179 - free_strmap_strings(&opti->paths);
1180 - strmap_clear(&opti->paths, 1);
1181 -
1182 - /*
1183 - * All keys and values in opti->conflicted are a subset of those in
1184 - * opti->paths. We don't want to deallocate anything twice, so we
1185 - * don't free the keys and we pass 0 for free_values.
1186 - */
1187 - strmap_clear(&opti->conflicted, 0);
1195 + clear_internal_opts(opti, 0);
1196 FREE_AND_NULL(opti);
1197 }
1198