summaryrefslogtreecommitdiff
path: root/string-list.c
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2012-09-12 16:04:44 +0200
committerJunio C Hamano <gitster@pobox.com>2012-09-12 11:43:25 -0700
commiteb5f0c7a616531a024a582b72ca6d8775ff98d46 (patch)
tree1c791a163140cb2988c7d2049ce706ad93e0c23d /string-list.c
parentff919f965d20d003e3882c70de667f41a86349ac (diff)
downloadgit-eb5f0c7a616531a024a582b72ca6d8775ff98d46.tar.gz
string_list: add a new function, filter_string_list()
This function allows entries that don't match a specified criterion to be discarded from a string_list while preserving the order of the remaining entries. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'string-list.c')
-rw-r--r--string-list.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/string-list.c b/string-list.c
index acb1f5b6dc..179fde4210 100644
--- a/string-list.c
+++ b/string-list.c
@@ -102,6 +102,23 @@ int for_each_string_list(struct string_list *list,
return ret;
}
+void filter_string_list(struct string_list *list, int free_util,
+ string_list_each_func_t want, void *cb_data)
+{
+ int src, dst = 0;
+ for (src = 0; src < list->nr; src++) {
+ if (want(&list->items[src], cb_data)) {
+ list->items[dst++] = list->items[src];
+ } else {
+ if (list->strdup_strings)
+ free(list->items[src].string);
+ if (free_util)
+ free(list->items[src].util);
+ }
+ }
+ list->nr = dst;
+}
+
void string_list_clear(struct string_list *list, int free_util)
{
if (list->items) {