git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH v2 4/5] tests: replace remaining packetize() with "test-tool pkt-line"
Date: Tue, 13 Jul 2021 16:58:28 -0400	[thread overview]
Message-ID: <YO3+dBHL5ZBe/NbU@coredump.intra.peff.net> (raw)
In-Reply-To: <patch-4.5-a44e1790f2a-20210712T164208Z-avarab@gmail.com>

On Mon, Jul 12, 2021 at 06:44:19PM +0200, Ævar Arnfjörð Bjarmason wrote:

> Move the only remaining users of "packetize()" over to "test-tool
> pkt-line", for this we need a new "pack-raw-stdin" subcommand in the
> test-tool. The "pack" command takes input on stdin, but splits it by
> "\n", furthermore we'll format the output using C-strings, so the
> embedded "\0" being tested for here would cause the string to be
> truncated.
> 
> So we need another mode that just calls packet_write() on the raw
> input we got on stdin.

Makes sense. Lacking this "raw" version was the sticking point in the
past for using the helper in more places.

> +static void pack_raw_stdin(void)
> +{
> +	struct strbuf sb = STRBUF_INIT;
> +	strbuf_read(&sb, 0, 0);
> +	if (strbuf_read(&sb, 0, 0) < 0)
> +		die_errno("failed to read from stdin");

What's up with the two reads here?

It looks like just a duplication. And it happens to work because each
one tries to read to eof, making the second one generally a noop.

> diff --git a/t/t5570-git-daemon.sh b/t/t5570-git-daemon.sh
> index 2dde0348816..b52afb0cdea 100755
> --- a/t/t5570-git-daemon.sh
> +++ b/t/t5570-git-daemon.sh
> @@ -193,10 +193,12 @@ test_expect_success 'hostname cannot break out of directory' '
>  '
>  
>  test_expect_success FAKENC 'hostname interpolation works after LF-stripping' '
> -	{
> -		printf "git-upload-pack /interp.git\n\0host=localhost" | packetize
> -		printf "0000"
> -	} >input &&
> +	printf "git-upload-pack /interp.git\n\0host=localhost" >has-null &&
> +	test-tool pkt-line pack-raw-stdin >input <has-null &&
> +	test-tool pkt-line pack >>input <<-\EOF &&
> +	0000
> +	EOF

This is a minor style nit, but I really prefer redirecting output from
a block (as in the original) rather than iterative appending (in the
result). IMHO it makes it more obvious what is going into the file and
what is not.

I.e.:

  {
          printf "git-upload-pack /interp.git\n\0host=localhost" |
	  test-tool pkt-line pack-raw-stdin &&
	  printf "0000" | test-tool pkt-line pack
  } >input

(again here the packing of "0000" is pointless, but I'm OK with it for
consistency).

-Peff

  reply	other threads:[~2021-07-13 20:58 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-07 10:21 [PATCH 0/5] tests: migrate to "test-tool pkt-line" Ævar Arnfjörð Bjarmason
2021-07-07 10:21 ` [PATCH 1/5] serve tests: add missing "extra delim" test Ævar Arnfjörð Bjarmason
2021-07-07 10:21 ` [PATCH 2/5] serve tests: use test_cmp in "protocol violations" test Ævar Arnfjörð Bjarmason
2021-07-07 10:21 ` [PATCH 3/5] tests: replace [de]packetize() shell+perl test-tool pkt-line Ævar Arnfjörð Bjarmason
2021-07-07 10:21 ` [PATCH 4/5] tests: replace remaining packetize() with "test-tool pkt-line" Ævar Arnfjörð Bjarmason
2021-07-07 10:21 ` [PATCH 5/5] test-lib-functions.sh: remove unused [de]packetize() functions Ævar Arnfjörð Bjarmason
2021-07-12 16:44 ` [PATCH v2 0/5] tests: migrate to "test-tool pkt-line" Ævar Arnfjörð Bjarmason
2021-07-12 16:44   ` [PATCH v2 1/5] serve tests: add missing "extra delim" test Ævar Arnfjörð Bjarmason
2021-07-12 16:44   ` [PATCH v2 2/5] serve tests: use test_cmp in "protocol violations" test Ævar Arnfjörð Bjarmason
2021-07-12 16:44   ` [PATCH v2 3/5] tests: replace [de]packetize() shell+perl test-tool pkt-line Ævar Arnfjörð Bjarmason
2021-07-13 20:50     ` Jeff King
2021-07-13 23:41       ` Ævar Arnfjörð Bjarmason
2021-07-14  1:12         ` Jeff King
2021-07-12 16:44   ` [PATCH v2 4/5] tests: replace remaining packetize() with "test-tool pkt-line" Ævar Arnfjörð Bjarmason
2021-07-13 20:58     ` Jeff King [this message]
2021-07-13 23:52       ` Ævar Arnfjörð Bjarmason
2021-07-14  1:16         ` Jeff King
2021-07-12 16:44   ` [PATCH v2 5/5] test-lib-functions.sh: remove unused [de]packetize() functions Ævar Arnfjörð Bjarmason
2021-07-12 20:41   ` [PATCH v2 0/5] tests: migrate to "test-tool pkt-line" Junio C Hamano
2021-07-13 21:00     ` Jeff King
2021-07-14  0:54   ` [PATCH v3 " Ævar Arnfjörð Bjarmason
2021-07-14  0:54     ` [PATCH v3 1/5] serve tests: add missing "extra delim" test Ævar Arnfjörð Bjarmason
2021-07-14  0:54     ` [PATCH v3 2/5] serve tests: use test_cmp in "protocol violations" test Ævar Arnfjörð Bjarmason
2021-07-14  0:54     ` [PATCH v3 3/5] tests: replace [de]packetize() shell+perl test-tool pkt-line Ævar Arnfjörð Bjarmason
2021-07-14  4:04       ` Taylor Blau
2021-07-14 16:22         ` Junio C Hamano
2021-07-14  0:54     ` [PATCH v3 4/5] tests: replace remaining packetize() with "test-tool pkt-line" Ævar Arnfjörð Bjarmason
2021-07-14  0:54     ` [PATCH v3 5/5] test-lib-functions.sh: remove unused [de]packetize() functions Ævar Arnfjörð Bjarmason
2021-07-16 15:41     ` [PATCH v4] test-lib-functions: use test-tool for [de]packetize() Ævar Arnfjörð Bjarmason
2021-07-16 16:53       ` Taylor Blau
2021-07-16 19:08         ` Jeff King
2021-07-16 19:03       ` Jeff King
2021-07-19 18:54       ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YO3+dBHL5ZBe/NbU@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).