test-mergesort: use strbuf_getline()

Strip line ending characters to make sure empty lines are sorted like
sort(1) does.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
René Scharfe 2021-10-01 11:10:09 +02:00 committed by Junio C Hamano
parent 94f6e3e283
commit 2e6701017e

View File

@ -28,9 +28,7 @@ int cmd__mergesort(int argc, const char **argv)
struct line *line, *p = NULL, *lines = NULL; struct line *line, *p = NULL, *lines = NULL;
struct strbuf sb = STRBUF_INIT; struct strbuf sb = STRBUF_INIT;
for (;;) { while (!strbuf_getline(&sb, stdin)) {
if (strbuf_getwholeline(&sb, stdin, '\n'))
break;
line = xmalloc(sizeof(struct line)); line = xmalloc(sizeof(struct line));
line->text = strbuf_detach(&sb, NULL); line->text = strbuf_detach(&sb, NULL);
if (p) { if (p) {
@ -46,7 +44,7 @@ int cmd__mergesort(int argc, const char **argv)
lines = llist_mergesort(lines, get_next, set_next, compare_strings); lines = llist_mergesort(lines, get_next, set_next, compare_strings);
while (lines) { while (lines) {
printf("%s", lines->text); puts(lines->text);
lines = lines->next; lines = lines->next;
} }
return 0; return 0;