| 3 | #include "string-list.h" |
| 4 | |
| 5 | int cmd__string_list(int argc, const char **argv) |
| 6 | { |
| 7 | if (argc == 2 && !strcmp(argv[1], "sort")) { |
| 8 | struct string_list list = STRING_LIST_INIT_NODUP; |
| 9 | struct strbuf sb = STRBUF_INIT; |
| 10 | struct string_list_item *item; |
| 11 | |
| 12 | strbuf_read(&sb, 0, 0); |
| 13 | |
| 14 | /* |
| 15 | * Split by newline, but don't create a string_list item |
| 16 | * for the empty string after the last separator. |
| 17 | */ |
| 18 | if (sb.len && sb.buf[sb.len - 1] == '\n') |
| 19 | strbuf_setlen(&sb, sb.len - 1); |
| 20 | string_list_split_in_place(&list, sb.buf, "\n", -1); |
| 21 | |
| 22 | string_list_sort(&list); |
| 23 | |
| 24 | for_each_string_list_item(item, &list) |
| 25 | puts(item->string); |
| 26 | |
| 27 | string_list_clear(&list, 0); |
| 28 | strbuf_release(&sb); |
| 29 | return 0; |
| 30 | } |
| 31 | |
| 32 | fprintf(stderr, "%s: unknown function name: %s\n", argv[0], |
| 33 | argv[1] ? argv[1] : "(there was none)"); |
| 34 | return 1; |
| 35 | } |
nothing calls this directly
no test coverage detected