git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 3/4] test-tool: migrate read-cache-again to parse_options()

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Aug 24, 2021, 09:15 UTC
Message-ID
<patch-v2-3.4-a34e69eaa48-20210824T091204Z-avarab@gmail.com>
In-Reply-To
<cover-v2-0.4-00000000000-20210824T091204Z-avarab@gmail.com>

Change the newly added (but then mostly copy/pasted) read-cache-perf to use the parse_options() API. I have no plans to further modify read-cache-again, but making these commands consistent has a value in and of itself.

Since we check the "cnt = < 1" case now via more idiomatic post-parse_options() assertions we can move from the for-loop to a while-loop and ditch the "i" variable.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/helper/test-read-cache-again.c | 26 ++++++++++++++++++++------
 t/t7519-status-fsmonitor.sh      |  2 +-
 2 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/t/helper/test-read-cache-again.c b/t/helper/test-read-cache-again.c
index 707db036cb1..fa456ca229e 100644
--- a/t/helper/test-read-cache-again.c
+++ b/t/helper/test-read-cache-again.c
@@ -1,20 +1,34 @@
 #include "test-tool.h"
 #include "cache.h"
+#include "parse-options.h"
+
+static const char *read_cache_again_usage[] = {
+	"test-tool read-cache-again [<options>...] <file>",
+	NULL
+};
 
 int cmd__read_cache_again(int argc, const char **argv)
 {
 	struct repository *r = the_repository;
-	int i, cnt;
+	int cnt = 2;
 	const char *name;
+	struct option options[] = {
+		OPT_INTEGER(0, "count", &cnt, "number of passes"),
+		OPT_END()
+	};
 
-	if (argc != 2)
-		die("usage: test-tool read-cache-again <count> <file>");
-
-	cnt = strtol(argv[0], NULL, 0);
+	argc = parse_options(argc, argv, "test-tools", options,
+			     read_cache_again_usage, 0);
+	if (argc != 1)
+		usage_msg_opt("Too many arguments.", read_cache_again_usage,
+			      options);
+	if (cnt < 1)
+		usage_msg_opt("Need at least one pass.", read_cache_again_usage,
+			      options);
 	name = argv[2];
 
 	setup_git_directory();
-	for (i = 0; i < cnt; i++) {
+	while (cnt--) {
 		int pos;
 		repo_read_index(r);
 		refresh_index(r->index, REFRESH_QUIET,
diff --git a/t/t7519-status-fsmonitor.sh b/t/t7519-status-fsmonitor.sh
index 7de5fcb1bd7..817e642f58e 100755
--- a/t/t7519-status-fsmonitor.sh
+++ b/t/t7519-status-fsmonitor.sh
@@ -360,7 +360,7 @@ test_expect_success UNTRACKED_CACHE 'ignore .git changes when invalidating UNTR'
 test_expect_success 'discard_index() also discards fsmonitor info' '
 	test_config core.fsmonitor "$TEST_DIRECTORY/t7519/fsmonitor-all" &&
 	test_might_fail git update-index --refresh &&
-	test-tool read-cache-again 2 tracked >actual &&
+	test-tool read-cache-again --count=2 tracked >actual &&
 	printf "tracked is%s up to date\n" "" " not" >expect &&
 	test_cmp expect actual
 '
-- 
2.33.0.663.gbaff4edb973
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 14 of 18 in “test-tool: split up "read-cache" tool”
  1. 0/4 test-tool: split up "read-cache" toolÆvar Arnfjörð Bjarmason, Jun 7, 2021
  2. 4/4 read-cache perf: add a perf test for refresh_index()Ævar Arnfjörð Bjarmason, Jun 7, 2021
  3. 3/4 test-tools: migrate read-cache-again to parse_options()Ævar Arnfjörð Bjarmason, Jun 7, 2021
  4. 2/4 test-tools: migrate read-cache-perf to parse_options()Ævar Arnfjörð Bjarmason, Jun 7, 2021
  5. 1/4 test-tool: split up test-tool read-cacheÆvar Arnfjörð Bjarmason, Jun 7, 2021
  6. Junio C HamanoJun 7, 2021
  7. Ævar Arnfjörð BjarmasonJun 8, 2021
  8. Junio C HamanoJun 8, 2021
  9. Emily ShafferJun 30, 2021
  10. Ævar Arnfjörð BjarmasonJun 30, 2021
  11. 0/4 test-tool: split up "read-cache" toolÆvar Arnfjörð Bjarmason, Aug 24, 2021
  12. 1/4 test-tool: split up test-tool read-cacheÆvar Arnfjörð Bjarmason, Aug 24, 2021
  13. 2/4 test-tool: migrate read-cache-perf to parse_options()Ævar Arnfjörð Bjarmason, Aug 24, 2021
  14. 3/4 test-tool: migrate read-cache-again to parse_options()Ævar Arnfjörð Bjarmason, Aug 24, 2021
  15. 4/4 read-cache perf: add a perf test for refresh_index()Ævar Arnfjörð Bjarmason, Aug 24, 2021
  16. Taylor BlauAug 24, 2021
  17. Junio C HamanoAug 25, 2021
  18. Ævar Arnfjörð BjarmasonAug 27, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.