branch: don't assume the merge filter ref exists
[git/mjg.git] / argv-array.c
bloba4e04201e61d0243dc225d85117341d993ca0c3b
1 #include "cache.h"
2 #include "argv-array.h"
3 #include "strbuf.h"
5 static const char *empty_argv_storage = NULL;
6 const char **empty_argv = &empty_argv_storage;
8 void argv_array_init(struct argv_array *array)
10 array->argv = empty_argv;
11 array->argc = 0;
12 array->alloc = 0;
15 static void argv_array_push_nodup(struct argv_array *array, const char *value)
17 if (array->argv == empty_argv)
18 array->argv = NULL;
20 ALLOC_GROW(array->argv, array->argc + 2, array->alloc);
21 array->argv[array->argc++] = value;
22 array->argv[array->argc] = NULL;
25 void argv_array_push(struct argv_array *array, const char *value)
27 argv_array_push_nodup(array, xstrdup(value));
30 void argv_array_pushf(struct argv_array *array, const char *fmt, ...)
32 va_list ap;
33 struct strbuf v = STRBUF_INIT;
35 va_start(ap, fmt);
36 strbuf_vaddf(&v, fmt, ap);
37 va_end(ap);
39 argv_array_push_nodup(array, strbuf_detach(&v, NULL));
42 void argv_array_clear(struct argv_array *array)
44 if (array->argv != empty_argv) {
45 int i;
46 for (i = 0; i < array->argc; i++)
47 free((char **)array->argv[i]);
48 free(array->argv);
50 argv_array_init(array);