[PATCH v2 20/24] submodule--helper: add skeleton "goto cleanup" to update_submodule()
- From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
- Date
- Jul 19, 2022, 20:47 UTC
- Message-ID
- <patch-v2-20.24-7882e33cdca-20220719T204458Z-avarab@gmail.com>
- In-Reply-To
- <cover-v2-00.24-00000000000-20220719T204458Z-avarab@gmail.com>
Add a skeleton "goto cleanup" pattern to update_submodule(), rather than having branches in it "return". This is in preparation for doing something useful with the "cleanup" label, but for now we're using it as the equivalent of a "done" label.
The "exit()" branch is not handled yet, and neither is the exit() that run_update_procedure() might invoke. That'll be handled in a subsequent commit.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- builtin/submodule--helper.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-)
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 900f89f549d..3b0f46ad3f6 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2544,6 +2544,8 @@ static void update_data_to_args(struct update_data *update_data, struct strvec * static int update_submodule(struct update_data *update_data) { + int ret; + ensure_core_worktree(update_data->sm_path); update_data->displaypath = get_submodule_displaypath( @@ -2580,14 +2582,17 @@ static int update_submodule(struct update_data *update_data) free(remote_ref); } - if (!oideq(&update_data->oid, &update_data->suboid) || update_data->force) - if (run_update_procedure(update_data)) - return 1; + if (!oideq(&update_data->oid, &update_data->suboid) || update_data->force) { + ret = run_update_procedure(update_data); + if (ret) { + ret = 1; + goto cleanup; + } + } if (update_data->recursive) { struct child_process cp = CHILD_PROCESS_INIT; struct update_data next = *update_data; - int ret; next.prefix = NULL; oidcpy(&next.oid, null_oid()); @@ -2601,16 +2606,20 @@ static int update_submodule(struct update_data *update_data) /* die() if child process die()'d */ ret = run_command(&cp); if (!ret) - return 0; + goto cleanup; die_message(_("Failed to recurse into submodule path '%s'"), update_data->displaypath); - if (ret == 128) + if (ret == 128) { exit(ret); - else if (ret) - return 1; + } else if (ret) { + ret = 1; + goto cleanup; + } } - return 0; + ret = 0; +cleanup: + return ret; } static int update_submodules(struct update_data *update_data)
-- 2.37.1.1062.g385eac7fccf