submodule: use strvec_pushf() for --submodule-prefix
Add the option --submodule-prefix and its argument directly using strvec_pushf() instead of via a detour through a strbuf. This is shorter, easier to read and doesn't require any explicit cleanup afterwards. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Feb 25, 2024 at 19:24 UTC
9a97b43e035e0770d5bbe1b0afe1c5e80eb05f99
1 file changed
+4
-15
submodule.c
+4
-15
@@ -1687,8 +1687,6 @@ static int get_next_submodule(struct child_process *cp, struct strbuf *err,
1687
task = get_fetch_task_from_changed(spf, err);
1688
1689
if (task) {
1690
- struct strbuf submodule_prefix = STRBUF_INIT;
1691
-
1690
child_process_init(cp);
1691
cp->dir = task->repo->gitdir;
1692
prepare_submodule_repo_env_in_gitdir(&cp->env);
@@ -1698,15 +1696,11 @@ static int get_next_submodule(struct child_process *cp, struct strbuf *err,
1696
strvec_pushv(&cp->args, task->git_args.v);
1697
strvec_pushv(&cp->args, spf->args.v);
1698
strvec_push(&cp->args, task->default_argv);
1701
- strvec_push(&cp->args, "--submodule-prefix");
1699
+ strvec_pushf(&cp->args, "--submodule-prefix=%s%s/",
1700
+ spf->prefix, task->sub->path);
1701
1703
- strbuf_addf(&submodule_prefix, "%s%s/",
1704
- spf->prefix,
1705
- task->sub->path);
1706
- strvec_push(&cp->args, submodule_prefix.buf);
1702
*task_cb = task;
1703
1709
- strbuf_release(&submodule_prefix);
1704
string_list_insert(&spf->seen_submodule_names, task->sub->name);
1705
return 1;
1706
}
@@ -1714,12 +1708,8 @@ static int get_next_submodule(struct child_process *cp, struct strbuf *err,
1708
if (spf->oid_fetch_tasks_nr) {
1709
struct fetch_task *task =
1710
spf->oid_fetch_tasks[spf->oid_fetch_tasks_nr - 1];
1717
- struct strbuf submodule_prefix = STRBUF_INIT;
1711
spf->oid_fetch_tasks_nr--;
1712
1720
- strbuf_addf(&submodule_prefix, "%s%s/",
1721
- spf->prefix, task->sub->path);
1722
-
1713
child_process_init(cp);
1714
prepare_submodule_repo_env_in_gitdir(&cp->env);
1715
cp->git_cmd = 1;
@@ -1728,8 +1718,8 @@ static int get_next_submodule(struct child_process *cp, struct strbuf *err,
1718
strvec_init(&cp->args);
1719
strvec_pushv(&cp->args, spf->args.v);
1720
strvec_push(&cp->args, "on-demand");
1731
- strvec_push(&cp->args, "--submodule-prefix");
1732
- strvec_push(&cp->args, submodule_prefix.buf);
1721
+ strvec_pushf(&cp->args, "--submodule-prefix=%s%s/",
1722
+ spf->prefix, task->sub->path);
1723
1724
/* NEEDSWORK: have get_default_remote from submodule--helper */
1725
strvec_push(&cp->args, "origin");
@@ -1737,7 +1727,6 @@ static int get_next_submodule(struct child_process *cp, struct strbuf *err,
1727
append_oid_to_argv, &cp->args);
1728
1729
*task_cb = task;
1740
- strbuf_release(&submodule_prefix);
1730
return 1;
1731
}
1732