summaryrefslogtreecommitdiff
path: root/string-list.c
diff options
context:
space:
mode:
authorBrandon Williams <bmwill@google.com>2017-04-19 16:13:21 -0700
committerJunio C Hamano <gitster@pobox.com>2017-04-20 17:55:32 -0700
commit3a30033327337323e91dcbcb87396d3245260585 (patch)
treee008f3df89e78774ab9810a3e18fe6b472049616 /string-list.c
parente3a434468fecca7c14a6bef32050dfa60534fde6 (diff)
downloadgit-3a30033327337323e91dcbcb87396d3245260585.tar.gz
string-list: add string_list_remove function
Teach string-list to be able to remove a string from a sorted 'struct string_list'. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'string-list.c')
-rw-r--r--string-list.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/string-list.c b/string-list.c
index 45016ad86d..8f7b69ada1 100644
--- a/string-list.c
+++ b/string-list.c
@@ -67,6 +67,24 @@ struct string_list_item *string_list_insert(struct string_list *list, const char
return list->items + index;
}
+void string_list_remove(struct string_list *list, const char *string,
+ int free_util)
+{
+ int exact_match;
+ int i = get_entry_index(list, string, &exact_match);
+
+ if (exact_match) {
+ if (list->strdup_strings)
+ free(list->items[i].string);
+ if (free_util)
+ free(list->items[i].util);
+
+ list->nr--;
+ memmove(list->items + i, list->items + i + 1,
+ (list->nr - i) * sizeof(struct string_list_item));
+ }
+}
+
int string_list_has_string(const struct string_list *list, const char *string)
{
int exact_match;