{"thread":{"id":"60994","subject":"[PATCH] submodule: use strvec_pushf() for --submodule-prefix","startedAt":"2024-02-25T18:24:47Z","lastAt":"2024-02-27T07:31:36Z","messageCount":2,"participants":["René Scharfe","Patrick Steinhardt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"489320","messageId":"8cd983fb-32b9-41c6-a9e7-a485b190488c@web.de","threadId":"60994","inReplyTo":null,"subject":"[PATCH] submodule: use strvec_pushf() for --submodule-prefix","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2024-02-25T18:24:39Z","receivedAt":"2024-02-25T18:24:47Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Add the option --submodule-prefix and its argument directly using\nstrvec_pushf() instead of via a detour through a strbuf.  This is\nshorter, easier to read and doesn't require any explicit cleanup\nafterwards.\n\nSigned-off-by: René Scharfe <l.s.r@web.de>\n---\n submodule.c | 19 ++++---------------\n 1 file changed, 4 insertions(+), 15 deletions(-)\n\ndiff --git a/submodule.c b/submodule.c\nindex 213da79f66..40f13a3685 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -1687,8 +1687,6 @@ static int get_next_submodule(struct child_process *cp, struct strbuf *err,\n \t\ttask = get_fetch_task_from_changed(spf, err);\n\n \tif (task) {\n-\t\tstruct strbuf submodule_prefix = STRBUF_INIT;\n-\n \t\tchild_process_init(cp);\n \t\tcp->dir = task->repo->gitdir;\n \t\tprepare_submodule_repo_env_in_gitdir(&cp->env);\n@@ -1698,15 +1696,11 @@ static int get_next_submodule(struct child_process *cp, struct strbuf *err,\n \t\t\tstrvec_pushv(&cp->args, task->git_args.v);\n \t\tstrvec_pushv(&cp->args, spf->args.v);\n \t\tstrvec_push(&cp->args, task->default_argv);\n-\t\tstrvec_push(&cp->args, \"--submodule-prefix\");\n+\t\tstrvec_pushf(&cp->args, \"--submodule-prefix=%s%s/\",\n+\t\t\t     spf->prefix, task->sub->path);\n\n-\t\tstrbuf_addf(&submodule_prefix, \"%s%s/\",\n-\t\t\t\t\t\tspf->prefix,\n-\t\t\t\t\t\ttask->sub->path);\n-\t\tstrvec_push(&cp->args, submodule_prefix.buf);\n \t\t*task_cb = task;\n\n-\t\tstrbuf_release(&submodule_prefix);\n \t\tstring_list_insert(&spf->seen_submodule_names, task->sub->name);\n \t\treturn 1;\n \t}\n@@ -1714,12 +1708,8 @@ static int get_next_submodule(struct child_process *cp, struct strbuf *err,\n \tif (spf->oid_fetch_tasks_nr) {\n \t\tstruct fetch_task *task =\n \t\t\tspf->oid_fetch_tasks[spf->oid_fetch_tasks_nr - 1];\n-\t\tstruct strbuf submodule_prefix = STRBUF_INIT;\n \t\tspf->oid_fetch_tasks_nr--;\n\n-\t\tstrbuf_addf(&submodule_prefix, \"%s%s/\",\n-\t\t\t    spf->prefix, task->sub->path);\n-\n \t\tchild_process_init(cp);\n \t\tprepare_submodule_repo_env_in_gitdir(&cp->env);\n \t\tcp->git_cmd = 1;\n@@ -1728,8 +1718,8 @@ static int get_next_submodule(struct child_process *cp, struct strbuf *err,\n \t\tstrvec_init(&cp->args);\n \t\tstrvec_pushv(&cp->args, spf->args.v);\n \t\tstrvec_push(&cp->args, \"on-demand\");\n-\t\tstrvec_push(&cp->args, \"--submodule-prefix\");\n-\t\tstrvec_push(&cp->args, submodule_prefix.buf);\n+\t\tstrvec_pushf(&cp->args, \"--submodule-prefix=%s%s/\",\n+\t\t\t     spf->prefix, task->sub->path);\n\n \t\t/* NEEDSWORK: have get_default_remote from submodule--helper */\n \t\tstrvec_push(&cp->args, \"origin\");\n@@ -1737,7 +1727,6 @@ static int get_next_submodule(struct child_process *cp, struct strbuf *err,\n \t\t\t\t\t  append_oid_to_argv, &cp->args);\n\n \t\t*task_cb = task;\n-\t\tstrbuf_release(&submodule_prefix);\n \t\treturn 1;\n \t}\n\n--\n2.44.0\n"},{"id":"489463","messageId":"Zd2P0irjsaeiSapJ@tanuki","threadId":"60994","inReplyTo":"8cd983fb-32b9-41c6-a9e7-a485b190488c@web.de","subject":"Re: [PATCH] submodule: use strvec_pushf() for --submodule-prefix","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2024-02-27T07:31:30Z","receivedAt":"2024-02-27T07:31:36Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Sun, Feb 25, 2024 at 07:24:39PM +0100, René Scharfe wrote:\n> Add the option --submodule-prefix and its argument directly using\n> strvec_pushf() instead of via a detour through a strbuf.  This is\n> shorter, easier to read and doesn't require any explicit cleanup\n> afterwards.\n\nThis looks obviously good to me. Thanks for this nice simplification!\n\nPatrick\n\n> Signed-off-by: René Scharfe <l.s.r@web.de>\n> ---\n>  submodule.c | 19 ++++---------------\n>  1 file changed, 4 insertions(+), 15 deletions(-)\n> \n> diff --git a/submodule.c b/submodule.c\n> index 213da79f66..40f13a3685 100644\n> --- a/submodule.c\n> +++ b/submodule.c\n> @@ -1687,8 +1687,6 @@ static int get_next_submodule(struct child_process *cp, struct strbuf *err,\n>  \t\ttask = get_fetch_task_from_changed(spf, err);\n> \n>  \tif (task) {\n> -\t\tstruct strbuf submodule_prefix = STRBUF_INIT;\n> -\n>  \t\tchild_process_init(cp);\n>  \t\tcp->dir = task->repo->gitdir;\n>  \t\tprepare_submodule_repo_env_in_gitdir(&cp->env);\n> @@ -1698,15 +1696,11 @@ static int get_next_submodule(struct child_process *cp, struct strbuf *err,\n>  \t\t\tstrvec_pushv(&cp->args, task->git_args.v);\n>  \t\tstrvec_pushv(&cp->args, spf->args.v);\n>  \t\tstrvec_push(&cp->args, task->default_argv);\n> -\t\tstrvec_push(&cp->args, \"--submodule-prefix\");\n> +\t\tstrvec_pushf(&cp->args, \"--submodule-prefix=%s%s/\",\n> +\t\t\t     spf->prefix, task->sub->path);\n> \n> -\t\tstrbuf_addf(&submodule_prefix, \"%s%s/\",\n> -\t\t\t\t\t\tspf->prefix,\n> -\t\t\t\t\t\ttask->sub->path);\n> -\t\tstrvec_push(&cp->args, submodule_prefix.buf);\n>  \t\t*task_cb = task;\n> \n> -\t\tstrbuf_release(&submodule_prefix);\n>  \t\tstring_list_insert(&spf->seen_submodule_names, task->sub->name);\n>  \t\treturn 1;\n>  \t}\n> @@ -1714,12 +1708,8 @@ static int get_next_submodule(struct child_process *cp, struct strbuf *err,\n>  \tif (spf->oid_fetch_tasks_nr) {\n>  \t\tstruct fetch_task *task =\n>  \t\t\tspf->oid_fetch_tasks[spf->oid_fetch_tasks_nr - 1];\n> -\t\tstruct strbuf submodule_prefix = STRBUF_INIT;\n>  \t\tspf->oid_fetch_tasks_nr--;\n> \n> -\t\tstrbuf_addf(&submodule_prefix, \"%s%s/\",\n> -\t\t\t    spf->prefix, task->sub->path);\n> -\n>  \t\tchild_process_init(cp);\n>  \t\tprepare_submodule_repo_env_in_gitdir(&cp->env);\n>  \t\tcp->git_cmd = 1;\n> @@ -1728,8 +1718,8 @@ static int get_next_submodule(struct child_process *cp, struct strbuf *err,\n>  \t\tstrvec_init(&cp->args);\n>  \t\tstrvec_pushv(&cp->args, spf->args.v);\n>  \t\tstrvec_push(&cp->args, \"on-demand\");\n> -\t\tstrvec_push(&cp->args, \"--submodule-prefix\");\n> -\t\tstrvec_push(&cp->args, submodule_prefix.buf);\n> +\t\tstrvec_pushf(&cp->args, \"--submodule-prefix=%s%s/\",\n> +\t\t\t     spf->prefix, task->sub->path);\n> \n>  \t\t/* NEEDSWORK: have get_default_remote from submodule--helper */\n>  \t\tstrvec_push(&cp->args, \"origin\");\n> @@ -1737,7 +1727,6 @@ static int get_next_submodule(struct child_process *cp, struct strbuf *err,\n>  \t\t\t\t\t  append_oid_to_argv, &cp->args);\n> \n>  \t\t*task_cb = task;\n> -\t\tstrbuf_release(&submodule_prefix);\n>  \t\treturn 1;\n>  \t}\n> \n> --\n> 2.44.0\n> \n"}]}