git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 3/7] refactor argv_array into generic code

From
Christian Couder <christian.couder@gmail.com>
Date
Sep 14, 2011, 05:54 UTC
Message-ID
<CAP8UFD1vxP9ABgJpM99hxDWWLeGO_QW7QLVFq1f-teu1fiCftA@mail.gmail.com>
In-Reply-To
<20110913215757.GC24490@sigill.intra.peff.net>
Hi Peff,
On Tue, Sep 13, 2011 at 11:57 PM, Jeff King <peff@peff.net> wrote:
Show 46 quoted lines
> diff --git a/argv-array.c b/argv-array.c
> new file mode 100644
> index 0000000..a50507a
> --- /dev/null
> +++ b/argv-array.c
> @@ -0,0 +1,52 @@
> +#include "cache.h"
> +#include "argv-array.h"
> +#include "strbuf.h"
> +
> +static const char *empty_argv_storage = NULL;
> +const char **empty_argv = &empty_argv_storage;
> +
> +void argv_array_init(struct argv_array *array)
> +{
> +       array->argv = empty_argv;
> +       array->argc = 0;
> +       array->alloc = 0;
> +}
> +
> +static void argv_array_push_nodup(struct argv_array *array, const char *value)
> +{
> +       if (array->argv == empty_argv)
> +               array->argv = NULL;
> +
> +       ALLOC_GROW(array->argv, array->argc + 2, array->alloc);
> +       array->argv[array->argc++] = value;
> +       array->argv[array->argc] = NULL;
> +}
> +
> +void argv_array_push(struct argv_array *array, const char *value)
> +{
> +       argv_array_push_nodup(array, xstrdup(value));
> +}
> +
> +void argv_array_pushf(struct argv_array *array, const char *fmt, ...)
> +{
> +       va_list ap;
> +       struct strbuf v = STRBUF_INIT;
> +
> +       va_start(ap, fmt);
> +       strbuf_vaddf(&v, fmt, ap);
> +       va_end(ap);
> +
> +       argv_array_push_nodup(array, strbuf_detach(&v, NULL));
> +}

In sha1-array you called the "push" function "sha1_array_append" instead of "sha1_array_push", so I wonder why here you call them "*_push*" instead of "*_append*"?

Thanks for doing this anyway, Christian.

Previous: Jeff KingNext: Jeff King
Message 5 of 18 in “create argv_array API”
  1. 0/7 create argv_array APIJeff King, Sep 13, 2011
  2. 1/7 add sha1_array API docsJeff King, Sep 13, 2011
  3. 2/7 quote.h: fix bogus commentJeff King, Sep 13, 2011
  4. 3/7 refactor argv_array into generic codeJeff King, Sep 13, 2011
  5. Christian CouderSep 14, 2011
  6. Jeff KingSep 14, 2011
  7. Junio C HamanoSep 14, 2011
  8. Junio C HamanoSep 14, 2011
  9. 4/7 quote: provide sq_dequote_to_argv_arrayJeff King, Sep 13, 2011
  10. 5/7 bisect: use argv_array APIJeff King, Sep 13, 2011
  11. 6/7 checkout: use argv_array APIJeff King, Sep 13, 2011
  12. 7/7 run_hook: use argv_array APIJeff King, Sep 13, 2011
  13. [nit] diff func headers ignore contextJeff King, Sep 13, 2011
  14. Andreas EricssonSep 14, 2011
  15. Junio C HamanoSep 14, 2011
  16. Junio C HamanoSep 14, 2011
  17. Jeff KingSep 14, 2011
  18. Junio C HamanoSep 14, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.