]> git.ipfire.org Git - thirdparty/git.git/commitdiff
submodule--helper: use xstrfmt() in clone_submodule()
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Wed, 31 Aug 2022 23:17:54 +0000 (01:17 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 2 Sep 2022 16:16:23 +0000 (09:16 -0700)
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>
builtin/submodule--helper.c

index 60165a848a205349f973ef3cc52dcfe7b1c39c74..63008970f1c56b679f0f68c855d6718914a6c939 100644 (file)
@@ -1568,12 +1568,11 @@ static int clone_submodule(struct module_clone_data *clone_data)
        sm_gitdir = absolute_pathdup(sb.buf);
        strbuf_reset(&sb);
 
-       if (!is_absolute_path(clone_data->path)) {
-               strbuf_addf(&sb, "%s/%s", get_git_work_tree(), clone_data->path);
-               clone_data->path = strbuf_detach(&sb, NULL);
-       } else {
+       if (!is_absolute_path(clone_data->path))
+               clone_data->path = xstrfmt("%s/%s", get_git_work_tree(),
+                                          clone_data->path);
+       else
                clone_data->path = xstrdup(clone_data->path);
-       }
 
        if (validate_submodule_git_dir(sm_gitdir, clone_data->name) < 0)
                die(_("refusing to create/use '%s' in another submodule's "
@@ -1625,14 +1624,16 @@ static int clone_submodule(struct module_clone_data *clone_data)
                        die(_("clone of '%s' into submodule path '%s' failed"),
                            clone_data->url, clone_data->path);
        } else {
+               char *path;
+
                if (clone_data->require_init && !access(clone_data->path, X_OK) &&
                    !is_empty_dir(clone_data->path))
                        die(_("directory not empty: '%s'"), clone_data->path);
                if (safe_create_leading_directories_const(clone_data->path) < 0)
                        die(_("could not create directory '%s'"), clone_data->path);
-               strbuf_addf(&sb, "%s/index", sm_gitdir);
-               unlink_or_warn(sb.buf);
-               strbuf_reset(&sb);
+               path = xstrfmt("%s/index", sm_gitdir);
+               unlink_or_warn(path);
+               free(path);
        }
 
        connect_work_tree_and_git_dir(clone_data->path, sm_gitdir, 0);