]> git.ipfire.org Git - thirdparty/git.git/commitdiff
test-mergesort: add sort subcommand
authorRené Scharfe <l.s.r@web.de>
Fri, 1 Oct 2021 09:11:19 +0000 (11:11 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 1 Oct 2021 19:43:08 +0000 (12:43 -0700)
Give the code for sorting a text file its own sub-command.  This allows
extending the helper, which we'll do in the following patches.

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 621e2a519770b378ef3f4899d54587aff9e5be14..05be0d067ac8ca9f6266aae1a954f4801655b053 100644 (file)
@@ -23,7 +23,7 @@ static int compare_strings(const void *a, const void *b)
        return strcmp(x->text, y->text);
 }
 
-int cmd__mergesort(int argc, const char **argv)
+static int sort_stdin(void)
 {
        struct line *line, *p = NULL, *lines = NULL;
        struct strbuf sb = STRBUF_INIT;
@@ -49,3 +49,10 @@ int cmd__mergesort(int argc, const char **argv)
        }
        return 0;
 }
+
+int cmd__mergesort(int argc, const char **argv)
+{
+       if (argc == 2 && !strcmp(argv[1], "sort"))
+               return sort_stdin();
+       usage("test-tool mergesort sort");
+}