merge-ort: extract handling of priv member into reusable function

In preparation for a subsequent commit which will ensure we do not forget to maintain our invariants for the priv member in error codepaths, extract the necessary functionality out into a separate function. This change is cosmetic at this point, and introduces no changes beyond an extra assertion sanity check. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Jun 19, 2024 at 03:00 UTC e79bdb426c7033cf431cd5cb628196fd19303da0
1 file changed +22 -5
merge-ort.c
+22 -5
@@ -5000,6 +5000,26 @@ static void merge_check_renames_reusable(struct merge_result *result,
5000
5001 /*** Function Grouping: merge_incore_*() and their internal variants ***/
5002
5003 +static void move_opt_priv_to_result_priv(struct merge_options *opt,
5004 + struct merge_result *result)
5005 +{
5006 + /*
5007 + * opt->priv and result->priv are a bit weird. opt->priv contains
5008 + * information that we can re-use in subsequent merge operations to
5009 + * enable our cached renames optimization. The best way to provide
5010 + * that to subsequent merges is putting it in result->priv.
5011 + * However, putting it directly there would mean retrofitting lots
5012 + * of functions in this file to also take a merge_result pointer,
5013 + * which is ugly and annoying. So, we just make sure at the end of
5014 + * the merge (the outer merge if there are internal recursive ones)
5015 + * to move it.
5016 + */
5017 + assert(opt->priv && !result->priv);
5018 + result->priv = opt->priv;
5019 + result->_properly_initialized = RESULT_INITIALIZED;
5020 + opt->priv = NULL;
5021 +}
5022 +
5023 /*
5024 * Originally from merge_trees_internal(); heavily adapted, though.
5025 */
@@ -5060,11 +5080,8 @@ redo:
5080 /* existence of conflicted entries implies unclean */
5081 result->clean &= strmap_empty(&opt->priv->conflicted);
5082 }
5063 - if (!opt->priv->call_depth) {
5064 - result->priv = opt->priv;
5065 - result->_properly_initialized = RESULT_INITIALIZED;
5066 - opt->priv = NULL;
5067 - }
5083 + if (!opt->priv->call_depth)
5084 + move_opt_priv_to_result_priv(opt, result);
5085 }
5086
5087 /*