argv-array: implement argv_array_pushv()

When we have a null-terminated array, it would be useful to convert it or append it to an argv_array for further manipulation. Implement argv_array_pushv() which will push a null-terminated array of strings on to an argv_array. Signed-off-by: Paul Tan <pyokagan@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Paul Tan committed Jun 14, 2015 at 16:41 UTC 85b343245b495a47f937007e1c0650f2070b9b4f
3 files changed +10
Documentation/technical/api-argv-array.txt
+3
@@ -46,6 +46,9 @@ Functions
46 Format a string and push it onto the end of the array. This is a
47 convenience wrapper combining `strbuf_addf` and `argv_array_push`.
48
49 +`argv_array_pushv`::
50 + Push a null-terminated array of strings onto the end of the array.
51 +
52 `argv_array_pop`::
53 Remove the final element from the array. If there are no
54 elements in the array, do nothing.
argv-array.c
+6
@@ -49,6 +49,12 @@ void argv_array_pushl(struct argv_array *array, ...)
49 va_end(ap);
50 }
51
52 +void argv_array_pushv(struct argv_array *array, const char **argv)
53 +{
54 + for (; *argv; argv++)
55 + argv_array_push(array, *argv);
56 +}
57 +
58 void argv_array_pop(struct argv_array *array)
59 {
60 if (!array->argc)
argv-array.h
+1
@@ -17,6 +17,7 @@ __attribute__((format (printf,2,3)))
17 void argv_array_pushf(struct argv_array *, const char *fmt, ...);
18 LAST_ARG_MUST_BE_NULL
19 void argv_array_pushl(struct argv_array *, ...);
20 +void argv_array_pushv(struct argv_array *, const char **);
21 void argv_array_pop(struct argv_array *);
22 void argv_array_clear(struct argv_array *);
23