sequencer.c: split up sequencer_remove_state()

Split off the free()-ing in sequencer_remove_state() into a utility function, which will be adjusted and called independent of the other code in sequencer_remove_state() in a subsequent commit. The only functional change here is changing the "int" to a "size_t", which is the correct type, as "xopts_nr" is a "size_t". Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Feb 6, 2023 at 20:08 UTC 6a09c3a9a69fa2059383dd94294bbfd44b440d4b
1 file changed +14 -9
sequencer.c
+14 -9
@@ -351,10 +351,22 @@ static const char *gpg_sign_opt_quoted(struct replay_opts *opts)
351 return buf.buf;
352 }
353
354 +static void replay_opts_release(struct replay_opts *opts)
355 +{
356 + free(opts->gpg_sign);
357 + free(opts->reflog_action);
358 + free(opts->default_strategy);
359 + free(opts->strategy);
360 + for (size_t i = 0; i < opts->xopts_nr; i++)
361 + free(opts->xopts[i]);
362 + free(opts->xopts);
363 + strbuf_release(&opts->current_fixups);
364 +}
365 +
366 int sequencer_remove_state(struct replay_opts *opts)
367 {
368 struct strbuf buf = STRBUF_INIT;
357 - int i, ret = 0;
369 + int ret = 0;
370
371 if (is_rebase_i(opts) &&
372 strbuf_read_file(&buf, rebase_path_refs_to_delete(), 0) > 0) {
@@ -373,14 +385,7 @@ int sequencer_remove_state(struct replay_opts *opts)
385 }
386 }
387
376 - free(opts->gpg_sign);
377 - free(opts->reflog_action);
378 - free(opts->default_strategy);
379 - free(opts->strategy);
380 - for (i = 0; i < opts->xopts_nr; i++)
381 - free(opts->xopts[i]);
382 - free(opts->xopts);
383 - strbuf_release(&opts->current_fixups);
388 + replay_opts_release(opts);
389
390 strbuf_reset(&buf);
391 strbuf_addstr(&buf, get_dir(opts));