Skip to content

Commit fc5db56

Browse files
rscharfegitster
authored andcommitted
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>
1 parent 6e8d538 commit fc5db56

5 files changed

Lines changed: 51 additions & 13 deletions

File tree

builtin/rebase.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,7 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts)
182182

183183
replay.signoff = opts->signoff;
184184

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);
187186

188187
replay.allow_ff = !(opts->flags & REBASE_FORCE);
189188
if (opts->allow_rerere_autoupdate)

contrib/coccinelle/strvec.cocci

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
- }

fetch-pack.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,12 +1024,8 @@ static int get_pack(struct fetch_pack_args *args,
10241024
fsck_msg_types.buf);
10251025
}
10261026

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);
10331029

10341030
sigchain_push(SIGPIPE, SIG_IGN);
10351031

git.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -877,8 +877,7 @@ static int run_argv(struct strvec *args)
877877
commit_pager_choice();
878878

879879
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);
882881

883882
trace_argv_printf(cmd.args.v, "trace: exec:");
884883

submodule.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,7 +1815,6 @@ int fetch_submodules(struct repository *r,
18151815
int default_option,
18161816
int quiet, int max_parallel_jobs)
18171817
{
1818-
int i;
18191818
struct submodule_parallel_fetch spf = SPF_INIT;
18201819
const struct run_process_parallel_opts opts = {
18211820
.tr2_category = "submodule",
@@ -1842,8 +1841,7 @@ int fetch_submodules(struct repository *r,
18421841
die(_("index file corrupt"));
18431842

18441843
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);
18471845
strvec_push(&spf.args, "--recurse-submodules-default");
18481846
/* default value, "--submodule-prefix" and its value are added later */
18491847

0 commit comments

Comments
 (0)