git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: Jonathan Tan <jonathantanmy@google.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 1/2] t5616: refactor packfile replacement
Date: Wed, 15 May 2019 10:36:52 +0200 (DST)	[thread overview]
Message-ID: <nycvar.QRO.7.76.6.1905151032500.44@tvgsbejvaqbjf.bet> (raw)
In-Reply-To: <991a3aa27dd7fe67adbed2e03502790932b5059c.1557868134.git.jonathantanmy@google.com>

Hi Jonathan,

On Tue, 14 May 2019, Jonathan Tan wrote:

> diff --git a/t/t5616-partial-clone.sh b/t/t5616-partial-clone.sh
> index 9a8f9886b3..7cc0c71556 100755
> --- a/t/t5616-partial-clone.sh
> +++ b/t/t5616-partial-clone.sh
> @@ -244,11 +244,25 @@ test_expect_success 'fetch what is specified on CLI even if already promised' '
>  . "$TEST_DIRECTORY"/lib-httpd.sh
>  start_httpd
>
> -# Converts bytes into a form suitable for inclusion in a sed command. For
> -# example, "printf 'ab\r\n' | hex_unpack" results in '\x61\x62\x0d\x0a'.
> -sed_escape () {
> -	perl -e '$/ = undef; $input = <>; print unpack("H2" x length($input), $input)' |
> -		sed 's/\(..\)/\\x\1/g'
> +# Converts bytes into their hexadecimal representation. For example,
> +# "printf 'ab\r\n' | hex_unpack" results in '61620d0a'.
> +hex_unpack () {
> +	perl -e '$/ = undef; $input = <>; print unpack("H2" x length($input), $input)'
> +}
> +
> +# Inserts $1 at the start of the string and every 2 characters thereafter.
> +intersperse () {
> +	sed 's/\(..\)/'$1'\1/g'
> +}
> +
> +# Create a one-time-sed command to replace the existing packfile with $1.
> +replace_packfile () {
> +	# The protocol requires that the packfile be sent in sideband 1, hence
> +	# the extra \x01 byte at the beginning.
> +	printf "1,/packfile/!c %04x\\\\x01%s0000" \
> +		"$(($(wc -c <$1) + 5))" \
> +		"$(hex_unpack <$1 | intersperse '\\x')" \
> +		>"$HTTPD_ROOT_PATH/one-time-sed"
>  }

Urgh. This is not a problem *this* patch introduces, but why on Earth do
we have to do complicated computations in shell code using an unholy mix
of complex sed and Perl invocations, making things fragile and slow? We do
have such a nice facility is the t/test-tool helper...

The refactoring itself looks correct to me, of course.

Thanks,
Dscho

>
>  test_expect_success 'upon cloning, check that all refs point to objects' '
> @@ -270,10 +284,7 @@ test_expect_success 'upon cloning, check that all refs point to objects' '
>  	# Replace the existing packfile with the crafted one. The protocol
>  	# requires that the packfile be sent in sideband 1, hence the extra
>  	# \x01 byte at the beginning.
> -	printf "1,/packfile/!c %04x\\\\x01%s0000" \
> -		"$(($(wc -c <incomplete.pack) + 5))" \
> -		"$(sed_escape <incomplete.pack)" \
> -		>"$HTTPD_ROOT_PATH/one-time-sed" &&
> +	replace_packfile incomplete.pack &&
>
>  	# Use protocol v2 because the sed command looks for the "packfile"
>  	# section header.
> @@ -313,10 +324,7 @@ test_expect_success 'when partial cloning, tolerate server not sending target of
>  	# Replace the existing packfile with the crafted one. The protocol
>  	# requires that the packfile be sent in sideband 1, hence the extra
>  	# \x01 byte at the beginning.
> -	printf "1,/packfile/!c %04x\\\\x01%s0000" \
> -		"$(($(wc -c <incomplete.pack) + 5))" \
> -		"$(sed_escape <incomplete.pack)" \
> -		>"$HTTPD_ROOT_PATH/one-time-sed" &&
> +	replace_packfile incomplete.pack &&
>
>  	# Use protocol v2 because the sed command looks for the "packfile"
>  	# section header.
> --
> 2.21.0.1020.gf2820cf01a-goog
>
>

  reply	other threads:[~2019-05-15  8:36 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-14 21:10 [PATCH 0/2] Partial clone fix: handling received REF_DELTA Jonathan Tan
2019-05-14 21:10 ` [PATCH 1/2] t5616: refactor packfile replacement Jonathan Tan
2019-05-15  8:36   ` Johannes Schindelin [this message]
2019-05-15 18:22     ` Jonathan Tan
2019-05-14 21:10 ` [PATCH 2/2] index-pack: prefetch missing REF_DELTA bases Jonathan Tan
2019-05-15  8:46   ` Johannes Schindelin
2019-05-15 18:28     ` Jonathan Tan
2019-05-17 18:33       ` Johannes Schindelin
2019-05-15 23:16   ` Jeff King
2019-05-16  1:43     ` Junio C Hamano
2019-05-16  4:04       ` Jeff King
2019-05-16 18:26     ` Jonathan Tan
2019-05-16 21:12       ` Jeff King
2019-05-16 21:30         ` Jonathan Tan
2019-05-16 21:42           ` Jeff King
2019-05-16 23:15             ` Jonathan Tan
2019-05-17  1:09               ` Jeff King
2019-05-17  1:22                 ` Jeff King
2019-05-17  4:39                   ` Jeff King
2019-05-17  4:42                     ` Jeff King
2019-05-17  7:20                     ` Duy Nguyen
2019-05-17  8:55                       ` Jeff King
2019-05-18 11:39                         ` Duy Nguyen
2019-05-20 23:04                           ` Nicolas Pitre
2019-05-21 21:20                             ` Jeff King
2019-06-03 22:23   ` Jonathan Nieder

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=nycvar.QRO.7.76.6.1905151032500.44@tvgsbejvaqbjf.bet \
    --to=johannes.schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=jonathantanmy@google.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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).