diff options
| author | Junio C Hamano <gitster@pobox.com> | 2026-04-01 10:28:18 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2026-04-01 10:28:19 -0700 |
| commit | 51a74900aa48242db54336c0af43507acbe108ed (patch) | |
| tree | 2e835bb2ee5460d802b9590ea8bd5cfddfbc3700 | |
| parent | 11f494d5b22a6c2fcd95bf941c03e2ec12b26bfb (diff) | |
| parent | 250e977a2b0aa8cc1c8063c64c44597a166e79f5 (diff) | |
| download | git-51a74900aa48242db54336c0af43507acbe108ed.tar.xz | |
Merge branch 'rs/use-strvec-pushv'
Code paths that loop over another array to push each element into a
strvec have been rewritten to use strvec_pushv() instead.
* rs/use-strvec-pushv:
use strvec_pushv() to add another strvec
| -rw-r--r-- | builtin/rebase.c | 3 | ||||
| -rw-r--r-- | fetch-pack.c | 8 | ||||
| -rw-r--r-- | git.c | 3 | ||||
| -rw-r--r-- | submodule.c | 4 | ||||
| -rw-r--r-- | tools/coccinelle/strvec.cocci | 46 |
5 files changed, 51 insertions, 13 deletions
diff --git a/builtin/rebase.c b/builtin/rebase.c index a1c7d78196..fa4f5d9306 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -182,8 +182,7 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts) replay.signoff = opts->signoff; - for (size_t i = 0; i < opts->trailer_args.nr; i++) - strvec_push(&replay.trailer_args, opts->trailer_args.v[i]); + strvec_pushv(&replay.trailer_args, opts->trailer_args.v); replay.allow_ff = !(opts->flags & REBASE_FORCE); if (opts->allow_rerere_autoupdate) diff --git a/fetch-pack.c b/fetch-pack.c index 6ecd468ef7..a32224ed02 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -1024,12 +1024,8 @@ static int get_pack(struct fetch_pack_args *args, fsck_msg_types.buf); } - if (index_pack_args) { - int i; - - for (i = 0; i < cmd.args.nr; i++) - strvec_push(index_pack_args, cmd.args.v[i]); - } + if (index_pack_args) + strvec_pushv(index_pack_args, cmd.args.v); sigchain_push(SIGPIPE, SIG_IGN); @@ -877,8 +877,7 @@ static int run_argv(struct strvec *args) commit_pager_choice(); strvec_push(&cmd.args, "git"); - for (size_t i = 0; i < args->nr; i++) - strvec_push(&cmd.args, args->v[i]); + strvec_pushv(&cmd.args, args->v); trace_argv_printf(cmd.args.v, "trace: exec:"); diff --git a/submodule.c b/submodule.c index e20537ba8d..b1a0363f9d 100644 --- a/submodule.c +++ b/submodule.c @@ -1828,7 +1828,6 @@ int fetch_submodules(struct repository *r, int default_option, int quiet, int max_parallel_jobs) { - int i; struct submodule_parallel_fetch spf = SPF_INIT; const struct run_process_parallel_opts opts = { .tr2_category = "submodule", @@ -1855,8 +1854,7 @@ int fetch_submodules(struct repository *r, die(_("index file corrupt")); strvec_push(&spf.args, "fetch"); - for (i = 0; i < options->nr; i++) - strvec_push(&spf.args, options->v[i]); + strvec_pushv(&spf.args, options->v); strvec_push(&spf.args, "--recurse-submodules-default"); /* default value, "--submodule-prefix" and its value are added later */ diff --git a/tools/coccinelle/strvec.cocci b/tools/coccinelle/strvec.cocci new file mode 100644 index 0000000000..64edb09f1c --- /dev/null +++ b/tools/coccinelle/strvec.cocci @@ -0,0 +1,46 @@ +@@ +type T; +identifier i; +expression dst; +struct strvec *src_ptr; +struct strvec src_arr; +@@ +( +- for (T i = 0; i < src_ptr->nr; i++) { strvec_push(dst, src_ptr->v[i]); } ++ strvec_pushv(dst, src_ptr->v); +| +- for (T i = 0; i < src_arr.nr; i++) { strvec_push(dst, src_arr.v[i]); } ++ strvec_pushv(dst, src_arr.v); +) + +@ separate_loop_index @ +type T; +identifier i; +expression dst; +struct strvec *src_ptr; +struct strvec src_arr; +@@ + T i; + ... +( +- for (i = 0; i < src_ptr->nr; i++) { strvec_push(dst, src_ptr->v[i]); } ++ strvec_pushv(dst, src_ptr->v); +| +- for (i = 0; i < src_arr.nr; i++) { strvec_push(dst, src_arr.v[i]); } ++ strvec_pushv(dst, src_arr.v); +) + +@ unused_loop_index extends separate_loop_index @ +@@ + { + ... +- T i; + ... when != i + } + +@ depends on unused_loop_index @ +@@ + if (...) +- { + strvec_pushv(...); +- } |
