use strvec_pushv() to add another strvec
Add and apply a semantic patch that simplifies the code by letting strvec_pushv() append the items of a second strvec instead of pushing them one by one. Suggested-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Mar 24, 2026 at 12:26 UTC
250e977a2b0aa8cc1c8063c64c44597a166e79f5
5 files changed
+51
-13
builtin/rebase.c
+1
-2
@@ -182,8 +182,7 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts)
182
183
replay.signoff = opts->signoff;
184
185
- for (size_t i = 0; i < opts->trailer_args.nr; i++)
186
- strvec_push(&replay.trailer_args, opts->trailer_args.v[i]);
185
+ strvec_pushv(&replay.trailer_args, opts->trailer_args.v);
186
187
replay.allow_ff = !(opts->flags & REBASE_FORCE);
188
if (opts->allow_rerere_autoupdate)
fetch-pack.c
+2
-6
@@ -1024,12 +1024,8 @@ static int get_pack(struct fetch_pack_args *args,
1024
fsck_msg_types.buf);
1025
}
1026
1027
- if (index_pack_args) {
1028
- int i;
1029
-
1030
- for (i = 0; i < cmd.args.nr; i++)
1031
- strvec_push(index_pack_args, cmd.args.v[i]);
1032
- }
1027
+ if (index_pack_args)
1028
+ strvec_pushv(index_pack_args, cmd.args.v);
1029
1030
sigchain_push(SIGPIPE, SIG_IGN);
1031
git.c
+1
-2
@@ -877,8 +877,7 @@ static int run_argv(struct strvec *args)
877
commit_pager_choice();
878
879
strvec_push(&cmd.args, "git");
880
- for (size_t i = 0; i < args->nr; i++)
881
- strvec_push(&cmd.args, args->v[i]);
880
+ strvec_pushv(&cmd.args, args->v);
881
882
trace_argv_printf(cmd.args.v, "trace: exec:");
883
submodule.c
+1
-3
@@ -1815,7 +1815,6 @@ int fetch_submodules(struct repository *r,
1815
int default_option,
1816
int quiet, int max_parallel_jobs)
1817
{
1818
- int i;
1818
struct submodule_parallel_fetch spf = SPF_INIT;
1819
const struct run_process_parallel_opts opts = {
1820
.tr2_category = "submodule",
@@ -1842,8 +1841,7 @@ int fetch_submodules(struct repository *r,
1841
die(_("index file corrupt"));
1842
1843
strvec_push(&spf.args, "fetch");
1845
- for (i = 0; i < options->nr; i++)
1846
- strvec_push(&spf.args, options->v[i]);
1844
+ strvec_pushv(&spf.args, options->v);
1845
strvec_push(&spf.args, "--recurse-submodules-default");
1846
/* default value, "--submodule-prefix" and its value are added later */
1847
tools/coccinelle/strvec.cocci
new
+46
@@ -0,0 +1,46 @@
1
+@@
2
+type T;
3
+identifier i;
4
+expression dst;
5
+struct strvec *src_ptr;
6
+struct strvec src_arr;
7
+@@
8
+(
9
+- for (T i = 0; i < src_ptr->nr; i++) { strvec_push(dst, src_ptr->v[i]); }
10
++ strvec_pushv(dst, src_ptr->v);
11
+|
12
+- for (T i = 0; i < src_arr.nr; i++) { strvec_push(dst, src_arr.v[i]); }
13
++ strvec_pushv(dst, src_arr.v);
14
+)
15
+
16
+@ separate_loop_index @
17
+type T;
18
+identifier i;
19
+expression dst;
20
+struct strvec *src_ptr;
21
+struct strvec src_arr;
22
+@@
23
+ T i;
24
+ ...
25
+(
26
+- for (i = 0; i < src_ptr->nr; i++) { strvec_push(dst, src_ptr->v[i]); }
27
++ strvec_pushv(dst, src_ptr->v);
28
+|
29
+- for (i = 0; i < src_arr.nr; i++) { strvec_push(dst, src_arr.v[i]); }
30
++ strvec_pushv(dst, src_arr.v);
31
+)
32
+
33
+@ unused_loop_index extends separate_loop_index @
34
+@@
35
+ {
36
+ ...
37
+- T i;
38
+ ... when != i
39
+ }
40
+
41
+@ depends on unused_loop_index @
42
+@@
43
+ if (...)
44
+- {
45
+ strvec_pushv(...);
46
+- }