All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] submodule: use strvec_pushf() for --submodule-prefix
@ 2024-02-25 18:24 René Scharfe
  2024-02-27  7:31 ` Patrick Steinhardt
  0 siblings, 1 reply; 2+ messages in thread
From: René Scharfe @ 2024-02-25 18:24 UTC (permalink / raw)
  To: Git List

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>
---
 submodule.c | 19 ++++---------------
 1 file changed, 4 insertions(+), 15 deletions(-)

diff --git a/submodule.c b/submodule.c
index 213da79f66..40f13a3685 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1687,8 +1687,6 @@ static int get_next_submodule(struct child_process *cp, struct strbuf *err,
 		task = get_fetch_task_from_changed(spf, err);

 	if (task) {
-		struct strbuf submodule_prefix = STRBUF_INIT;
-
 		child_process_init(cp);
 		cp->dir = task->repo->gitdir;
 		prepare_submodule_repo_env_in_gitdir(&cp->env);
@@ -1698,15 +1696,11 @@ static int get_next_submodule(struct child_process *cp, struct strbuf *err,
 			strvec_pushv(&cp->args, task->git_args.v);
 		strvec_pushv(&cp->args, spf->args.v);
 		strvec_push(&cp->args, task->default_argv);
-		strvec_push(&cp->args, "--submodule-prefix");
+		strvec_pushf(&cp->args, "--submodule-prefix=%s%s/",
+			     spf->prefix, task->sub->path);

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

-		strbuf_release(&submodule_prefix);
 		string_list_insert(&spf->seen_submodule_names, task->sub->name);
 		return 1;
 	}
@@ -1714,12 +1708,8 @@ static int get_next_submodule(struct child_process *cp, struct strbuf *err,
 	if (spf->oid_fetch_tasks_nr) {
 		struct fetch_task *task =
 			spf->oid_fetch_tasks[spf->oid_fetch_tasks_nr - 1];
-		struct strbuf submodule_prefix = STRBUF_INIT;
 		spf->oid_fetch_tasks_nr--;

-		strbuf_addf(&submodule_prefix, "%s%s/",
-			    spf->prefix, task->sub->path);
-
 		child_process_init(cp);
 		prepare_submodule_repo_env_in_gitdir(&cp->env);
 		cp->git_cmd = 1;
@@ -1728,8 +1718,8 @@ static int get_next_submodule(struct child_process *cp, struct strbuf *err,
 		strvec_init(&cp->args);
 		strvec_pushv(&cp->args, spf->args.v);
 		strvec_push(&cp->args, "on-demand");
-		strvec_push(&cp->args, "--submodule-prefix");
-		strvec_push(&cp->args, submodule_prefix.buf);
+		strvec_pushf(&cp->args, "--submodule-prefix=%s%s/",
+			     spf->prefix, task->sub->path);

 		/* NEEDSWORK: have get_default_remote from submodule--helper */
 		strvec_push(&cp->args, "origin");
@@ -1737,7 +1727,6 @@ static int get_next_submodule(struct child_process *cp, struct strbuf *err,
 					  append_oid_to_argv, &cp->args);

 		*task_cb = task;
-		strbuf_release(&submodule_prefix);
 		return 1;
 	}

--
2.44.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] submodule: use strvec_pushf() for --submodule-prefix
  2024-02-25 18:24 [PATCH] submodule: use strvec_pushf() for --submodule-prefix René Scharfe
@ 2024-02-27  7:31 ` Patrick Steinhardt
  0 siblings, 0 replies; 2+ messages in thread
From: Patrick Steinhardt @ 2024-02-27  7:31 UTC (permalink / raw)
  To: René Scharfe; +Cc: Git List

[-- Attachment #1: Type: text/plain, Size: 3023 bytes --]

On Sun, Feb 25, 2024 at 07:24:39PM +0100, René Scharfe wrote:
> 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.

This looks obviously good to me. Thanks for this nice simplification!

Patrick

> Signed-off-by: René Scharfe <l.s.r@web.de>
> ---
>  submodule.c | 19 ++++---------------
>  1 file changed, 4 insertions(+), 15 deletions(-)
> 
> diff --git a/submodule.c b/submodule.c
> index 213da79f66..40f13a3685 100644
> --- a/submodule.c
> +++ b/submodule.c
> @@ -1687,8 +1687,6 @@ static int get_next_submodule(struct child_process *cp, struct strbuf *err,
>  		task = get_fetch_task_from_changed(spf, err);
> 
>  	if (task) {
> -		struct strbuf submodule_prefix = STRBUF_INIT;
> -
>  		child_process_init(cp);
>  		cp->dir = task->repo->gitdir;
>  		prepare_submodule_repo_env_in_gitdir(&cp->env);
> @@ -1698,15 +1696,11 @@ static int get_next_submodule(struct child_process *cp, struct strbuf *err,
>  			strvec_pushv(&cp->args, task->git_args.v);
>  		strvec_pushv(&cp->args, spf->args.v);
>  		strvec_push(&cp->args, task->default_argv);
> -		strvec_push(&cp->args, "--submodule-prefix");
> +		strvec_pushf(&cp->args, "--submodule-prefix=%s%s/",
> +			     spf->prefix, task->sub->path);
> 
> -		strbuf_addf(&submodule_prefix, "%s%s/",
> -						spf->prefix,
> -						task->sub->path);
> -		strvec_push(&cp->args, submodule_prefix.buf);
>  		*task_cb = task;
> 
> -		strbuf_release(&submodule_prefix);
>  		string_list_insert(&spf->seen_submodule_names, task->sub->name);
>  		return 1;
>  	}
> @@ -1714,12 +1708,8 @@ static int get_next_submodule(struct child_process *cp, struct strbuf *err,
>  	if (spf->oid_fetch_tasks_nr) {
>  		struct fetch_task *task =
>  			spf->oid_fetch_tasks[spf->oid_fetch_tasks_nr - 1];
> -		struct strbuf submodule_prefix = STRBUF_INIT;
>  		spf->oid_fetch_tasks_nr--;
> 
> -		strbuf_addf(&submodule_prefix, "%s%s/",
> -			    spf->prefix, task->sub->path);
> -
>  		child_process_init(cp);
>  		prepare_submodule_repo_env_in_gitdir(&cp->env);
>  		cp->git_cmd = 1;
> @@ -1728,8 +1718,8 @@ static int get_next_submodule(struct child_process *cp, struct strbuf *err,
>  		strvec_init(&cp->args);
>  		strvec_pushv(&cp->args, spf->args.v);
>  		strvec_push(&cp->args, "on-demand");
> -		strvec_push(&cp->args, "--submodule-prefix");
> -		strvec_push(&cp->args, submodule_prefix.buf);
> +		strvec_pushf(&cp->args, "--submodule-prefix=%s%s/",
> +			     spf->prefix, task->sub->path);
> 
>  		/* NEEDSWORK: have get_default_remote from submodule--helper */
>  		strvec_push(&cp->args, "origin");
> @@ -1737,7 +1727,6 @@ static int get_next_submodule(struct child_process *cp, struct strbuf *err,
>  					  append_oid_to_argv, &cp->args);
> 
>  		*task_cb = task;
> -		strbuf_release(&submodule_prefix);
>  		return 1;
>  	}
> 
> --
> 2.44.0
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-02-27  7:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-25 18:24 [PATCH] submodule: use strvec_pushf() for --submodule-prefix René Scharfe
2024-02-27  7:31 ` Patrick Steinhardt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.