Subject: [RFC PATCH 1/2] Adding string_list_sort_u which sorts a list then deduplicates it.

From: Amisha Chhajed <[email-masked]>
Date: Thu, 22 Jan 2026 22:45:22 +0530

string_list_remove_duplicates is almost always preceeded by
string_list_sort, hence adding string_list_sort_u which dedupliactes
post sorting.

Signed-off-by: Amisha Chhajed <[email-masked]>
---
 string-list.c | 6 ++++++
 string-list.h | 6 ++++++
 2 files changed, 12 insertions(+)

diff --git a/string-list.c b/string-list.c
index 08dc00984c..020ed8fef7 100644
--- a/string-list.c
+++ b/string-list.c
@@ -247,6 +247,12 @@ void string_list_sort(struct string_list *list)
 	QSORT_S(list->items, list->nr, cmp_items, &sort_ctx);
 }
 
+void string_list_sort_u(struct string_list *list, int free_util)
+{
+	string_list_sort(list);
+	string_list_remove_duplicates(list, free_util);
+}
+
 struct string_list_item *unsorted_string_list_lookup(struct string_list *list,
 						     const char *string)
 {
diff --git a/string-list.h b/string-list.h
index fa6ba07853..3ad862a187 100644
--- a/string-list.h
+++ b/string-list.h
@@ -239,6 +239,12 @@ struct string_list_item *string_list_append_nodup(struct string_list *list, char
  */
 void string_list_sort(struct string_list *list);
 
+/**
+ * Sort the list and then remove duplicate entries.  If free_util is true,
+ * call free() on the util members of any items that have to be deleted.
+ */
+void string_list_sort_u(struct string_list *list, int free_util);
+
 /**
  * Like `string_list_has_string()` but for unsorted lists. Linear in
  * size of the list.
-- 
2.51.0