submodule--helper: use xstrfmt() in clone_submodule()
Use xstrfmt() in clone_submodule() instead of a "struct strbuf" in two cases where we weren't getting anything out of using the "struct strbuf". This changes code that was was added along with other uses of "struct strbuf" in this function in ee8838d1577 (submodule: rewrite `module_clone` shell function in C, 2015-09-08). 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
21496b4c60b2327417c63fc9762096037a185be3
1 file changed
+9
-8
builtin/submodule--helper.c
+9
-8
@@ -1568,12 +1568,11 @@ static int clone_submodule(struct module_clone_data *clone_data)
1568
sm_gitdir = absolute_pathdup(sb.buf);
1569
strbuf_reset(&sb);
1570
1571
- if (!is_absolute_path(clone_data->path)) {
1572
- strbuf_addf(&sb, "%s/%s", get_git_work_tree(), clone_data->path);
1573
- clone_data->path = strbuf_detach(&sb, NULL);
1574
- } else {
1571
+ if (!is_absolute_path(clone_data->path))
1572
+ clone_data->path = xstrfmt("%s/%s", get_git_work_tree(),
1573
+ clone_data->path);
1574
+ else
1575
clone_data->path = xstrdup(clone_data->path);
1576
- }
1576
1577
if (validate_submodule_git_dir(sm_gitdir, clone_data->name) < 0)
1578
die(_("refusing to create/use '%s' in another submodule's "
@@ -1625,14 +1624,16 @@ static int clone_submodule(struct module_clone_data *clone_data)
1624
die(_("clone of '%s' into submodule path '%s' failed"),
1625
clone_data->url, clone_data->path);
1626
} else {
1627
+ char *path;
1628
+
1629
if (clone_data->require_init && !access(clone_data->path, X_OK) &&
1630
!is_empty_dir(clone_data->path))
1631
die(_("directory not empty: '%s'"), clone_data->path);
1632
if (safe_create_leading_directories_const(clone_data->path) < 0)
1633
die(_("could not create directory '%s'"), clone_data->path);
1633
- strbuf_addf(&sb, "%s/index", sm_gitdir);
1634
- unlink_or_warn(sb.buf);
1635
- strbuf_reset(&sb);
1634
+ path = xstrfmt("%s/index", sm_gitdir);
1635
+ unlink_or_warn(path);
1636
+ free(path);
1637
}
1638
1639
connect_work_tree_and_git_dir(clone_data->path, sm_gitdir, 0);