summaryrefslogtreecommitdiff
path: root/builtin/submodule--helper.c
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2022-08-31 23:17:55 (GMT)
committerJunio C Hamano <gitster@pobox.com>2022-09-02 16:16:23 (GMT)
commit9bdf5277d5989d128469847b7b88ff20077e6d43 (patch)
tree0fac4301c2ee67ded0141ad216668cd4ffa5a1a9 /builtin/submodule--helper.c
parent21496b4c60b2327417c63fc9762096037a185be3 (diff)
downloadgit-9bdf5277d5989d128469847b7b88ff20077e6d43.zip
git-9bdf5277d5989d128469847b7b88ff20077e6d43.tar.gz
git-9bdf5277d5989d128469847b7b88ff20077e6d43.tar.bz2
submodule--helper: move "sb" in clone_submodule() to its own scope
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 <avarab@gmail.com> Reviewed-by: Glen Choo <chooglen@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/submodule--helper.c')
-rw-r--r--builtin/submodule--helper.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 6300897..fe32abd 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1557,16 +1557,24 @@ static void prepare_possible_alternates(const char *sm_name,
free(error_strategy);
}
-static int clone_submodule(struct module_clone_data *clone_data)
+static char *clone_submodule_sm_gitdir(const char *name)
{
- char *p, *sm_gitdir;
- char *sm_alternate = NULL, *error_strategy = NULL;
struct strbuf sb = STRBUF_INIT;
- struct child_process cp = CHILD_PROCESS_INIT;
+ char *sm_gitdir;
- submodule_name_to_gitdir(&sb, the_repository, clone_data->name);
+ submodule_name_to_gitdir(&sb, the_repository, name);
sm_gitdir = absolute_pathdup(sb.buf);
- strbuf_reset(&sb);
+ strbuf_release(&sb);
+
+ return sm_gitdir;
+}
+
+static int clone_submodule(struct module_clone_data *clone_data)
+{
+ char *p;
+ char *sm_gitdir = clone_submodule_sm_gitdir(clone_data->name);
+ char *sm_alternate = NULL, *error_strategy = NULL;
+ struct child_process cp = CHILD_PROCESS_INIT;
if (!is_absolute_path(clone_data->path))
clone_data->path = xstrfmt("%s/%s", get_git_work_tree(),
@@ -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;