diff options
| author | Amisha Chhajed <amishhhaaaa@gmail.com> | 2026-01-29 17:42:20 +0530 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2026-01-29 09:32:50 -0800 |
| commit | 2e711acfbdfc0fedf631688d78cde153ba835c93 (patch) | |
| tree | b8725125128340b97c086e32e78117284cbbe75d /t | |
| parent | 208642cfbb53781602af1fa77c67322c0aab0ad9 (diff) | |
| download | git-2e711acfbdfc0fedf631688d78cde153ba835c93.tar.xz | |
string-list: add string_list_sort_u() that mimics "sort -u"
Many callsites of string_list_remove_duplicates() call it
immdediately after calling string_list_sort(), understandably
as the former requires string-list to be sorted, it is clear
that these places are sorting only to remove duplicates and
for no other reason.
Introduce a helper function string_list_sort_u that combines
these two calls that often appear together, to simplify
these callsites. Replace the current calls of those methods with
string_list_sort_u().
Signed-off-by: Amisha Chhajed <amishhhaaaa@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't')
| -rw-r--r-- | t/unit-tests/u-string-list.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/t/unit-tests/u-string-list.c b/t/unit-tests/u-string-list.c index d469a06eca..7ad84cc1cd 100644 --- a/t/unit-tests/u-string-list.c +++ b/t/unit-tests/u-string-list.c @@ -437,6 +437,40 @@ void test_string_list__remove_duplicates(void) t_string_list_clear(&list, 0); } +static void t_string_list_sort_u(struct string_list *list, ...) +{ + struct string_list expected_strings = STRING_LIST_INIT_DUP; + va_list ap; + + va_start(ap, list); + t_vcreate_string_list_dup(&expected_strings, 0, ap); + va_end(ap); + + string_list_sort_u(list, 0); + t_string_list_equal(list, &expected_strings); + + string_list_clear(&expected_strings, 0); +} + +void test_string_list__sort_u(void) +{ + struct string_list list = STRING_LIST_INIT_DUP; + + t_create_string_list_dup(&list, 0, NULL); + t_string_list_sort_u(&list, NULL); + + t_create_string_list_dup(&list, 0, "", "", "", "", NULL); + t_string_list_sort_u(&list, "", NULL); + + t_create_string_list_dup(&list, 0, "b", "a", "a", "", NULL); + t_string_list_sort_u(&list, "", "a", "b", NULL); + + t_create_string_list_dup(&list, 0, "b", "a", "a", "d", "c", "c", NULL); + t_string_list_sort_u(&list, "a", "b", "c", "d", NULL); + + t_string_list_clear(&list, 0); +} + static void t_string_list_remove_empty_items( struct string_list *expected_strings, struct string_list *list) |
