revisions API users: add "goto cleanup" for release_revisions()

Add a release_revisions() to various users of "struct rev_info" which
requires a minor refactoring to a "goto cleanup" pattern to use that
function.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Ævar Arnfjörð Bjarmason
2022-04-13 22:01:40 +02:00
committed by Junio C Hamano
parent 5e480176fe
commit 0139c58ab9
6 changed files with 55 additions and 24 deletions

View File

@ -99,6 +99,7 @@ int cmd__fast_rebase(int argc, const char **argv)
struct merge_result result;
struct strbuf reflog_msg = STRBUF_INIT;
struct strbuf branch_name = STRBUF_INIT;
int ret = 0;
/*
* test-tool stuff doesn't set up the git directory by default; need to
@ -137,13 +138,17 @@ int cmd__fast_rebase(int argc, const char **argv)
revs.topo_order = 1;
strvec_pushl(&rev_walk_args, "", argv[4], "--not", argv[3], NULL);
if (setup_revisions(rev_walk_args.nr, rev_walk_args.v, &revs, NULL) > 1)
return error(_("unhandled options"));
if (setup_revisions(rev_walk_args.nr, rev_walk_args.v, &revs, NULL) > 1) {
ret = error(_("unhandled options"));
goto cleanup;
}
strvec_clear(&rev_walk_args);
if (prepare_revision_walk(&revs) < 0)
return error(_("error preparing revisions"));
if (prepare_revision_walk(&revs) < 0) {
ret = error(_("error preparing revisions"));
goto cleanup;
}
init_merge_options(&merge_opt, the_repository);
memset(&result, 0, sizeof(result));
@ -220,7 +225,10 @@ int cmd__fast_rebase(int argc, const char **argv)
COMMIT_LOCK | SKIP_IF_UNCHANGED))
die(_("unable to write %s"), get_index_file());
ret = (result.clean == 0);
cleanup:
strbuf_release(&reflog_msg);
strbuf_release(&branch_name);
return (result.clean == 0);
release_revisions(&revs);
return ret;
}