[PATCH 1/5] argv-array: Add argv_array_pop function [v2]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



As a convienience, it would be nice if we could pop entries off the argv_array
structs so that if they had multiple uses in a function, we wouldn't have to
clear them and repopulate common entries.  This patch adds the argv_array_pop
function to do just that.  Common entries can be added to an argv_array first,
then useage specific ones can be added on the end and removed later on.

Signed-off-by: Neil Horman <nhorman@xxxxxxxxxxxxx>
CC: Jeff King <peff@xxxxxxxx>
CC: Phil Hord <phil.hord@xxxxxxxxx>
CC: Junio C Hamano <gitster@xxxxxxxxx>
---
 argv-array.c |   12 ++++++++++++
 argv-array.h |    1 +
 2 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/argv-array.c b/argv-array.c
index a4e0420..ce24a48 100644
--- a/argv-array.c
+++ b/argv-array.c
@@ -39,6 +39,18 @@ void argv_array_pushf(struct argv_array *array, const char *fmt, ...)
 	argv_array_push_nodup(array, strbuf_detach(&v, NULL));
 }
 
+int argv_array_pop(struct argv_array *array, unsigned int num)
+{
+	if (num > array->argc)
+		return -1;
+
+	for(num--; num>0; num--) {
+		free((char **)array->argv[num]);
+		array->argv[num] = NULL;
+	}
+	return 0;
+}
+
 void argv_array_clear(struct argv_array *array)
 {
 	if (array->argv != empty_argv) {
diff --git a/argv-array.h b/argv-array.h
index 74dd2b1..8233243 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, ...);
+int argv_array_pop(struct argv_array *, unsigned int num);
 void argv_array_clear(struct argv_array *);
 
 #endif /* ARGV_ARRAY_H */
-- 
1.7.7.6

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]