{"thread":{"id":"58306","subject":"[PATCH v4 1/3] t0021: avoid grepping for a Perl-specific string at filter output","startedAt":"2022-08-15T01:07:01Z","lastAt":"2022-08-19T22:18:02Z","messageCount":6,"participants":["Matheus Tavares","Johannes Schindelin","Junio C Hamano"],"isPatch":true,"patchVersion":4,"patchTotal":3},"messages":[{"id":"461208","messageId":"64dc9af1ad90c31e988ea8d6ece4a23a930d57d0.1660522524.git.matheus.bernardino@usp.br","threadId":"58306","inReplyTo":"cover.1660522524.git.matheus.bernardino@usp.br","subject":"[PATCH v4 1/3] t0021: avoid grepping for a Perl-specific string at filter output","fromName":"Matheus Tavares","fromEmail":"matheus.bernardino@usp.br","sentAt":"2022-08-15T01:06:36Z","receivedAt":"2022-08-15T01:07:01Z","isPatch":true,"sender":{"key":"matheus.tavb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/12701583?v=4"},"body":"This test sets the t0021/rot13-filter.pl script as a long-running\nprocess filter for a git checkout command. It then expects the filter to\nfail producing a specific error message at stderr. In the following\ncommits we are going to replace the script with a C test-tool helper,\nbut the test currently expects the error message in a Perl-specific\nformat. That is, when you call `die <msg>` in Perl, it emits\n\"<msg> at - line 1.\" In preparation for the conversion, let's avoid the\nPerl-specific part and only grep for <msg> itself.\n\nSigned-off-by: Matheus Tavares <matheus.bernardino@usp.br>\n---\n t/t0021-conversion.sh | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/t/t0021-conversion.sh b/t/t0021-conversion.sh\nindex 1c840348bd..963b66e08c 100755\n--- a/t/t0021-conversion.sh\n+++ b/t/t0021-conversion.sh\n@@ -735,7 +735,7 @@ test_expect_success PERL 'process filter should restart after unexpected write f\n \t\trm -f debug.log &&\n \t\tgit checkout --quiet --no-progress . 2>git-stderr.log &&\n \n-\t\tgrep \"smudge write error at\" git-stderr.log &&\n+\t\tgrep \"smudge write error\" git-stderr.log &&\n \t\ttest_i18ngrep \"error: external filter\" git-stderr.log &&\n \n \t\tcat >expected.log <<-EOF &&\n-- \n2.37.1\n\n"},{"id":"461209","messageId":"cover.1660522524.git.matheus.bernardino@usp.br","threadId":"58306","inReplyTo":"cover.1659291025.git.matheus.bernardino@usp.br","subject":"[PATCH v4 0/3] t0021: convert perl script to C test-tool helper","fromName":"Matheus Tavares","fromEmail":"matheus.bernardino@usp.br","sentAt":"2022-08-15T01:06:35Z","receivedAt":"2022-08-15T01:07:03Z","isPatch":true,"sender":{"key":"matheus.tavb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/12701583?v=4"},"body":"Convert t/t0021/rot13-filter.pl to a test-tool helper to avoid the PERL\nprereq in various tests.\n\nMain changes since v3:\nPatch 2:\n- Mentioned in commit message why we removed the flush() calls for the\n  log file handler.\n- Removed 'buf[size] = \\0' and relied on the fact that packet_read()\n  already 0-terminates the buffer. This also allows us to use NULL\n  instead of &size in many places, dropping down the unneeded variable.\n- Used parse-options instead of manual argv fiddling. I'm not strongly\n  about one way or another, but I found the parse-options slightly\n  easier for new options that may be added in the future.\n- Style: removed unnecessary {} and newline.\n\nNotes:\n- About the s/die()/BUG()/ suggestion: I ended up leaving the die()\n  calls because this seems to be the preferred mechanics at the\n  t/helper/*.c files.\n\n- About the suggestion of dropping the dot printing from Dscho: I really\n  wished we could do that because I dislike the huge function name at\n  pkt-line.*. Unfortunately, though, many tests in t0021-conversion.sh\n  do seem to rely on the number of dots printed to the log file to check\n  the proper number of packets sent. See e.g. the test 'required process\n  filter should process multiple packets'.\n\nMatheus Tavares (3):\n  t0021: avoid grepping for a Perl-specific string at filter output\n  t0021: implementation the rot13-filter.pl script in C\n  tests: use the new C rot13-filter helper to avoid PERL prereq\n\n Makefile                                |   1 +\n pkt-line.c                              |   5 +-\n pkt-line.h                              |   8 +-\n t/helper/test-rot13-filter.c            | 382 ++++++++++++++++++++++++\n t/helper/test-tool.c                    |   1 +\n t/helper/test-tool.h                    |   1 +\n t/t0021-conversion.sh                   |  71 +++--\n t/t0021/rot13-filter.pl                 | 247 ---------------\n t/t2080-parallel-checkout-basics.sh     |   7 +-\n t/t2082-parallel-checkout-attributes.sh |   7 +-\n 10 files changed, 434 insertions(+), 296 deletions(-)\n create mode 100644 t/helper/test-rot13-filter.c\n delete mode 100644 t/t0021/rot13-filter.pl\n\nRange-diff against v3:\n1:  5ec95c7e69 = 1:  64dc9af1ad t0021: avoid grepping for a Perl-specific string at filter output\n2:  86e6baba46 ! 2:  99d8458f35 t0021: implementation the rot13-filter.pl script in C\n    @@ Commit message\n         command. The following commit will take care of actually modifying the\n         said tests to use the new C helper and removing the Perl script.\n     \n    +    The Perl script flushes the log file handler after each write. As\n    +    commented in [1], this seems to be an early design decision that was\n    +    later reconsidered, but possibly ended up being left in the code by\n    +    accident:\n    +\n    +            >> +$debug->flush();T\n    +            >\n    +            > Isn't $debug flushed automatically?\n    +\n    +            Maybe, but autoflush is not explicitly enabled. I will\n    +            enable it again (I disabled it because of Eric's comment\n    +            but I re-read the comment and he is only talking about\n    +            pipes).\n    +\n    +    Anyways, this behavior is not really needed for the tests and the\n    +    flush() calls make the code slightly larger, so let's avoid them\n    +    altogether in the new C version.\n    +\n    +    [1]: https://lore.kernel.org/git/7F1F1A0E-8FC3-4FBD-81AA-37786DE0EF50@gmail.com/\n    +\n         Helped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n         Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br>\n     \n    @@ t/helper/test-rot13-filter.c (new)\n     + * Example implementation for the Git filter protocol version 2\n     + * See Documentation/gitattributes.txt, section \"Filter Protocol\"\n     + *\n    -+ * Usage: test-tool rot13-filter [--always-delay] <log path> <capabilities>\n    ++ * Usage: test-tool rot13-filter [--always-delay] --log=<path> <capabilities>\n     + *\n     + * Log path defines a debug log file that the script writes to. The\n     + * subsequent arguments define a list of supported protocol capabilities\n    @@ t/helper/test-rot13-filter.c (new)\n     +#include \"pkt-line.h\"\n     +#include \"string-list.h\"\n     +#include \"strmap.h\"\n    ++#include \"parse-options.h\"\n     +\n     +static FILE *logfile;\n     +static int always_delay, has_clean_cap, has_smudge_cap;\n     +static struct strmap delay = STRMAP_INIT;\n     +\n    ++static inline const char *str_or_null(const char *str)\n    ++{\n    ++\treturn str ? str : \"(null)\";\n    ++}\n    ++\n     +static char *rot13(char *str)\n     +{\n     +\tchar *c;\n    @@ t/helper/test-rot13-filter.c (new)\n     +\treturn str;\n     +}\n     +\n    -+static char *get_value(char *buf, size_t size, const char *key)\n    ++static char *get_value(char *buf, const char *key)\n     +{\n     +\tconst char *orig_buf = buf;\n    -+\tint orig_size = (int)size;\n    -+\n    -+\tif (!skip_prefix_mem((const char *)buf, size, key, (const char **)&buf, &size) ||\n    -+\t    !skip_prefix_mem((const char *)buf, size, \"=\", (const char **)&buf, &size) ||\n    -+\t    !size)\n    -+\t\tdie(\"expected key '%s', got '%.*s'\",\n    -+\t\t    key, orig_size, orig_buf);\n    -+\n    -+\tbuf[size] = '\\0';\n    ++\tif (!buf ||\n    ++\t    !skip_prefix((const char *)buf, key, (const char **)&buf) ||\n    ++\t    !skip_prefix((const char *)buf, \"=\", (const char **)&buf) ||\n    ++\t    !*buf)\n    ++\t\tdie(\"expected key '%s', got '%s'\", key, str_or_null(orig_buf));\n     +\treturn buf;\n     +}\n     +\n    @@ t/helper/test-rot13-filter.c (new)\n     + */\n     +static char *packet_key_val_read(const char *key)\n     +{\n    -+\tint size;\n     +\tchar *buf;\n    -+\tif (packet_read_line_gently(0, &size, &buf) < 0)\n    ++\tif (packet_read_line_gently(0, NULL, &buf) < 0)\n     +\t\treturn NULL;\n    -+\treturn xstrdup(get_value(buf, size, key));\n    ++\treturn xstrdup(get_value(buf, key));\n     +}\n     +\n     +static inline void assert_remote_capability(struct strset *caps, const char *cap)\n    @@ t/helper/test-rot13-filter.c (new)\n     +static void read_capabilities(struct strset *remote_caps)\n     +{\n     +\tfor (;;) {\n    -+\t\tint size;\n    -+\t\tchar *buf = packet_read_line(0, &size);\n    ++\t\tchar *buf = packet_read_line(0, NULL);\n     +\t\tif (!buf)\n     +\t\t\tbreak;\n    -+\t\tstrset_add(remote_caps, get_value(buf, size, \"capability\"));\n    ++\t\tstrset_add(remote_caps, get_value(buf, \"capability\"));\n     +\t}\n     +\n     +\tassert_remote_capability(remote_caps, \"clean\");\n    @@ t/helper/test-rot13-filter.c (new)\n     +}\n     +\n     +static void check_and_write_capabilities(struct strset *remote_caps,\n    -+\t\t\t\t\t const char **caps, int caps_count)\n    ++\t\t\t\t\t const char **caps, int nr_caps)\n     +{\n     +\tint i;\n    -+\tfor (i = 0; i < caps_count; i++) {\n    ++\tfor (i = 0; i < nr_caps; i++) {\n     +\t\tif (!strset_contains(remote_caps, caps[i]))\n     +\t\t\tdie(\"our capability '%s' is not available from remote\",\n     +\t\t\t    caps[i]);\n    @@ t/helper/test-rot13-filter.c (new)\n     +{\n     +\tfor (;;) {\n     +\t\tchar *buf, *output;\n    -+\t\tint size;\n     +\t\tchar *pathname;\n     +\t\tstruct delay_entry *entry;\n     +\t\tstruct strbuf input = STRBUF_INIT;\n    @@ t/helper/test-rot13-filter.c (new)\n     +\t\tfprintf(logfile, \" %s\", pathname);\n     +\n     +\t\t/* Read until flush */\n    -+\t\twhile ((buf = packet_read_line(0, &size))) {\n    ++\t\twhile ((buf = packet_read_line(0, NULL))) {\n     +\t\t\tif (!strcmp(buf, \"can-delay=1\")) {\n     +\t\t\t\tentry = strmap_get(&delay, pathname);\n    -+\t\t\t\tif (entry && !entry->requested) {\n    ++\t\t\t\tif (entry && !entry->requested)\n     +\t\t\t\t\tentry->requested = 1;\n    -+\t\t\t\t} else if (!entry && always_delay) {\n    ++\t\t\t\telse if (!entry && always_delay)\n     +\t\t\t\t\tadd_delay_entry(pathname, 1, 1);\n    -+\t\t\t\t}\n     +\t\t\t} else if (starts_with(buf, \"ref=\") ||\n     +\t\t\t\t   starts_with(buf, \"treeish=\") ||\n     +\t\t\t\t   starts_with(buf, \"blob=\")) {\n    @@ t/helper/test-rot13-filter.c (new)\n     +\t\t\t}\n     +\t\t}\n     +\n    -+\n     +\t\tread_packetized_to_strbuf(0, &input, 0);\n     +\t\tfprintf(logfile, \" %\"PRIuMAX\" [OK] -- \", (uintmax_t)input.len);\n     +\n    @@ t/helper/test-rot13-filter.c (new)\n     +\n     +static void packet_initialize(void)\n     +{\n    -+\tint size;\n    -+\tchar *pkt_buf = packet_read_line(0, &size);\n    ++\tchar *pkt_buf = packet_read_line(0, NULL);\n     +\n    -+\tif (!pkt_buf || strncmp(pkt_buf, \"git-filter-client\", size))\n    -+\t\tdie(\"bad initialize: '%s'\", xstrndup(pkt_buf, size));\n    ++\tif (!pkt_buf || strcmp(pkt_buf, \"git-filter-client\"))\n    ++\t\tdie(\"bad initialize: '%s'\", str_or_null(pkt_buf));\n     +\n    -+\tpkt_buf = packet_read_line(0, &size);\n    -+\tif (!pkt_buf || strncmp(pkt_buf, \"version=2\", size))\n    -+\t\tdie(\"bad version: '%.*s'\", (int)size, pkt_buf);\n    ++\tpkt_buf = packet_read_line(0, NULL);\n    ++\tif (!pkt_buf || strcmp(pkt_buf, \"version=2\"))\n    ++\t\tdie(\"bad version: '%s'\", str_or_null(pkt_buf));\n     +\n    -+\tpkt_buf = packet_read_line(0, &size);\n    ++\tpkt_buf = packet_read_line(0, NULL);\n     +\tif (pkt_buf)\n    -+\t\tdie(\"bad version end: '%.*s'\", (int)size, pkt_buf);\n    ++\t\tdie(\"bad version end: '%s'\", pkt_buf);\n     +\n     +\tpacket_write_fmt(1, \"git-filter-server\");\n     +\tpacket_write_fmt(1, \"version=2\");\n     +\tpacket_flush(1);\n     +}\n     +\n    -+static char *rot13_usage = \"test-tool rot13-filter [--always-delay] <log path> <capabilities>\";\n    ++static const char *rot13_usage[] = {\n    ++\t\"test-tool rot13-filter [--always-delay] --log=<path> <capabilities>\",\n    ++\tNULL\n    ++};\n     +\n     +int cmd__rot13_filter(int argc, const char **argv)\n     +{\n    -+\tconst char **caps;\n    -+\tint cap_count, i = 1;\n    ++\tint i, nr_caps;\n     +\tstruct strset remote_caps = STRSET_INIT;\n    ++\tconst char *log_path = NULL;\n     +\n    -+\tif (argc > 1 && !strcmp(argv[1], \"--always-delay\")) {\n    -+\t\talways_delay = 1;\n    -+\t\ti++;\n    -+\t}\n    -+\tif (argc - i < 2)\n    -+\t\tusage(rot13_usage);\n    ++\tstruct option options[] = {\n    ++\t\tOPT_BOOL(0, \"always-delay\", &always_delay,\n    ++\t\t\t \"delay all paths with the can-delay flag\"),\n    ++\t\tOPT_STRING(0, \"log\", &log_path, \"path\",\n    ++\t\t\t   \"path to the debug log file\"),\n    ++\t\tOPT_END()\n    ++\t};\n    ++\tnr_caps = parse_options(argc, argv, NULL, options, rot13_usage,\n    ++\t\t\t\tPARSE_OPT_STOP_AT_NON_OPTION);\n     +\n    -+\tlogfile = fopen(argv[i++], \"a\");\n    ++\tif (!log_path || !nr_caps)\n    ++\t\tusage_with_options(rot13_usage, options);\n    ++\n    ++\tlogfile = fopen(log_path, \"a\");\n     +\tif (!logfile)\n     +\t\tdie_errno(\"failed to open log file\");\n     +\n    -+\tcaps = argv + i;\n    -+\tcap_count = argc - i;\n    -+\n    -+\tfor (i = 0; i < cap_count; i++) {\n    -+\t\tif (!strcmp(caps[i], \"clean\"))\n    -+\t\t\thas_clean_cap = 1;\n    -+\t\telse if (!strcmp(caps[i], \"smudge\"))\n    ++\tfor (i = 0; i < nr_caps; i++) {\n    ++\t\tif (!strcmp(argv[i], \"smudge\"))\n     +\t\t\thas_smudge_cap = 1;\n    ++\t\tif (!strcmp(argv[i], \"clean\"))\n    ++\t\t\thas_clean_cap = 1;\n     +\t}\n     +\n     +\tadd_delay_entry(\"test-delay10.a\", 1, 0);\n    @@ t/helper/test-rot13-filter.c (new)\n     +\tpacket_initialize();\n     +\n     +\tread_capabilities(&remote_caps);\n    -+\tcheck_and_write_capabilities(&remote_caps, caps, cap_count);\n    ++\tcheck_and_write_capabilities(&remote_caps, argv, nr_caps);\n     +\tfprintf(logfile, \"init handshake complete\\n\");\n     +\tstrset_clear(&remote_caps);\n     +\n     +\tcommand_loop();\n     +\n    -+\tfclose(logfile);\n    ++\tif (fclose(logfile))\n    ++\t\tdie_errno(\"error closing logfile\");\n     +\tfree_delay_entries();\n     +\treturn 0;\n     +}\n3:  c66fc0a186 ! 3:  d6033abbce tests: use the new C rot13-filter helper to avoid PERL prereq\n    @@ t/t0021-conversion.sh: test_expect_success 'diff does not reuse worktree files t\n     -test_expect_success PERL 'required process filter should filter data' '\n     -\ttest_config_global filter.protocol.process \"rot13-filter.pl debug.log clean smudge\" &&\n     +test_expect_success 'required process filter should filter data' '\n    -+\ttest_config_global filter.protocol.process \"test-tool rot13-filter debug.log clean smudge\" &&\n    ++\ttest_config_global filter.protocol.process \"test-tool rot13-filter --log=debug.log clean smudge\" &&\n      \ttest_config_global filter.protocol.required true &&\n      \trm -rf repo &&\n      \tmkdir repo &&\n    @@ t/t0021-conversion.sh: test_expect_success PERL 'required process filter should\n     -test_expect_success PERL 'required process filter should filter data for various subcommands' '\n     -\ttest_config_global filter.protocol.process \"rot13-filter.pl debug.log clean smudge\" &&\n     +test_expect_success 'required process filter should filter data for various subcommands' '\n    -+\ttest_config_global filter.protocol.process \"test-tool rot13-filter debug.log clean smudge\" &&\n    ++\ttest_config_global filter.protocol.process \"test-tool rot13-filter --log=debug.log clean smudge\" &&\n      \ttest_config_global filter.protocol.required true &&\n      \t(\n      \t\tcd repo &&\n    @@ t/t0021-conversion.sh: test_expect_success PERL 'required process filter should\n     +test_expect_success 'required process filter takes precedence' '\n      \ttest_config_global filter.protocol.clean false &&\n     -\ttest_config_global filter.protocol.process \"rot13-filter.pl debug.log clean\" &&\n    -+\ttest_config_global filter.protocol.process \"test-tool rot13-filter debug.log clean\" &&\n    ++\ttest_config_global filter.protocol.process \"test-tool rot13-filter --log=debug.log clean\" &&\n      \ttest_config_global filter.protocol.required true &&\n      \trm -rf repo &&\n      \tmkdir repo &&\n    @@ t/t0021-conversion.sh: test_expect_success PERL 'required process filter takes p\n     -test_expect_success PERL 'required process filter should be used only for \"clean\" operation only' '\n     -\ttest_config_global filter.protocol.process \"rot13-filter.pl debug.log clean\" &&\n     +test_expect_success 'required process filter should be used only for \"clean\" operation only' '\n    -+\ttest_config_global filter.protocol.process \"test-tool rot13-filter debug.log clean\" &&\n    ++\ttest_config_global filter.protocol.process \"test-tool rot13-filter --log=debug.log clean\" &&\n      \trm -rf repo &&\n      \tmkdir repo &&\n      \t(\n    @@ t/t0021-conversion.sh: test_expect_success PERL 'required process filter should\n     -test_expect_success PERL 'required process filter should process multiple packets' '\n     -\ttest_config_global filter.protocol.process \"rot13-filter.pl debug.log clean smudge\" &&\n     +test_expect_success 'required process filter should process multiple packets' '\n    -+\ttest_config_global filter.protocol.process \"test-tool rot13-filter debug.log clean smudge\" &&\n    ++\ttest_config_global filter.protocol.process \"test-tool rot13-filter --log=debug.log clean smudge\" &&\n      \ttest_config_global filter.protocol.required true &&\n      \n      \trm -rf repo &&\n    @@ t/t0021-conversion.sh: test_expect_success PERL 'required process filter should\n     -test_expect_success PERL 'required process filter with clean error should fail' '\n     -\ttest_config_global filter.protocol.process \"rot13-filter.pl debug.log clean smudge\" &&\n     +test_expect_success 'required process filter with clean error should fail' '\n    -+\ttest_config_global filter.protocol.process \"test-tool rot13-filter debug.log clean smudge\" &&\n    ++\ttest_config_global filter.protocol.process \"test-tool rot13-filter --log=debug.log clean smudge\" &&\n      \ttest_config_global filter.protocol.required true &&\n      \trm -rf repo &&\n      \tmkdir repo &&\n    @@ t/t0021-conversion.sh: test_expect_success PERL 'required process filter with cl\n     -test_expect_success PERL 'process filter should restart after unexpected write failure' '\n     -\ttest_config_global filter.protocol.process \"rot13-filter.pl debug.log clean smudge\" &&\n     +test_expect_success 'process filter should restart after unexpected write failure' '\n    -+\ttest_config_global filter.protocol.process \"test-tool rot13-filter debug.log clean smudge\" &&\n    ++\ttest_config_global filter.protocol.process \"test-tool rot13-filter --log=debug.log clean smudge\" &&\n      \trm -rf repo &&\n      \tmkdir repo &&\n      \t(\n    @@ t/t0021-conversion.sh: test_expect_success PERL 'process filter should restart a\n     -test_expect_success PERL 'process filter should not be restarted if it signals an error' '\n     -\ttest_config_global filter.protocol.process \"rot13-filter.pl debug.log clean smudge\" &&\n     +test_expect_success 'process filter should not be restarted if it signals an error' '\n    -+\ttest_config_global filter.protocol.process \"test-tool rot13-filter debug.log clean smudge\" &&\n    ++\ttest_config_global filter.protocol.process \"test-tool rot13-filter --log=debug.log clean smudge\" &&\n      \trm -rf repo &&\n      \tmkdir repo &&\n      \t(\n    @@ t/t0021-conversion.sh: test_expect_success PERL 'process filter should not be re\n     -test_expect_success PERL 'process filter abort stops processing of all further files' '\n     -\ttest_config_global filter.protocol.process \"rot13-filter.pl debug.log clean smudge\" &&\n     +test_expect_success 'process filter abort stops processing of all further files' '\n    -+\ttest_config_global filter.protocol.process \"test-tool rot13-filter debug.log clean smudge\" &&\n    ++\ttest_config_global filter.protocol.process \"test-tool rot13-filter --log=debug.log clean smudge\" &&\n      \trm -rf repo &&\n      \tmkdir repo &&\n      \t(\n    @@ t/t0021-conversion.sh: test_expect_success PERL 'invalid process filter must fai\n     -test_expect_success PERL 'delayed checkout in process filter' '\n     -\ttest_config_global filter.a.process \"rot13-filter.pl a.log clean smudge delay\" &&\n     +test_expect_success 'delayed checkout in process filter' '\n    -+\ttest_config_global filter.a.process \"test-tool rot13-filter a.log clean smudge delay\" &&\n    ++\ttest_config_global filter.a.process \"test-tool rot13-filter --log=a.log clean smudge delay\" &&\n      \ttest_config_global filter.a.required true &&\n     -\ttest_config_global filter.b.process \"rot13-filter.pl b.log clean smudge delay\" &&\n    -+\ttest_config_global filter.b.process \"test-tool rot13-filter b.log clean smudge delay\" &&\n    ++\ttest_config_global filter.b.process \"test-tool rot13-filter --log=b.log clean smudge delay\" &&\n      \ttest_config_global filter.b.required true &&\n      \n      \trm -rf repo &&\n    @@ t/t0021-conversion.sh: test_expect_success PERL 'delayed checkout in process fil\n     -test_expect_success PERL 'missing file in delayed checkout' '\n     -\ttest_config_global filter.bug.process \"rot13-filter.pl bug.log clean smudge delay\" &&\n     +test_expect_success 'missing file in delayed checkout' '\n    -+\ttest_config_global filter.bug.process \"test-tool rot13-filter bug.log clean smudge delay\" &&\n    ++\ttest_config_global filter.bug.process \"test-tool rot13-filter --log=bug.log clean smudge delay\" &&\n      \ttest_config_global filter.bug.required true &&\n      \n      \trm -rf repo &&\n    @@ t/t0021-conversion.sh: test_expect_success PERL 'missing file in delayed checkou\n     -test_expect_success PERL 'invalid file in delayed checkout' '\n     -\ttest_config_global filter.bug.process \"rot13-filter.pl bug.log clean smudge delay\" &&\n     +test_expect_success 'invalid file in delayed checkout' '\n    -+\ttest_config_global filter.bug.process \"test-tool rot13-filter bug.log clean smudge delay\" &&\n    ++\ttest_config_global filter.bug.process \"test-tool rot13-filter --log=bug.log clean smudge delay\" &&\n      \ttest_config_global filter.bug.required true &&\n      \n      \trm -rf repo &&\n    @@ t/t0021-conversion.sh: do\n      \t\"delayed checkout with $mode-collision don't write to the wrong place\" '\n      \t\ttest_config_global filter.delay.process \\\n     -\t\t\t\"\\\"$TEST_ROOT/rot13-filter.pl\\\" --always-delay delayed.log clean smudge delay\" &&\n    -+\t\t\t\"test-tool rot13-filter --always-delay delayed.log clean smudge delay\" &&\n    ++\t\t\t\"test-tool rot13-filter --always-delay --log=delayed.log clean smudge delay\" &&\n      \t\ttest_config_global filter.delay.required true &&\n      \n      \t\tgit init $mode-collision &&\n    @@ t/t0021-conversion.sh: do\n      \t(\n      \t\tcd collision-with-submodule &&\n     -\t\tgit config filter.delay.process \"\\\"$TEST_ROOT/rot13-filter.pl\\\" --always-delay delayed.log clean smudge delay\" &&\n    -+\t\tgit config filter.delay.process \"test-tool rot13-filter --always-delay delayed.log clean smudge delay\" &&\n    ++\t\tgit config filter.delay.process \"test-tool rot13-filter --always-delay --log=delayed.log clean smudge delay\" &&\n      \t\tgit config filter.delay.required true &&\n      \n      \t\t# We need Git to treat the submodule \"a\" and the\n    @@ t/t0021-conversion.sh: test_expect_success PERL,SYMLINKS,CASE_INSENSITIVE_FS \\\n      \t(\n      \t\tcd progress &&\n     -\t\tgit config filter.delay.process \"rot13-filter.pl delay-progress.log clean smudge delay\" &&\n    -+\t\tgit config filter.delay.process \"test-tool rot13-filter delay-progress.log clean smudge delay\" &&\n    ++\t\tgit config filter.delay.process \"test-tool rot13-filter --log=delay-progress.log clean smudge delay\" &&\n      \t\tgit config filter.delay.required true &&\n      \n      \t\techo \"*.a filter=delay\" >.gitattributes &&\n    @@ t/t0021-conversion.sh: do\n      \t(\n      \t\tcd repo &&\n     -\t\tgit config filter.delay.process \"../rot13-filter.pl delayed.log clean smudge delay\" &&\n    -+\t\tgit config filter.delay.process \"test-tool rot13-filter delayed.log clean smudge delay\" &&\n    ++\t\tgit config filter.delay.process \"test-tool rot13-filter --log=delayed.log clean smudge delay\" &&\n      \t\tgit config filter.delay.required true &&\n      \n      \t\techo \"*.a filter=delay\" >.gitattributes &&\n    @@ t/t2080-parallel-checkout-basics.sh: test_expect_success SYMLINKS 'parallel chec\n     +test_expect_success '\"git checkout .\" report should not include failed entries' '\n      \ttest_config_global filter.delay.process \\\n     -\t\t\"\\\"$(pwd)/rot13-filter.pl\\\" --always-delay delayed.log clean smudge delay\" &&\n    -+\t\t\"test-tool rot13-filter --always-delay delayed.log clean smudge delay\" &&\n    ++\t\t\"test-tool rot13-filter --always-delay --log=delayed.log clean smudge delay\" &&\n      \ttest_config_global filter.delay.required true &&\n      \ttest_config_global filter.cat.clean cat  &&\n      \ttest_config_global filter.cat.smudge cat  &&\n    @@ t/t2082-parallel-checkout-attributes.sh: test_expect_success 'parallel-checkout\n     +test_expect_success 'parallel-checkout and delayed checkout' '\n      \ttest_config_global filter.delay.process \\\n     -\t\t\"\\\"$(pwd)/rot13-filter.pl\\\" --always-delay \\\"$(pwd)/delayed.log\\\" clean smudge delay\" &&\n    -+\t\t\"test-tool rot13-filter --always-delay \\\"$(pwd)/delayed.log\\\" clean smudge delay\" &&\n    ++\t\t\"test-tool rot13-filter --always-delay --log=\\\"$(pwd)/delayed.log\\\" clean smudge delay\" &&\n      \ttest_config_global filter.delay.required true &&\n      \n      \techo \"abcd\" >original &&\n-- \n2.37.1\n\n"},{"id":"461210","messageId":"99d8458f35e5ed8dbb696a3f1f27e1704d17de38.1660522524.git.matheus.bernardino@usp.br","threadId":"58306","inReplyTo":"cover.1660522524.git.matheus.bernardino@usp.br","subject":"[PATCH v4 2/3] t0021: implementation the rot13-filter.pl script in C","fromName":"Matheus Tavares","fromEmail":"matheus.bernardino@usp.br","sentAt":"2022-08-15T01:06:37Z","receivedAt":"2022-08-15T01:07:09Z","isPatch":true,"sender":{"key":"matheus.tavb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/12701583?v=4"},"body":"This script is currently used by three test files: t0021-conversion.sh,\nt2080-parallel-checkout-basics.sh, and\nt2082-parallel-checkout-attributes.sh. To avoid the need for the PERL\ndependency at these tests, let's convert the script to a C test-tool\ncommand. The following commit will take care of actually modifying the\nsaid tests to use the new C helper and removing the Perl script.\n\nThe Perl script flushes the log file handler after each write. As\ncommented in [1], this seems to be an early design decision that was\nlater reconsidered, but possibly ended up being left in the code by\naccident:\n\n\t>> +$debug->flush();\n\t>\n\t> Isn't $debug flushed automatically?\n\n\tMaybe, but autoflush is not explicitly enabled. I will\n\tenable it again (I disabled it because of Eric's comment\n\tbut I re-read the comment and he is only talking about\n\tpipes).\n\nAnyways, this behavior is not really needed for the tests and the\nflush() calls make the code slightly larger, so let's avoid them\naltogether in the new C version.\n\n[1]: https://lore.kernel.org/git/7F1F1A0E-8FC3-4FBD-81AA-37786DE0EF50@gmail.com/\n\nHelped-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\nSigned-off-by: Matheus Tavares <matheus.bernardino@usp.br>\n---\n Makefile                     |   1 +\n pkt-line.c                   |   5 +-\n pkt-line.h                   |   8 +-\n t/helper/test-rot13-filter.c | 382 +++++++++++++++++++++++++++++++++++\n t/helper/test-tool.c         |   1 +\n t/helper/test-tool.h         |   1 +\n 6 files changed, 396 insertions(+), 2 deletions(-)\n create mode 100644 t/helper/test-rot13-filter.c\n\ndiff --git a/Makefile b/Makefile\nindex 2ec9b2dc6b..ae7def7c66 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -772,6 +772,7 @@ TEST_BUILTINS_OBJS += test-read-midx.o\n TEST_BUILTINS_OBJS += test-ref-store.o\n TEST_BUILTINS_OBJS += test-reftable.o\n TEST_BUILTINS_OBJS += test-regex.o\n+TEST_BUILTINS_OBJS += test-rot13-filter.o\n TEST_BUILTINS_OBJS += test-repository.o\n TEST_BUILTINS_OBJS += test-revision-walking.o\n TEST_BUILTINS_OBJS += test-run-command.o\ndiff --git a/pkt-line.c b/pkt-line.c\nindex 8e43c2def4..ce4e73b683 100644\n--- a/pkt-line.c\n+++ b/pkt-line.c\n@@ -309,7 +309,8 @@ int write_packetized_from_fd_no_flush(int fd_in, int fd_out)\n \treturn err;\n }\n \n-int write_packetized_from_buf_no_flush(const char *src_in, size_t len, int fd_out)\n+int write_packetized_from_buf_no_flush_count(const char *src_in, size_t len,\n+\t\t\t\t\t     int fd_out, int *packet_counter)\n {\n \tint err = 0;\n \tsize_t bytes_written = 0;\n@@ -324,6 +325,8 @@ int write_packetized_from_buf_no_flush(const char *src_in, size_t len, int fd_ou\n \t\t\tbreak;\n \t\terr = packet_write_gently(fd_out, src_in + bytes_written, bytes_to_write);\n \t\tbytes_written += bytes_to_write;\n+\t\tif (packet_counter)\n+\t\t\t(*packet_counter)++;\n \t}\n \treturn err;\n }\ndiff --git a/pkt-line.h b/pkt-line.h\nindex 1f623de60a..79c538b99e 100644\n--- a/pkt-line.h\n+++ b/pkt-line.h\n@@ -32,7 +32,13 @@ void packet_buf_write(struct strbuf *buf, const char *fmt, ...) __attribute__((f\n int packet_flush_gently(int fd);\n int packet_write_fmt_gently(int fd, const char *fmt, ...) __attribute__((format (printf, 2, 3)));\n int write_packetized_from_fd_no_flush(int fd_in, int fd_out);\n-int write_packetized_from_buf_no_flush(const char *src_in, size_t len, int fd_out);\n+int write_packetized_from_buf_no_flush_count(const char *src_in, size_t len,\n+\t\t\t\t\t     int fd_out, int *packet_counter);\n+static inline int write_packetized_from_buf_no_flush(const char *src_in,\n+\t\t\t\t\t\t     size_t len, int fd_out)\n+{\n+\treturn write_packetized_from_buf_no_flush_count(src_in, len, fd_out, NULL);\n+}\n \n /*\n  * Stdio versions of packet_write functions. When mixing these with fd\ndiff --git a/t/helper/test-rot13-filter.c b/t/helper/test-rot13-filter.c\nnew file mode 100644\nindex 0000000000..f8d564c622\n--- /dev/null\n+++ b/t/helper/test-rot13-filter.c\n@@ -0,0 +1,382 @@\n+/*\n+ * Example implementation for the Git filter protocol version 2\n+ * See Documentation/gitattributes.txt, section \"Filter Protocol\"\n+ *\n+ * Usage: test-tool rot13-filter [--always-delay] --log=<path> <capabilities>\n+ *\n+ * Log path defines a debug log file that the script writes to. The\n+ * subsequent arguments define a list of supported protocol capabilities\n+ * (\"clean\", \"smudge\", etc).\n+ *\n+ * When --always-delay is given all pathnames with the \"can-delay\" flag\n+ * that don't appear on the list bellow are delayed with a count of 1\n+ * (see more below).\n+ *\n+ * This implementation supports special test cases:\n+ * (1) If data with the pathname \"clean-write-fail.r\" is processed with\n+ *     a \"clean\" operation then the write operation will die.\n+ * (2) If data with the pathname \"smudge-write-fail.r\" is processed with\n+ *     a \"smudge\" operation then the write operation will die.\n+ * (3) If data with the pathname \"error.r\" is processed with any\n+ *     operation then the filter signals that it cannot or does not want\n+ *     to process the file.\n+ * (4) If data with the pathname \"abort.r\" is processed with any\n+ *     operation then the filter signals that it cannot or does not want\n+ *     to process the file and any file after that is processed with the\n+ *     same command.\n+ * (5) If data with a pathname that is a key in the delay hash is\n+ *     requested (e.g. \"test-delay10.a\") then the filter responds with\n+ *     a \"delay\" status and sets the \"requested\" field in the delay hash.\n+ *     The filter will signal the availability of this object after\n+ *     \"count\" (field in delay hash) \"list_available_blobs\" commands.\n+ * (6) If data with the pathname \"missing-delay.a\" is processed that the\n+ *     filter will drop the path from the \"list_available_blobs\" response.\n+ * (7) If data with the pathname \"invalid-delay.a\" is processed that the\n+ *     filter will add the path \"unfiltered\" which was not delayed before\n+ *     to the \"list_available_blobs\" response.\n+ */\n+\n+#include \"test-tool.h\"\n+#include \"pkt-line.h\"\n+#include \"string-list.h\"\n+#include \"strmap.h\"\n+#include \"parse-options.h\"\n+\n+static FILE *logfile;\n+static int always_delay, has_clean_cap, has_smudge_cap;\n+static struct strmap delay = STRMAP_INIT;\n+\n+static inline const char *str_or_null(const char *str)\n+{\n+\treturn str ? str : \"(null)\";\n+}\n+\n+static char *rot13(char *str)\n+{\n+\tchar *c;\n+\tfor (c = str; *c; c++)\n+\t\tif (isalpha(*c))\n+\t\t\t*c += tolower(*c) < 'n' ? 13 : -13;\n+\treturn str;\n+}\n+\n+static char *get_value(char *buf, const char *key)\n+{\n+\tconst char *orig_buf = buf;\n+\tif (!buf ||\n+\t    !skip_prefix((const char *)buf, key, (const char **)&buf) ||\n+\t    !skip_prefix((const char *)buf, \"=\", (const char **)&buf) ||\n+\t    !*buf)\n+\t\tdie(\"expected key '%s', got '%s'\", key, str_or_null(orig_buf));\n+\treturn buf;\n+}\n+\n+/*\n+ * Read a text packet, expecting that it is in the form \"key=value\" for\n+ * the given key. An EOF does not trigger any error and is reported\n+ * back to the caller with NULL. Die if the \"key\" part of \"key=value\" does\n+ * not match the given key, or the value part is empty.\n+ */\n+static char *packet_key_val_read(const char *key)\n+{\n+\tchar *buf;\n+\tif (packet_read_line_gently(0, NULL, &buf) < 0)\n+\t\treturn NULL;\n+\treturn xstrdup(get_value(buf, key));\n+}\n+\n+static inline void assert_remote_capability(struct strset *caps, const char *cap)\n+{\n+\tif (!strset_contains(caps, cap))\n+\t\tdie(\"required '%s' capability not available from remote\", cap);\n+}\n+\n+static void read_capabilities(struct strset *remote_caps)\n+{\n+\tfor (;;) {\n+\t\tchar *buf = packet_read_line(0, NULL);\n+\t\tif (!buf)\n+\t\t\tbreak;\n+\t\tstrset_add(remote_caps, get_value(buf, \"capability\"));\n+\t}\n+\n+\tassert_remote_capability(remote_caps, \"clean\");\n+\tassert_remote_capability(remote_caps, \"smudge\");\n+\tassert_remote_capability(remote_caps, \"delay\");\n+}\n+\n+static void check_and_write_capabilities(struct strset *remote_caps,\n+\t\t\t\t\t const char **caps, int nr_caps)\n+{\n+\tint i;\n+\tfor (i = 0; i < nr_caps; i++) {\n+\t\tif (!strset_contains(remote_caps, caps[i]))\n+\t\t\tdie(\"our capability '%s' is not available from remote\",\n+\t\t\t    caps[i]);\n+\t\tpacket_write_fmt(1, \"capability=%s\\n\", caps[i]);\n+\t}\n+\tpacket_flush(1);\n+}\n+\n+struct delay_entry {\n+\tint requested, count;\n+\tchar *output;\n+};\n+\n+static void free_delay_entries(void)\n+{\n+\tstruct hashmap_iter iter;\n+\tstruct strmap_entry *ent;\n+\n+\tstrmap_for_each_entry(&delay, &iter, ent) {\n+\t\tstruct delay_entry *delay_entry = ent->value;\n+\t\tfree(delay_entry->output);\n+\t\tfree(delay_entry);\n+\t}\n+\tstrmap_clear(&delay, 0);\n+}\n+\n+static void add_delay_entry(char *pathname, int count, int requested)\n+{\n+\tstruct delay_entry *entry = xcalloc(1, sizeof(*entry));\n+\tentry->count = count;\n+\tentry->requested = requested;\n+\tif (strmap_put(&delay, pathname, entry))\n+\t\tBUG(\"adding the same path twice to delay hash?\");\n+}\n+\n+static void reply_list_available_blobs_cmd(void)\n+{\n+\tstruct hashmap_iter iter;\n+\tstruct strmap_entry *ent;\n+\tstruct string_list_item *str_item;\n+\tstruct string_list paths = STRING_LIST_INIT_NODUP;\n+\n+\t/* flush */\n+\tif (packet_read_line(0, NULL))\n+\t\tdie(\"bad list_available_blobs end\");\n+\n+\tstrmap_for_each_entry(&delay, &iter, ent) {\n+\t\tstruct delay_entry *delay_entry = ent->value;\n+\t\tif (!delay_entry->requested)\n+\t\t\tcontinue;\n+\t\tdelay_entry->count--;\n+\t\tif (!strcmp(ent->key, \"invalid-delay.a\")) {\n+\t\t\t/* Send Git a pathname that was not delayed earlier */\n+\t\t\tpacket_write_fmt(1, \"pathname=unfiltered\");\n+\t\t}\n+\t\tif (!strcmp(ent->key, \"missing-delay.a\")) {\n+\t\t\t/* Do not signal Git that this file is available */\n+\t\t} else if (!delay_entry->count) {\n+\t\t\tstring_list_append(&paths, ent->key);\n+\t\t\tpacket_write_fmt(1, \"pathname=%s\", ent->key);\n+\t\t}\n+\t}\n+\n+\t/* Print paths in sorted order. */\n+\tstring_list_sort(&paths);\n+\tfor_each_string_list_item(str_item, &paths)\n+\t\tfprintf(logfile, \" %s\", str_item->string);\n+\tstring_list_clear(&paths, 0);\n+\n+\tpacket_flush(1);\n+\n+\tfprintf(logfile, \" [OK]\\n\");\n+\tpacket_write_fmt(1, \"status=success\");\n+\tpacket_flush(1);\n+}\n+\n+static void command_loop(void)\n+{\n+\tfor (;;) {\n+\t\tchar *buf, *output;\n+\t\tchar *pathname;\n+\t\tstruct delay_entry *entry;\n+\t\tstruct strbuf input = STRBUF_INIT;\n+\t\tchar *command = packet_key_val_read(\"command\");\n+\n+\t\tif (!command) {\n+\t\t\tfprintf(logfile, \"STOP\\n\");\n+\t\t\tbreak;\n+\t\t}\n+\t\tfprintf(logfile, \"IN: %s\", command);\n+\n+\t\tif (!strcmp(command, \"list_available_blobs\")) {\n+\t\t\treply_list_available_blobs_cmd();\n+\t\t\tfree(command);\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tpathname = packet_key_val_read(\"pathname\");\n+\t\tif (!pathname)\n+\t\t\tdie(\"unexpected EOF while expecting pathname\");\n+\t\tfprintf(logfile, \" %s\", pathname);\n+\n+\t\t/* Read until flush */\n+\t\twhile ((buf = packet_read_line(0, NULL))) {\n+\t\t\tif (!strcmp(buf, \"can-delay=1\")) {\n+\t\t\t\tentry = strmap_get(&delay, pathname);\n+\t\t\t\tif (entry && !entry->requested)\n+\t\t\t\t\tentry->requested = 1;\n+\t\t\t\telse if (!entry && always_delay)\n+\t\t\t\t\tadd_delay_entry(pathname, 1, 1);\n+\t\t\t} else if (starts_with(buf, \"ref=\") ||\n+\t\t\t\t   starts_with(buf, \"treeish=\") ||\n+\t\t\t\t   starts_with(buf, \"blob=\")) {\n+\t\t\t\tfprintf(logfile, \" %s\", buf);\n+\t\t\t} else {\n+\t\t\t\t/*\n+\t\t\t\t * In general, filters need to be graceful about\n+\t\t\t\t * new metadata, since it's documented that we\n+\t\t\t\t * can pass any key-value pairs, but for tests,\n+\t\t\t\t * let's be a little stricter.\n+\t\t\t\t */\n+\t\t\t\tdie(\"Unknown message '%s'\", buf);\n+\t\t\t}\n+\t\t}\n+\n+\t\tread_packetized_to_strbuf(0, &input, 0);\n+\t\tfprintf(logfile, \" %\"PRIuMAX\" [OK] -- \", (uintmax_t)input.len);\n+\n+\t\tentry = strmap_get(&delay, pathname);\n+\t\tif (entry && entry->output) {\n+\t\t\toutput = entry->output;\n+\t\t} else if (!strcmp(pathname, \"error.r\") || !strcmp(pathname, \"abort.r\")) {\n+\t\t\toutput = \"\";\n+\t\t} else if (!strcmp(command, \"clean\") && has_clean_cap) {\n+\t\t\toutput = rot13(input.buf);\n+\t\t} else if (!strcmp(command, \"smudge\") && has_smudge_cap) {\n+\t\t\toutput = rot13(input.buf);\n+\t\t} else {\n+\t\t\tdie(\"bad command '%s'\", command);\n+\t\t}\n+\n+\t\tif (!strcmp(pathname, \"error.r\")) {\n+\t\t\tfprintf(logfile, \"[ERROR]\\n\");\n+\t\t\tpacket_write_fmt(1, \"status=error\");\n+\t\t\tpacket_flush(1);\n+\t\t} else if (!strcmp(pathname, \"abort.r\")) {\n+\t\t\tfprintf(logfile, \"[ABORT]\\n\");\n+\t\t\tpacket_write_fmt(1, \"status=abort\");\n+\t\t\tpacket_flush(1);\n+\t\t} else if (!strcmp(command, \"smudge\") &&\n+\t\t\t   (entry = strmap_get(&delay, pathname)) &&\n+\t\t\t   entry->requested == 1) {\n+\t\t\tfprintf(logfile, \"[DELAYED]\\n\");\n+\t\t\tpacket_write_fmt(1, \"status=delayed\");\n+\t\t\tpacket_flush(1);\n+\t\t\tentry->requested = 2;\n+\t\t\tif (entry->output != output) {\n+\t\t\t\tfree(entry->output);\n+\t\t\t\tentry->output = xstrdup(output);\n+\t\t\t}\n+\t\t} else {\n+\t\t\tint i, nr_packets = 0;\n+\t\t\tsize_t output_len;\n+\t\t\tconst char *p;\n+\t\t\tpacket_write_fmt(1, \"status=success\");\n+\t\t\tpacket_flush(1);\n+\n+\t\t\tif (skip_prefix(pathname, command, &p) &&\n+\t\t\t    !strcmp(p, \"-write-fail.r\")) {\n+\t\t\t\tfprintf(logfile, \"[WRITE FAIL]\\n\");\n+\t\t\t\tdie(\"%s write error\", command);\n+\t\t\t}\n+\n+\t\t\toutput_len = strlen(output);\n+\t\t\tfprintf(logfile, \"OUT: %\"PRIuMAX\" \", (uintmax_t)output_len);\n+\n+\t\t\tif (write_packetized_from_buf_no_flush_count(output,\n+\t\t\t\toutput_len, 1, &nr_packets))\n+\t\t\t\tdie(\"failed to write buffer to stdout\");\n+\t\t\tpacket_flush(1);\n+\n+\t\t\tfor (i = 0; i < nr_packets; i++)\n+\t\t\t\tfprintf(logfile, \".\");\n+\t\t\tfprintf(logfile, \" [OK]\\n\");\n+\n+\t\t\tpacket_flush(1);\n+\t\t}\n+\t\tfree(pathname);\n+\t\tstrbuf_release(&input);\n+\t\tfree(command);\n+\t}\n+}\n+\n+static void packet_initialize(void)\n+{\n+\tchar *pkt_buf = packet_read_line(0, NULL);\n+\n+\tif (!pkt_buf || strcmp(pkt_buf, \"git-filter-client\"))\n+\t\tdie(\"bad initialize: '%s'\", str_or_null(pkt_buf));\n+\n+\tpkt_buf = packet_read_line(0, NULL);\n+\tif (!pkt_buf || strcmp(pkt_buf, \"version=2\"))\n+\t\tdie(\"bad version: '%s'\", str_or_null(pkt_buf));\n+\n+\tpkt_buf = packet_read_line(0, NULL);\n+\tif (pkt_buf)\n+\t\tdie(\"bad version end: '%s'\", pkt_buf);\n+\n+\tpacket_write_fmt(1, \"git-filter-server\");\n+\tpacket_write_fmt(1, \"version=2\");\n+\tpacket_flush(1);\n+}\n+\n+static const char *rot13_usage[] = {\n+\t\"test-tool rot13-filter [--always-delay] --log=<path> <capabilities>\",\n+\tNULL\n+};\n+\n+int cmd__rot13_filter(int argc, const char **argv)\n+{\n+\tint i, nr_caps;\n+\tstruct strset remote_caps = STRSET_INIT;\n+\tconst char *log_path = NULL;\n+\n+\tstruct option options[] = {\n+\t\tOPT_BOOL(0, \"always-delay\", &always_delay,\n+\t\t\t \"delay all paths with the can-delay flag\"),\n+\t\tOPT_STRING(0, \"log\", &log_path, \"path\",\n+\t\t\t   \"path to the debug log file\"),\n+\t\tOPT_END()\n+\t};\n+\tnr_caps = parse_options(argc, argv, NULL, options, rot13_usage,\n+\t\t\t\tPARSE_OPT_STOP_AT_NON_OPTION);\n+\n+\tif (!log_path || !nr_caps)\n+\t\tusage_with_options(rot13_usage, options);\n+\n+\tlogfile = fopen(log_path, \"a\");\n+\tif (!logfile)\n+\t\tdie_errno(\"failed to open log file\");\n+\n+\tfor (i = 0; i < nr_caps; i++) {\n+\t\tif (!strcmp(argv[i], \"smudge\"))\n+\t\t\thas_smudge_cap = 1;\n+\t\tif (!strcmp(argv[i], \"clean\"))\n+\t\t\thas_clean_cap = 1;\n+\t}\n+\n+\tadd_delay_entry(\"test-delay10.a\", 1, 0);\n+\tadd_delay_entry(\"test-delay11.a\", 1, 0);\n+\tadd_delay_entry(\"test-delay20.a\", 2, 0);\n+\tadd_delay_entry(\"test-delay10.b\", 1, 0);\n+\tadd_delay_entry(\"missing-delay.a\", 1, 0);\n+\tadd_delay_entry(\"invalid-delay.a\", 1, 0);\n+\n+\tfprintf(logfile, \"START\\n\");\n+\tpacket_initialize();\n+\n+\tread_capabilities(&remote_caps);\n+\tcheck_and_write_capabilities(&remote_caps, argv, nr_caps);\n+\tfprintf(logfile, \"init handshake complete\\n\");\n+\tstrset_clear(&remote_caps);\n+\n+\tcommand_loop();\n+\n+\tif (fclose(logfile))\n+\t\tdie_errno(\"error closing logfile\");\n+\tfree_delay_entries();\n+\treturn 0;\n+}\ndiff --git a/t/helper/test-tool.c b/t/helper/test-tool.c\nindex 318fdbab0c..d6a560f832 100644\n--- a/t/helper/test-tool.c\n+++ b/t/helper/test-tool.c\n@@ -65,6 +65,7 @@ static struct test_cmd cmds[] = {\n \t{ \"read-midx\", cmd__read_midx },\n \t{ \"ref-store\", cmd__ref_store },\n \t{ \"reftable\", cmd__reftable },\n+\t{ \"rot13-filter\", cmd__rot13_filter },\n \t{ \"dump-reftable\", cmd__dump_reftable },\n \t{ \"regex\", cmd__regex },\n \t{ \"repository\", cmd__repository },\ndiff --git a/t/helper/test-tool.h b/t/helper/test-tool.h\nindex bb79927163..21a91b1019 100644\n--- a/t/helper/test-tool.h\n+++ b/t/helper/test-tool.h\n@@ -54,6 +54,7 @@ int cmd__read_cache(int argc, const char **argv);\n int cmd__read_graph(int argc, const char **argv);\n int cmd__read_midx(int argc, const char **argv);\n int cmd__ref_store(int argc, const char **argv);\n+int cmd__rot13_filter(int argc, const char **argv);\n int cmd__reftable(int argc, const char **argv);\n int cmd__regex(int argc, const char **argv);\n int cmd__repository(int argc, const char **argv);\n-- \n2.37.1\n\n"},{"id":"461211","messageId":"d6033abbce7b71c3c134ebfbaacef0867642c5b8.1660522524.git.matheus.bernardino@usp.br","threadId":"58306","inReplyTo":"cover.1660522524.git.matheus.bernardino@usp.br","subject":"[PATCH v4 3/3] tests: use the new C rot13-filter helper to avoid PERL prereq","fromName":"Matheus Tavares","fromEmail":"matheus.bernardino@usp.br","sentAt":"2022-08-15T01:06:38Z","receivedAt":"2022-08-15T01:07:11Z","isPatch":true,"sender":{"key":"matheus.tavb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/12701583?v=4"},"body":"The previous commit implemented a C version of the t0021/rot13-filter.pl\nscript. Let's use this new C helper to eliminate the PERL prereq from\nvarious tests, and also remove the superseded Perl script.\n\nSigned-off-by: Matheus Tavares <matheus.bernardino@usp.br>\n---\n t/t0021-conversion.sh                   |  69 ++++---\n t/t0021/rot13-filter.pl                 | 247 ------------------------\n t/t2080-parallel-checkout-basics.sh     |   7 +-\n t/t2082-parallel-checkout-attributes.sh |   7 +-\n 4 files changed, 37 insertions(+), 293 deletions(-)\n delete mode 100644 t/t0021/rot13-filter.pl\n\ndiff --git a/t/t0021-conversion.sh b/t/t0021-conversion.sh\nindex 963b66e08c..abecd75e4e 100755\n--- a/t/t0021-conversion.sh\n+++ b/t/t0021-conversion.sh\n@@ -17,9 +17,6 @@ tr \\\n   'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM'\n EOF\n \n-write_script rot13-filter.pl \"$PERL_PATH\" \\\n-\t<\"$TEST_DIRECTORY\"/t0021/rot13-filter.pl\n-\n generate_random_characters () {\n \tLEN=$1\n \tNAME=$2\n@@ -365,8 +362,8 @@ test_expect_success 'diff does not reuse worktree files that need cleaning' '\n \ttest_line_count = 0 count\n '\n \n-test_expect_success PERL 'required process filter should filter data' '\n-\ttest_config_global filter.protocol.process \"rot13-filter.pl debug.log clean smudge\" &&\n+test_expect_success 'required process filter should filter data' '\n+\ttest_config_global filter.protocol.process \"test-tool rot13-filter --log=debug.log clean smudge\" &&\n \ttest_config_global filter.protocol.required true &&\n \trm -rf repo &&\n \tmkdir repo &&\n@@ -450,8 +447,8 @@ test_expect_success PERL 'required process filter should filter data' '\n \t)\n '\n \n-test_expect_success PERL 'required process filter should filter data for various subcommands' '\n-\ttest_config_global filter.protocol.process \"rot13-filter.pl debug.log clean smudge\" &&\n+test_expect_success 'required process filter should filter data for various subcommands' '\n+\ttest_config_global filter.protocol.process \"test-tool rot13-filter --log=debug.log clean smudge\" &&\n \ttest_config_global filter.protocol.required true &&\n \t(\n \t\tcd repo &&\n@@ -561,9 +558,9 @@ test_expect_success PERL 'required process filter should filter data for various\n \t)\n '\n \n-test_expect_success PERL 'required process filter takes precedence' '\n+test_expect_success 'required process filter takes precedence' '\n \ttest_config_global filter.protocol.clean false &&\n-\ttest_config_global filter.protocol.process \"rot13-filter.pl debug.log clean\" &&\n+\ttest_config_global filter.protocol.process \"test-tool rot13-filter --log=debug.log clean\" &&\n \ttest_config_global filter.protocol.required true &&\n \trm -rf repo &&\n \tmkdir repo &&\n@@ -587,8 +584,8 @@ test_expect_success PERL 'required process filter takes precedence' '\n \t)\n '\n \n-test_expect_success PERL 'required process filter should be used only for \"clean\" operation only' '\n-\ttest_config_global filter.protocol.process \"rot13-filter.pl debug.log clean\" &&\n+test_expect_success 'required process filter should be used only for \"clean\" operation only' '\n+\ttest_config_global filter.protocol.process \"test-tool rot13-filter --log=debug.log clean\" &&\n \trm -rf repo &&\n \tmkdir repo &&\n \t(\n@@ -622,8 +619,8 @@ test_expect_success PERL 'required process filter should be used only for \"clean\n \t)\n '\n \n-test_expect_success PERL 'required process filter should process multiple packets' '\n-\ttest_config_global filter.protocol.process \"rot13-filter.pl debug.log clean smudge\" &&\n+test_expect_success 'required process filter should process multiple packets' '\n+\ttest_config_global filter.protocol.process \"test-tool rot13-filter --log=debug.log clean smudge\" &&\n \ttest_config_global filter.protocol.required true &&\n \n \trm -rf repo &&\n@@ -687,8 +684,8 @@ test_expect_success PERL 'required process filter should process multiple packet\n \t)\n '\n \n-test_expect_success PERL 'required process filter with clean error should fail' '\n-\ttest_config_global filter.protocol.process \"rot13-filter.pl debug.log clean smudge\" &&\n+test_expect_success 'required process filter with clean error should fail' '\n+\ttest_config_global filter.protocol.process \"test-tool rot13-filter --log=debug.log clean smudge\" &&\n \ttest_config_global filter.protocol.required true &&\n \trm -rf repo &&\n \tmkdir repo &&\n@@ -706,8 +703,8 @@ test_expect_success PERL 'required process filter with clean error should fail'\n \t)\n '\n \n-test_expect_success PERL 'process filter should restart after unexpected write failure' '\n-\ttest_config_global filter.protocol.process \"rot13-filter.pl debug.log clean smudge\" &&\n+test_expect_success 'process filter should restart after unexpected write failure' '\n+\ttest_config_global filter.protocol.process \"test-tool rot13-filter --log=debug.log clean smudge\" &&\n \trm -rf repo &&\n \tmkdir repo &&\n \t(\n@@ -761,8 +758,8 @@ test_expect_success PERL 'process filter should restart after unexpected write f\n \t)\n '\n \n-test_expect_success PERL 'process filter should not be restarted if it signals an error' '\n-\ttest_config_global filter.protocol.process \"rot13-filter.pl debug.log clean smudge\" &&\n+test_expect_success 'process filter should not be restarted if it signals an error' '\n+\ttest_config_global filter.protocol.process \"test-tool rot13-filter --log=debug.log clean smudge\" &&\n \trm -rf repo &&\n \tmkdir repo &&\n \t(\n@@ -804,8 +801,8 @@ test_expect_success PERL 'process filter should not be restarted if it signals a\n \t)\n '\n \n-test_expect_success PERL 'process filter abort stops processing of all further files' '\n-\ttest_config_global filter.protocol.process \"rot13-filter.pl debug.log clean smudge\" &&\n+test_expect_success 'process filter abort stops processing of all further files' '\n+\ttest_config_global filter.protocol.process \"test-tool rot13-filter --log=debug.log clean smudge\" &&\n \trm -rf repo &&\n \tmkdir repo &&\n \t(\n@@ -861,10 +858,10 @@ test_expect_success PERL 'invalid process filter must fail (and not hang!)' '\n \t)\n '\n \n-test_expect_success PERL 'delayed checkout in process filter' '\n-\ttest_config_global filter.a.process \"rot13-filter.pl a.log clean smudge delay\" &&\n+test_expect_success 'delayed checkout in process filter' '\n+\ttest_config_global filter.a.process \"test-tool rot13-filter --log=a.log clean smudge delay\" &&\n \ttest_config_global filter.a.required true &&\n-\ttest_config_global filter.b.process \"rot13-filter.pl b.log clean smudge delay\" &&\n+\ttest_config_global filter.b.process \"test-tool rot13-filter --log=b.log clean smudge delay\" &&\n \ttest_config_global filter.b.required true &&\n \n \trm -rf repo &&\n@@ -940,8 +937,8 @@ test_expect_success PERL 'delayed checkout in process filter' '\n \t)\n '\n \n-test_expect_success PERL 'missing file in delayed checkout' '\n-\ttest_config_global filter.bug.process \"rot13-filter.pl bug.log clean smudge delay\" &&\n+test_expect_success 'missing file in delayed checkout' '\n+\ttest_config_global filter.bug.process \"test-tool rot13-filter --log=bug.log clean smudge delay\" &&\n \ttest_config_global filter.bug.required true &&\n \n \trm -rf repo &&\n@@ -960,8 +957,8 @@ test_expect_success PERL 'missing file in delayed checkout' '\n \tgrep \"error: .missing-delay\\.a. was not filtered properly\" git-stderr.log\n '\n \n-test_expect_success PERL 'invalid file in delayed checkout' '\n-\ttest_config_global filter.bug.process \"rot13-filter.pl bug.log clean smudge delay\" &&\n+test_expect_success 'invalid file in delayed checkout' '\n+\ttest_config_global filter.bug.process \"test-tool rot13-filter --log=bug.log clean smudge delay\" &&\n \ttest_config_global filter.bug.required true &&\n \n \trm -rf repo &&\n@@ -990,10 +987,10 @@ do\n \t\tmode_prereq='UTF8_NFD_TO_NFC' ;;\n \tesac\n \n-\ttest_expect_success PERL,SYMLINKS,$mode_prereq \\\n+\ttest_expect_success SYMLINKS,$mode_prereq \\\n \t\"delayed checkout with $mode-collision don't write to the wrong place\" '\n \t\ttest_config_global filter.delay.process \\\n-\t\t\t\"\\\"$TEST_ROOT/rot13-filter.pl\\\" --always-delay delayed.log clean smudge delay\" &&\n+\t\t\t\"test-tool rot13-filter --always-delay --log=delayed.log clean smudge delay\" &&\n \t\ttest_config_global filter.delay.required true &&\n \n \t\tgit init $mode-collision &&\n@@ -1026,12 +1023,12 @@ do\n \t'\n done\n \n-test_expect_success PERL,SYMLINKS,CASE_INSENSITIVE_FS \\\n+test_expect_success SYMLINKS,CASE_INSENSITIVE_FS \\\n \"delayed checkout with submodule collision don't write to the wrong place\" '\n \tgit init collision-with-submodule &&\n \t(\n \t\tcd collision-with-submodule &&\n-\t\tgit config filter.delay.process \"\\\"$TEST_ROOT/rot13-filter.pl\\\" --always-delay delayed.log clean smudge delay\" &&\n+\t\tgit config filter.delay.process \"test-tool rot13-filter --always-delay --log=delayed.log clean smudge delay\" &&\n \t\tgit config filter.delay.required true &&\n \n \t\t# We need Git to treat the submodule \"a\" and the\n@@ -1062,11 +1059,11 @@ test_expect_success PERL,SYMLINKS,CASE_INSENSITIVE_FS \\\n \t)\n '\n \n-test_expect_success PERL 'setup for progress tests' '\n+test_expect_success 'setup for progress tests' '\n \tgit init progress &&\n \t(\n \t\tcd progress &&\n-\t\tgit config filter.delay.process \"rot13-filter.pl delay-progress.log clean smudge delay\" &&\n+\t\tgit config filter.delay.process \"test-tool rot13-filter --log=delay-progress.log clean smudge delay\" &&\n \t\tgit config filter.delay.required true &&\n \n \t\techo \"*.a filter=delay\" >.gitattributes &&\n@@ -1132,12 +1129,12 @@ do\n \t'\n done\n \n-test_expect_success PERL 'delayed checkout correctly reports the number of updated entries' '\n+test_expect_success 'delayed checkout correctly reports the number of updated entries' '\n \trm -rf repo &&\n \tgit init repo &&\n \t(\n \t\tcd repo &&\n-\t\tgit config filter.delay.process \"../rot13-filter.pl delayed.log clean smudge delay\" &&\n+\t\tgit config filter.delay.process \"test-tool rot13-filter --log=delayed.log clean smudge delay\" &&\n \t\tgit config filter.delay.required true &&\n \n \t\techo \"*.a filter=delay\" >.gitattributes &&\ndiff --git a/t/t0021/rot13-filter.pl b/t/t0021/rot13-filter.pl\ndeleted file mode 100644\nindex 7bb93768f3..0000000000\n--- a/t/t0021/rot13-filter.pl\n+++ /dev/null\n@@ -1,247 +0,0 @@\n-#\n-# Example implementation for the Git filter protocol version 2\n-# See Documentation/gitattributes.txt, section \"Filter Protocol\"\n-#\n-# Usage: rot13-filter.pl [--always-delay] <log path> <capabilities>\n-#\n-# Log path defines a debug log file that the script writes to. The\n-# subsequent arguments define a list of supported protocol capabilities\n-# (\"clean\", \"smudge\", etc).\n-#\n-# When --always-delay is given all pathnames with the \"can-delay\" flag\n-# that don't appear on the list bellow are delayed with a count of 1\n-# (see more below).\n-#\n-# This implementation supports special test cases:\n-# (1) If data with the pathname \"clean-write-fail.r\" is processed with\n-#     a \"clean\" operation then the write operation will die.\n-# (2) If data with the pathname \"smudge-write-fail.r\" is processed with\n-#     a \"smudge\" operation then the write operation will die.\n-# (3) If data with the pathname \"error.r\" is processed with any\n-#     operation then the filter signals that it cannot or does not want\n-#     to process the file.\n-# (4) If data with the pathname \"abort.r\" is processed with any\n-#     operation then the filter signals that it cannot or does not want\n-#     to process the file and any file after that is processed with the\n-#     same command.\n-# (5) If data with a pathname that is a key in the DELAY hash is\n-#     requested (e.g. \"test-delay10.a\") then the filter responds with\n-#     a \"delay\" status and sets the \"requested\" field in the DELAY hash.\n-#     The filter will signal the availability of this object after\n-#     \"count\" (field in DELAY hash) \"list_available_blobs\" commands.\n-# (6) If data with the pathname \"missing-delay.a\" is processed that the\n-#     filter will drop the path from the \"list_available_blobs\" response.\n-# (7) If data with the pathname \"invalid-delay.a\" is processed that the\n-#     filter will add the path \"unfiltered\" which was not delayed before\n-#     to the \"list_available_blobs\" response.\n-#\n-\n-use 5.008;\n-sub gitperllib {\n-\t# Git assumes that all path lists are Unix-y colon-separated ones. But\n-\t# when the Git for Windows executes the test suite, its MSYS2 Bash\n-\t# calls git.exe, and colon-separated path lists are converted into\n-\t# Windows-y semicolon-separated lists of *Windows* paths (which\n-\t# naturally contain a colon after the drive letter, so splitting by\n-\t# colons simply does not cut it).\n-\t#\n-\t# Detect semicolon-separated path list and handle them appropriately.\n-\n-\tif ($ENV{GITPERLLIB} =~ /;/) {\n-\t\treturn split(/;/, $ENV{GITPERLLIB});\n-\t}\n-\treturn split(/:/, $ENV{GITPERLLIB});\n-}\n-use lib (gitperllib());\n-use strict;\n-use warnings;\n-use IO::File;\n-use Git::Packet;\n-\n-my $MAX_PACKET_CONTENT_SIZE = 65516;\n-\n-my $always_delay = 0;\n-if ( $ARGV[0] eq '--always-delay' ) {\n-\t$always_delay = 1;\n-\tshift @ARGV;\n-}\n-\n-my $log_file                = shift @ARGV;\n-my @capabilities            = @ARGV;\n-\n-open my $debug, \">>\", $log_file or die \"cannot open log file: $!\";\n-\n-my %DELAY = (\n-\t'test-delay10.a' => { \"requested\" => 0, \"count\" => 1 },\n-\t'test-delay11.a' => { \"requested\" => 0, \"count\" => 1 },\n-\t'test-delay20.a' => { \"requested\" => 0, \"count\" => 2 },\n-\t'test-delay10.b' => { \"requested\" => 0, \"count\" => 1 },\n-\t'missing-delay.a' => { \"requested\" => 0, \"count\" => 1 },\n-\t'invalid-delay.a' => { \"requested\" => 0, \"count\" => 1 },\n-);\n-\n-sub rot13 {\n-\tmy $str = shift;\n-\t$str =~ y/A-Za-z/N-ZA-Mn-za-m/;\n-\treturn $str;\n-}\n-\n-print $debug \"START\\n\";\n-$debug->flush();\n-\n-packet_initialize(\"git-filter\", 2);\n-\n-my %remote_caps = packet_read_and_check_capabilities(\"clean\", \"smudge\", \"delay\");\n-packet_check_and_write_capabilities(\\%remote_caps, @capabilities);\n-\n-print $debug \"init handshake complete\\n\";\n-$debug->flush();\n-\n-while (1) {\n-\tmy ( $res, $command ) = packet_key_val_read(\"command\");\n-\tif ( $res == -1 ) {\n-\t\tprint $debug \"STOP\\n\";\n-\t\texit();\n-\t}\n-\tprint $debug \"IN: $command\";\n-\t$debug->flush();\n-\n-\tif ( $command eq \"list_available_blobs\" ) {\n-\t\t# Flush\n-\t\tpacket_compare_lists([1, \"\"], packet_bin_read()) ||\n-\t\t\tdie \"bad list_available_blobs end\";\n-\n-\t\tforeach my $pathname ( sort keys %DELAY ) {\n-\t\t\tif ( $DELAY{$pathname}{\"requested\"} >= 1 ) {\n-\t\t\t\t$DELAY{$pathname}{\"count\"} = $DELAY{$pathname}{\"count\"} - 1;\n-\t\t\t\tif ( $pathname eq \"invalid-delay.a\" ) {\n-\t\t\t\t\t# Send Git a pathname that was not delayed earlier\n-\t\t\t\t\tpacket_txt_write(\"pathname=unfiltered\");\n-\t\t\t\t}\n-\t\t\t\tif ( $pathname eq \"missing-delay.a\" ) {\n-\t\t\t\t\t# Do not signal Git that this file is available\n-\t\t\t\t} elsif ( $DELAY{$pathname}{\"count\"} == 0 ) {\n-\t\t\t\t\tprint $debug \" $pathname\";\n-\t\t\t\t\tpacket_txt_write(\"pathname=$pathname\");\n-\t\t\t\t}\n-\t\t\t}\n-\t\t}\n-\n-\t\tpacket_flush();\n-\n-\t\tprint $debug \" [OK]\\n\";\n-\t\t$debug->flush();\n-\t\tpacket_txt_write(\"status=success\");\n-\t\tpacket_flush();\n-\t} else {\n-\t\tmy ( $res, $pathname ) = packet_key_val_read(\"pathname\");\n-\t\tif ( $res == -1 ) {\n-\t\t\tdie \"unexpected EOF while expecting pathname\";\n-\t\t}\n-\t\tprint $debug \" $pathname\";\n-\t\t$debug->flush();\n-\n-\t\t# Read until flush\n-\t\tmy ( $done, $buffer ) = packet_txt_read();\n-\t\twhile ( $buffer ne '' ) {\n-\t\t\tif ( $buffer eq \"can-delay=1\" ) {\n-\t\t\t\tif ( exists $DELAY{$pathname} and $DELAY{$pathname}{\"requested\"} == 0 ) {\n-\t\t\t\t\t$DELAY{$pathname}{\"requested\"} = 1;\n-\t\t\t\t} elsif ( !exists $DELAY{$pathname} and $always_delay ) {\n-\t\t\t\t\t$DELAY{$pathname} = { \"requested\" => 1, \"count\" => 1 };\n-\t\t\t\t}\n-\t\t\t} elsif ($buffer =~ /^(ref|treeish|blob)=/) {\n-\t\t\t\tprint $debug \" $buffer\";\n-\t\t\t} else {\n-\t\t\t\t# In general, filters need to be graceful about\n-\t\t\t\t# new metadata, since it's documented that we\n-\t\t\t\t# can pass any key-value pairs, but for tests,\n-\t\t\t\t# let's be a little stricter.\n-\t\t\t\tdie \"Unknown message '$buffer'\";\n-\t\t\t}\n-\n-\t\t\t( $done, $buffer ) = packet_txt_read();\n-\t\t}\n-\t\tif ( $done == -1 ) {\n-\t\t\tdie \"unexpected EOF after pathname '$pathname'\";\n-\t\t}\n-\n-\t\tmy $input = \"\";\n-\t\t{\n-\t\t\tbinmode(STDIN);\n-\t\t\tmy $buffer;\n-\t\t\tmy $done = 0;\n-\t\t\twhile ( !$done ) {\n-\t\t\t\t( $done, $buffer ) = packet_bin_read();\n-\t\t\t\t$input .= $buffer;\n-\t\t\t}\n-\t\t\tif ( $done == -1 ) {\n-\t\t\t\tdie \"unexpected EOF while reading input for '$pathname'\";\n-\t\t\t}\t\t\t\n-\t\t\tprint $debug \" \" . length($input) . \" [OK] -- \";\n-\t\t\t$debug->flush();\n-\t\t}\n-\n-\t\tmy $output;\n-\t\tif ( exists $DELAY{$pathname} and exists $DELAY{$pathname}{\"output\"} ) {\n-\t\t\t$output = $DELAY{$pathname}{\"output\"}\n-\t\t} elsif ( $pathname eq \"error.r\" or $pathname eq \"abort.r\" ) {\n-\t\t\t$output = \"\";\n-\t\t} elsif ( $command eq \"clean\" and grep( /^clean$/, @capabilities ) ) {\n-\t\t\t$output = rot13($input);\n-\t\t} elsif ( $command eq \"smudge\" and grep( /^smudge$/, @capabilities ) ) {\n-\t\t\t$output = rot13($input);\n-\t\t} else {\n-\t\t\tdie \"bad command '$command'\";\n-\t\t}\n-\n-\t\tif ( $pathname eq \"error.r\" ) {\n-\t\t\tprint $debug \"[ERROR]\\n\";\n-\t\t\t$debug->flush();\n-\t\t\tpacket_txt_write(\"status=error\");\n-\t\t\tpacket_flush();\n-\t\t} elsif ( $pathname eq \"abort.r\" ) {\n-\t\t\tprint $debug \"[ABORT]\\n\";\n-\t\t\t$debug->flush();\n-\t\t\tpacket_txt_write(\"status=abort\");\n-\t\t\tpacket_flush();\n-\t\t} elsif ( $command eq \"smudge\" and\n-\t\t\texists $DELAY{$pathname} and\n-\t\t\t$DELAY{$pathname}{\"requested\"} == 1 ) {\n-\t\t\tprint $debug \"[DELAYED]\\n\";\n-\t\t\t$debug->flush();\n-\t\t\tpacket_txt_write(\"status=delayed\");\n-\t\t\tpacket_flush();\n-\t\t\t$DELAY{$pathname}{\"requested\"} = 2;\n-\t\t\t$DELAY{$pathname}{\"output\"} = $output;\n-\t\t} else {\n-\t\t\tpacket_txt_write(\"status=success\");\n-\t\t\tpacket_flush();\n-\n-\t\t\tif ( $pathname eq \"${command}-write-fail.r\" ) {\n-\t\t\t\tprint $debug \"[WRITE FAIL]\\n\";\n-\t\t\t\t$debug->flush();\n-\t\t\t\tdie \"${command} write error\";\n-\t\t\t}\n-\n-\t\t\tprint $debug \"OUT: \" . length($output) . \" \";\n-\t\t\t$debug->flush();\n-\n-\t\t\twhile ( length($output) > 0 ) {\n-\t\t\t\tmy $packet = substr( $output, 0, $MAX_PACKET_CONTENT_SIZE );\n-\t\t\t\tpacket_bin_write($packet);\n-\t\t\t\t# dots represent the number of packets\n-\t\t\t\tprint $debug \".\";\n-\t\t\t\tif ( length($output) > $MAX_PACKET_CONTENT_SIZE ) {\n-\t\t\t\t\t$output = substr( $output, $MAX_PACKET_CONTENT_SIZE );\n-\t\t\t\t} else {\n-\t\t\t\t\t$output = \"\";\n-\t\t\t\t}\n-\t\t\t}\n-\t\t\tpacket_flush();\n-\t\t\tprint $debug \" [OK]\\n\";\n-\t\t\t$debug->flush();\n-\t\t\tpacket_flush();\n-\t\t}\n-\t}\n-}\ndiff --git a/t/t2080-parallel-checkout-basics.sh b/t/t2080-parallel-checkout-basics.sh\nindex c683e60007..00ce3033d3 100755\n--- a/t/t2080-parallel-checkout-basics.sh\n+++ b/t/t2080-parallel-checkout-basics.sh\n@@ -230,12 +230,9 @@ test_expect_success SYMLINKS 'parallel checkout checks for symlinks in leading d\n # check the final report including sequential, parallel, and delayed entries\n # all at the same time. So we must have finer control of the parallel checkout\n # variables.\n-test_expect_success PERL '\"git checkout .\" report should not include failed entries' '\n-\twrite_script rot13-filter.pl \"$PERL_PATH\" \\\n-\t\t<\"$TEST_DIRECTORY\"/t0021/rot13-filter.pl &&\n-\n+test_expect_success '\"git checkout .\" report should not include failed entries' '\n \ttest_config_global filter.delay.process \\\n-\t\t\"\\\"$(pwd)/rot13-filter.pl\\\" --always-delay delayed.log clean smudge delay\" &&\n+\t\t\"test-tool rot13-filter --always-delay --log=delayed.log clean smudge delay\" &&\n \ttest_config_global filter.delay.required true &&\n \ttest_config_global filter.cat.clean cat  &&\n \ttest_config_global filter.cat.smudge cat  &&\ndiff --git a/t/t2082-parallel-checkout-attributes.sh b/t/t2082-parallel-checkout-attributes.sh\nindex 2525457961..f3511cd43a 100755\n--- a/t/t2082-parallel-checkout-attributes.sh\n+++ b/t/t2082-parallel-checkout-attributes.sh\n@@ -138,12 +138,9 @@ test_expect_success 'parallel-checkout and external filter' '\n # The delayed queue is independent from the parallel queue, and they should be\n # able to work together in the same checkout process.\n #\n-test_expect_success PERL 'parallel-checkout and delayed checkout' '\n-\twrite_script rot13-filter.pl \"$PERL_PATH\" \\\n-\t\t<\"$TEST_DIRECTORY\"/t0021/rot13-filter.pl &&\n-\n+test_expect_success 'parallel-checkout and delayed checkout' '\n \ttest_config_global filter.delay.process \\\n-\t\t\"\\\"$(pwd)/rot13-filter.pl\\\" --always-delay \\\"$(pwd)/delayed.log\\\" clean smudge delay\" &&\n+\t\t\"test-tool rot13-filter --always-delay --log=\\\"$(pwd)/delayed.log\\\" clean smudge delay\" &&\n \ttest_config_global filter.delay.required true &&\n \n \techo \"abcd\" >original &&\n-- \n2.37.1\n\n"},{"id":"461222","messageId":"oop2rosn-011s-9rpn-04s5-ss12n45q615p@tzk.qr","threadId":"58306","inReplyTo":"cover.1660522524.git.matheus.bernardino@usp.br","subject":"Re: [PATCH v4 0/3] t0021: convert perl script to C test-tool helper","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2022-08-15T13:01:54Z","receivedAt":"2022-08-15T13:02:01Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Matheus,\n\nOn Sun, 14 Aug 2022, Matheus Tavares wrote:\n\n> Main changes since v3:\n> Patch 2:\n> - Mentioned in commit message why we removed the flush() calls for the\n>   log file handler.\n> - Removed 'buf[size] = \\0' and relied on the fact that packet_read()\n>   already 0-terminates the buffer. This also allows us to use NULL\n>   instead of &size in many places, dropping down the unneeded variable.\n> - Used parse-options instead of manual argv fiddling. I'm not strongly\n>   about one way or another, but I found the parse-options slightly\n>   easier for new options that may be added in the future.\n> - Style: removed unnecessary {} and newline.\n\nWhile I think that the `parse-options` were unnecessary churn, I won't\nobject because I find that I cannot motivate myself to care all that much\n(other reviewers seem to find this type of aspects super exciting, a\nsentiment I do not share). I care much more about the essence, about the\nactual improvement brought about by your patch series, which is to reduce\nGit's test suite's reliance on scripting.\n\nThe range-diff looks good to me, and I think this iteration is good to go.\n\nThanks,\nDscho\n"},{"id":"461633","messageId":"xmqq8rnjkhec.fsf@gitster.g","threadId":"58306","inReplyTo":"oop2rosn-011s-9rpn-04s5-ss12n45q615p@tzk.qr","subject":"Re: [PATCH v4 0/3] t0021: convert perl script to C test-tool helper","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-08-19T22:17:15Z","receivedAt":"2022-08-19T22:18:02Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> On Sun, 14 Aug 2022, Matheus Tavares wrote:\n>\n>> Main changes since v3:\n>> Patch 2:\n>> - Mentioned in commit message why we removed the flush() calls for the\n>>   log file handler.\n>> - Removed 'buf[size] = \\0' and relied on the fact that packet_read()\n>>   already 0-terminates the buffer. This also allows us to use NULL\n> ...\n> The range-diff looks good to me, and I think this iteration is good to go.\n\nThanks, both.  Let's merge it down.\n\n"}]}