Re: [PATCH 02/10] sequencer.c: split up sequencer_remove_state()
- From
René Scharfe <l.s.r@web.de>
- Date
- Dec 30, 2022, 17:35 UTC
- Message-ID
- <efa1d3d9-03a8-6558-fdfa-ff2d776cdacb@web.de>
- In-Reply-To
- <patch-02.10-4994940a0a9-20221230T071741Z-avarab@gmail.com>
Am 30.12.22 um 08:28 schrieb Ævar Arnfjörð Bjarmason:
Show 8 quoted lines
> 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 changes here are: > > * Changing the "int" to a "size_t", which is the correct type, as > "xopts_nr" is a "size_t".
Good, and you declare it in the for statement, which we can do now!
> > * Calling the free() before the "if (is_rebase_i(opts) && ...)", > which is OK, and makes a subsequent change smaller.
It's true that is_rebase_i() can be called after all that free()ing; here is its definition:
static inline int is_rebase_i(const struct replay_opts *opts)
{
return opts->action == REPLAY_INTERACTIVE_REBASE;
}But why? Making a subsequent change smaller is just a trivial fact if you do a part if it earlier, but that in itself is not a valid reason for the reordering.
And I can't find that patch -- sequencer_remove_state() is not touched again in this series.
Show 52 quoted lines
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
> sequencer.c | 25 +++++++++++++++----------
> 1 file changed, 15 insertions(+), 10 deletions(-)
>
> diff --git a/sequencer.c b/sequencer.c
> index bcb662e23be..655ae9f1a72 100644
> --- a/sequencer.c
> +++ b/sequencer.c
> @@ -351,10 +351,24 @@ static const char *gpg_sign_opt_quoted(struct replay_opts *opts)
> return buf.buf;
> }
>
> +static void replay_opts_release(struct replay_opts *opts)
> +{
> + free(opts->gpg_sign);
> + free(opts->reflog_action);
> + free(opts->default_strategy);
> + free(opts->strategy);
> + for (size_t i = 0; i < opts->xopts_nr; i++)
> + free(opts->xopts[i]);
> + free(opts->xopts);
> + strbuf_release(&opts->current_fixups);
> +}
> +
> int sequencer_remove_state(struct replay_opts *opts)
> {
> struct strbuf buf = STRBUF_INIT;
> - int i, ret = 0;
> + int ret = 0;
> +
> + replay_opts_release(opts);
>
> if (is_rebase_i(opts) &&
> strbuf_read_file(&buf, rebase_path_refs_to_delete(), 0) > 0) {
> @@ -373,15 +387,6 @@ int sequencer_remove_state(struct replay_opts *opts)
> }
> }
>
> - free(opts->gpg_sign);
> - free(opts->reflog_action);
> - free(opts->default_strategy);
> - free(opts->strategy);
> - for (i = 0; i < opts->xopts_nr; i++)
> - free(opts->xopts[i]);
> - free(opts->xopts);
> - strbuf_release(&opts->current_fixups);
> -
> strbuf_reset(&buf);
> strbuf_addstr(&buf, get_dir(opts));
> if (remove_dir_recursively(&buf, 0))