summaryrefslogtreecommitdiff
path: root/string-list.c
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2012-09-12 14:04:45 (GMT)
committerJunio C Hamano <gitster@pobox.com>2012-09-12 18:43:25 (GMT)
commit31d5451eed2677531c80177ff9dc8f5285f5a187 (patch)
treebd709b58ba3096867e2f6166f516773b67aad0e1 /string-list.c
parenteb5f0c7a616531a024a582b72ca6d8775ff98d46 (diff)
downloadgit-31d5451eed2677531c80177ff9dc8f5285f5a187.zip
git-31d5451eed2677531c80177ff9dc8f5285f5a187.tar.gz
git-31d5451eed2677531c80177ff9dc8f5285f5a187.tar.bz2
string_list: add a new function, string_list_remove_duplicates()
Add a function that deletes duplicate entries from a sorted string_list. 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 179fde4..decfa74 100644
--- a/string-list.c
+++ b/string-list.c
@@ -92,6 +92,23 @@ struct string_list_item *string_list_lookup(struct string_list *list, const char
return list->items + i;
}
+void string_list_remove_duplicates(struct string_list *list, int free_util)
+{
+ if (list->nr > 1) {
+ int src, dst;
+ for (src = dst = 1; src < list->nr; src++) {
+ if (!strcmp(list->items[dst - 1].string, list->items[src].string)) {
+ if (list->strdup_strings)
+ free(list->items[src].string);
+ if (free_util)
+ free(list->items[src].util);
+ } else
+ list->items[dst++] = list->items[src];
+ }
+ list->nr = dst;
+ }
+}
+
int for_each_string_list(struct string_list *list,
string_list_each_func_t fn, void *cb_data)
{