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>
Ævar Arnfjörð Bjarmason committed
Sep 1, 2022 at 01:17 UTC
9bdf5277d5989d128469847b7b88ff20077e6d43
1 file changed
+14
-7
builtin/submodule--helper.c
+14
-7
@@ -1557,16 +1557,24 @@ static void prepare_possible_alternates(const char *sm_name,
1557
free(error_strategy);
1558
}
1559
1560
-static int clone_submodule(struct module_clone_data *clone_data)
1560
+static char *clone_submodule_sm_gitdir(const char *name)
1561
{
1562
- char *p, *sm_gitdir;
1563
- char *sm_alternate = NULL, *error_strategy = NULL;
1562
struct strbuf sb = STRBUF_INIT;
1565
- struct child_process cp = CHILD_PROCESS_INIT;
1563
+ char *sm_gitdir;
1564
1567
- submodule_name_to_gitdir(&sb, the_repository, clone_data->name);
1565
+ submodule_name_to_gitdir(&sb, the_repository, name);
1566
sm_gitdir = absolute_pathdup(sb.buf);
1569
- strbuf_reset(&sb);
1567
+ strbuf_release(&sb);
1568
+
1569
+ return sm_gitdir;
1570
+}
1571
+
1572
+static int clone_submodule(struct module_clone_data *clone_data)
1573
+{
1574
+ char *p;
1575
+ char *sm_gitdir = clone_submodule_sm_gitdir(clone_data->name);
1576
+ char *sm_alternate = NULL, *error_strategy = NULL;
1577
+ struct child_process cp = CHILD_PROCESS_INIT;
1578
1579
if (!is_absolute_path(clone_data->path))
1580
clone_data->path = xstrfmt("%s/%s", get_git_work_tree(),
@@ -1655,7 +1663,6 @@ static int clone_submodule(struct module_clone_data *clone_data)
1663
free(sm_alternate);
1664
free(error_strategy);
1665
1658
- strbuf_release(&sb);
1666
free(sm_gitdir);
1667
free(p);
1668
return 0;