Skip to content

Commit 9a97b43

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3c2a3fd commit 9a97b43

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

submodule.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,8 +1687,6 @@ static int get_next_submodule(struct child_process *cp, struct strbuf *err,
16871687
task = get_fetch_task_from_changed(spf, err);
16881688

16891689
if (task) {
1690-
struct strbuf submodule_prefix = STRBUF_INIT;
1691-
16921690
child_process_init(cp);
16931691
cp->dir = task->repo->gitdir;
16941692
prepare_submodule_repo_env_in_gitdir(&cp->env);
@@ -1698,28 +1696,20 @@ static int get_next_submodule(struct child_process *cp, struct strbuf *err,
16981696
strvec_pushv(&cp->args, task->git_args.v);
16991697
strvec_pushv(&cp->args, spf->args.v);
17001698
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);
17021701

1703-
strbuf_addf(&submodule_prefix, "%s%s/",
1704-
spf->prefix,
1705-
task->sub->path);
1706-
strvec_push(&cp->args, submodule_prefix.buf);
17071702
*task_cb = task;
17081703

1709-
strbuf_release(&submodule_prefix);
17101704
string_list_insert(&spf->seen_submodule_names, task->sub->name);
17111705
return 1;
17121706
}
17131707

17141708
if (spf->oid_fetch_tasks_nr) {
17151709
struct fetch_task *task =
17161710
spf->oid_fetch_tasks[spf->oid_fetch_tasks_nr - 1];
1717-
struct strbuf submodule_prefix = STRBUF_INIT;
17181711
spf->oid_fetch_tasks_nr--;
17191712

1720-
strbuf_addf(&submodule_prefix, "%s%s/",
1721-
spf->prefix, task->sub->path);
1722-
17231713
child_process_init(cp);
17241714
prepare_submodule_repo_env_in_gitdir(&cp->env);
17251715
cp->git_cmd = 1;
@@ -1728,16 +1718,15 @@ static int get_next_submodule(struct child_process *cp, struct strbuf *err,
17281718
strvec_init(&cp->args);
17291719
strvec_pushv(&cp->args, spf->args.v);
17301720
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);
17331723

17341724
/* NEEDSWORK: have get_default_remote from submodule--helper */
17351725
strvec_push(&cp->args, "origin");
17361726
oid_array_for_each_unique(task->commits,
17371727
append_oid_to_argv, &cp->args);
17381728

17391729
*task_cb = task;
1740-
strbuf_release(&submodule_prefix);
17411730
return 1;
17421731
}
17431732

0 commit comments

Comments
 (0)