From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: [PATCH 2/3] argv-array: add a new "pushl" method
Date: Wed, 18 Apr 2012 14:10:05 -0700 [thread overview]
Message-ID: <20120418211005.GB21301@sigill.intra.peff.net> (raw)
In-Reply-To: <20120418210740.GA21214@sigill.intra.peff.net>
It can be convenient to push many strings in a single line
(e.g., if you are initializing an array with defaults). This
patch provides a convenience wrapper to allow this.
Signed-off-by: Jeff King <peff@peff.net>
---
I called this "pushl" after "execl", with the intent that we might
eventually have "pushv" if somebody wants it. Hopefully that makes
sense to others, but if not, I can name it something more verbose.
Documentation/technical/api-argv-array.txt | 5 +++++
argv-array.c | 11 +++++++++++
argv-array.h | 1 +
3 files changed, 17 insertions(+)
diff --git a/Documentation/technical/api-argv-array.txt b/Documentation/technical/api-argv-array.txt
index 49b3d52..1b7d8f1 100644
--- a/Documentation/technical/api-argv-array.txt
+++ b/Documentation/technical/api-argv-array.txt
@@ -37,6 +37,11 @@ Functions
`argv_array_push`::
Push a copy of a string onto the end of the array.
+`argv_array_pushl`::
+ Push a list of strings onto the end of the array. The arguments
+ should be a list of `const char *` strings, terminated by a NULL
+ argument.
+
`argv_array_pushf`::
Format a string and push it onto the end of the array. This is a
convenience wrapper combining `strbuf_addf` and `argv_array_push`.
diff --git a/argv-array.c b/argv-array.c
index 110a61b..0b5f889 100644
--- a/argv-array.c
+++ b/argv-array.c
@@ -38,6 +38,17 @@ void argv_array_pushf(struct argv_array *array, const char *fmt, ...)
argv_array_push_nodup(array, strbuf_detach(&v, NULL));
}
+void argv_array_pushl(struct argv_array *array, ...)
+{
+ va_list ap;
+ const char *arg;
+
+ va_start(ap, array);
+ while((arg = va_arg(ap, const char *)))
+ argv_array_push(array, arg);
+ va_end(ap);
+}
+
void argv_array_clear(struct argv_array *array)
{
if (array->argv != empty_argv) {
diff --git a/argv-array.h b/argv-array.h
index c45c698..b93a69c 100644
--- a/argv-array.h
+++ b/argv-array.h
@@ -15,6 +15,7 @@ void argv_array_init(struct argv_array *);
void argv_array_push(struct argv_array *, const char *);
__attribute__((format (printf,2,3)))
void argv_array_pushf(struct argv_array *, const char *fmt, ...);
+void argv_array_pushl(struct argv_array *, ...);
void argv_array_clear(struct argv_array *);
#endif /* ARGV_ARRAY_H */
--
1.7.9.6.8.g992e5
next prev parent reply other threads:[~2012-04-18 21:10 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-17 23:32 [PATCH] gc: fix off-by-one in append_option Jeff King
2012-04-18 19:18 ` Jeff King
2012-04-18 19:34 ` Junio C Hamano
2012-04-18 20:21 ` Jeff King
2012-04-18 21:07 ` Jeff King
2012-04-18 21:08 ` [PATCH 1/3] argv-array: refactor empty_argv initialization Jeff King
2012-04-18 21:10 ` Jeff King [this message]
2012-04-18 21:10 ` [PATCH 3/3] gc: use argv-array for sub-commands Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120418211005.GB21301@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).