Skip to content

Commit 01fd5fb

Browse files
avargitster
authored andcommitted
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 53bbcfb (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a6a323b commit 01fd5fb

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

builtin/rebase.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -254,24 +254,20 @@ static int init_basic_state(struct replay_opts *opts, const char *head_name,
254254

255255
static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
256256
{
257-
int ret;
257+
int ret = -1;
258258
char *revisions = NULL, *shortrevisions = NULL;
259259
struct strvec make_script_args = STRVEC_INIT;
260260
struct todo_list todo_list = TODO_LIST_INIT;
261261
struct replay_opts replay = get_replay_opts(opts);
262262

263263
if (get_revision_ranges(opts->upstream, opts->onto, &opts->orig_head->object.oid,
264264
&revisions, &shortrevisions))
265-
return -1;
265+
goto cleanup;
266266

267267
if (init_basic_state(&replay,
268268
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;
275271

276272
if (!opts->upstream && opts->squash_onto)
277273
write_file(path_squash_onto(), "%s\n",
@@ -300,6 +296,7 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
300296
opts->autosquash, opts->update_refs, &todo_list);
301297
}
302298

299+
cleanup:
303300
free(revisions);
304301
free(shortrevisions);
305302
todo_list_release(&todo_list);

0 commit comments

Comments
 (0)