From 9bdf5277d5989d128469847b7b88ff20077e6d43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Thu, 1 Sep 2022 01:17:55 +0200 Subject: [PATCH] submodule--helper: move "sb" in clone_submodule() to its own scope MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refactor the only remaining use of a "struct strbuf sb" in clone_submodule() to live in its own scope. This makes the code clearer by limiting its lifetime. Signed-off-by: Ævar Arnfjörð Bjarmason Reviewed-by: Glen Choo Signed-off-by: Junio C Hamano --- builtin/submodule--helper.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 63008970f1..fe32abd45e 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1557,17 +1557,25 @@ static void prepare_possible_alternates(const char *sm_name, free(error_strategy); } +static char *clone_submodule_sm_gitdir(const char *name) +{ + struct strbuf sb = STRBUF_INIT; + char *sm_gitdir; + + submodule_name_to_gitdir(&sb, the_repository, name); + sm_gitdir = absolute_pathdup(sb.buf); + strbuf_release(&sb); + + return sm_gitdir; +} + static int clone_submodule(struct module_clone_data *clone_data) { - char *p, *sm_gitdir; + char *p; + char *sm_gitdir = clone_submodule_sm_gitdir(clone_data->name); char *sm_alternate = NULL, *error_strategy = NULL; - struct strbuf sb = STRBUF_INIT; struct child_process cp = CHILD_PROCESS_INIT; - submodule_name_to_gitdir(&sb, the_repository, clone_data->name); - sm_gitdir = absolute_pathdup(sb.buf); - strbuf_reset(&sb); - if (!is_absolute_path(clone_data->path)) clone_data->path = xstrfmt("%s/%s", get_git_work_tree(), clone_data->path); @@ -1655,7 +1663,6 @@ static int clone_submodule(struct module_clone_data *clone_data) free(sm_alternate); free(error_strategy); - strbuf_release(&sb); free(sm_gitdir); free(p); return 0;