rebase: use "cleanup" pattern in do_interactive_rebase()

Use a "goto cleanup" pattern in do_interactive_rebase(). This eliminates some duplicated free() code added in 53bbcfbde7c (rebase -i: implement the main part of interactive rebase as a builtin, 2018-09-27), and sets us up for a subsequent commit which'll make further use of the "cleanup" label. 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 01fd5fb14b4f2a910679cf2ac672ff6b1d742f19
1 file changed +5 -8
builtin/rebase.c
+5 -8
@@ -254,7 +254,7 @@ static int init_basic_state(struct replay_opts *opts, const char *head_name,
254
255 static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
256 {
257 - int ret;
257 + int ret = -1;
258 char *revisions = NULL, *shortrevisions = NULL;
259 struct strvec make_script_args = STRVEC_INIT;
260 struct todo_list todo_list = TODO_LIST_INIT;
@@ -262,16 +262,12 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
262
263 if (get_revision_ranges(opts->upstream, opts->onto, &opts->orig_head->object.oid,
264 &revisions, &shortrevisions))
265 - return -1;
265 + goto cleanup;
266
267 if (init_basic_state(&replay,
268 opts->head_name ? opts->head_name : "detached HEAD",
269 - opts->onto, &opts->orig_head->object.oid)) {
270 - free(revisions);
271 - free(shortrevisions);
272 -
273 - return -1;
274 - }
269 + opts->onto, &opts->orig_head->object.oid))
270 + goto cleanup;
271
272 if (!opts->upstream && opts->squash_onto)
273 write_file(path_squash_onto(), "%s\n",
@@ -300,6 +296,7 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
296 opts->autosquash, opts->update_refs, &todo_list);
297 }
298
299 +cleanup:
300 free(revisions);
301 free(shortrevisions);
302 todo_list_release(&todo_list);