From fe4a0a288842e225f99254b3e6ce14ff98875501 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sat, 1 Sep 2012 07:25:27 -0400 Subject: argv-array: add pop function Sometimes we build a set of similar command lines, differing only in the final arguments (e.g., "fetch --multiple"). To use argv_array for this, you have to either push the same set of elements repeatedly, or break the abstraction by manually manipulating the array's internal members. Instead, let's provide a sanctioned "pop" function to remove elements from the end. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- argv-array.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'argv-array.c') diff --git a/argv-array.c b/argv-array.c index 0b5f8898a1..55e8443ff9 100644 --- a/argv-array.c +++ b/argv-array.c @@ -49,6 +49,15 @@ void argv_array_pushl(struct argv_array *array, ...) va_end(ap); } +void argv_array_pop(struct argv_array *array) +{ + if (!array->argc) + return; + free((char *)array->argv[array->argc - 1]); + array->argv[array->argc - 1] = NULL; + array->argc--; +} + void argv_array_clear(struct argv_array *array) { if (array->argv != empty_argv) { -- cgit v1.2.3 From ba4d1c7b1623b2c7ec198aee08036acf779375e6 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sat, 1 Sep 2012 07:34:09 -0400 Subject: argv-array: fix bogus cast when freeing array Since the array struct stores a "const char **" argv member (for compatibility with most of our argv-taking functions), we have to cast away the const-ness when freeing its elements. However, we used the wrong type when doing so. It doesn't make a difference since free() take a void pointer anyway, but it can be slightly confusing to a reader. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- argv-array.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'argv-array.c') diff --git a/argv-array.c b/argv-array.c index 55e8443ff9..256741d226 100644 --- a/argv-array.c +++ b/argv-array.c @@ -63,7 +63,7 @@ void argv_array_clear(struct argv_array *array) if (array->argv != empty_argv) { int i; for (i = 0; i < array->argc; i++) - free((char **)array->argv[i]); + free((char *)array->argv[i]); free(array->argv); } argv_array_init(array); -- cgit v1.2.3