summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Tan <pyokagan@gmail.com>2015-06-14 08:41:50 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-06-15 19:40:49 (GMT)
commit85b343245b495a47f937007e1c0650f2070b9b4f (patch)
treeaf7600866200705159dcffec6f35b3ae99c43cf5
parentffad85c599307441323de565c3fafde227e04a8f (diff)
downloadgit-85b343245b495a47f937007e1c0650f2070b9b4f.zip
git-85b343245b495a47f937007e1c0650f2070b9b4f.tar.gz
git-85b343245b495a47f937007e1c0650f2070b9b4f.tar.bz2
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>
-rw-r--r--Documentation/technical/api-argv-array.txt3
-rw-r--r--argv-array.c6
-rw-r--r--argv-array.h1
3 files changed, 10 insertions, 0 deletions
diff --git a/Documentation/technical/api-argv-array.txt b/Documentation/technical/api-argv-array.txt
index 1a79781..8076172 100644
--- a/Documentation/technical/api-argv-array.txt
+++ b/Documentation/technical/api-argv-array.txt
@@ -46,6 +46,9 @@ Functions
Format a string and push it onto the end of the array. This is a
convenience wrapper combining `strbuf_addf` and `argv_array_push`.
+`argv_array_pushv`::
+ Push a null-terminated array of strings onto the end of the array.
+
`argv_array_pop`::
Remove the final element from the array. If there are no
elements in the array, do nothing.
diff --git a/argv-array.c b/argv-array.c
index 256741d..eaed477 100644
--- a/argv-array.c
+++ b/argv-array.c
@@ -49,6 +49,12 @@ void argv_array_pushl(struct argv_array *array, ...)
va_end(ap);
}
+void argv_array_pushv(struct argv_array *array, const char **argv)
+{
+ for (; *argv; argv++)
+ argv_array_push(array, *argv);
+}
+
void argv_array_pop(struct argv_array *array)
{
if (!array->argc)
diff --git a/argv-array.h b/argv-array.h
index c65e6e8..a2fa0aa 100644
--- a/argv-array.h
+++ b/argv-array.h
@@ -17,6 +17,7 @@ __attribute__((format (printf,2,3)))
void argv_array_pushf(struct argv_array *, const char *fmt, ...);
LAST_ARG_MUST_BE_NULL
void argv_array_pushl(struct argv_array *, ...);
+void argv_array_pushv(struct argv_array *, const char **);
void argv_array_pop(struct argv_array *);
void argv_array_clear(struct argv_array *);