]> git.ipfire.org Git - thirdparty/git.git/commitdiff
test-mergesort: use strbuf_getline()
authorRené Scharfe <l.s.r@web.de>
Fri, 1 Oct 2021 09:10:09 +0000 (11:10 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 1 Oct 2021 19:43:08 +0000 (12:43 -0700)
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>
t/helper/test-mergesort.c

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