diff mbox series

[2/9] test-mergesort: add sort subcommand

Message ID f0a8c3c5-4c51-5128-42a3-3dadb8600a6f@web.de (mailing list archive)
State New, archived
Headers show
Series mergesort: improve tests and performance | expand

Commit Message

René Scharfe Oct. 1, 2021, 9:11 a.m. UTC
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>
---
 t/helper/test-mergesort.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

--
2.33.0

Comments

Junio C Hamano Oct. 1, 2021, 8:26 p.m. UTC | #1
René Scharfe <l.s.r@web.de> writes:

> 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.
> ...
> -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");
> +}

This smelled funny, as it would certainly have broken any existing
script in t/ that were using "test-tool mergesort <input".

But "git grep mergesort master -- t/" reveals that nobody uses it,
so we are safe ;-)
diff mbox series

Patch

diff --git a/t/helper/test-mergesort.c b/t/helper/test-mergesort.c
index 621e2a5197..05be0d067a 100644
--- a/t/helper/test-mergesort.c
+++ b/t/helper/test-mergesort.c
@@ -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");
+}