aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2026-03-24 12:26:58 -0700
committerJunio C Hamano <gitster@pobox.com>2026-03-24 12:26:58 -0700
commit250e977a2b0aa8cc1c8063c64c44597a166e79f5 (patch)
tree4bd35c77429ddd78fd53233d41e44b92e02d3e15 /tools
parent2d733b9660700fa4dd03a89d9003b8865b99bf4d (diff)
downloadgit-250e977a2b0aa8cc1c8063c64c44597a166e79f5.tar.xz
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>
Diffstat (limited to 'tools')
-rw-r--r--tools/coccinelle/strvec.cocci46
1 files changed, 46 insertions, 0 deletions
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(...);
+- }