git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] t5540-http-test: shorten grep pattern
@ 2011-08-28  4:42 Brian Gernhardt
  2011-08-29  5:17 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Brian Gernhardt @ 2011-08-28  4:42 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano

On OS X, the grep pattern

    "\"OP .*/objects/$x2/X38_X40 HTTP/[.0-9]*\" 20[0-9] "

is far too long ($x38 and $x40 represent 38 and 40 copies of
[0-9a-f]).  In order to still be able to match this, use the sed
invocation to replace what we're looking for a token.

Signed-off-by: Brian Gernhardt <brian@gernhardtsoftware.com>
---
 t/t5540-http-push.sh |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/t/t5540-http-push.sh b/t/t5540-http-push.sh
index a266ca5..5bf287d 100755
--- a/t/t5540-http-push.sh
+++ b/t/t5540-http-push.sh
@@ -132,8 +132,9 @@ x38="$x5$x5$x5$x5$x5$x5$x5$x1$x1$x1"
 x40="$x38$x2"
 
 test_expect_success 'PUT and MOVE sends object to URLs with SHA-1 hash suffix' '
-	sed -e "s/PUT /OP /" -e "s/MOVE /OP /" "$HTTPD_ROOT_PATH"/access.log |
-	grep -e "\"OP .*/objects/$x2/${x38}_$x40 HTTP/[.0-9]*\" 20[0-9] "
+	sed -e "s/PUT /OP /" -e "s/MOVE /OP /" -e "s/$x40/X40/" -e "s/$x38/X38/"\
+		"$HTTPD_ROOT_PATH"/access.log |
+	grep -e "\"OP .*/objects/$x2/X38_X40 HTTP/[.0-9]*\" 20[0-9] "
 
 '
 
-- 
1.7.6.671.g4d09b

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] t5540-http-test: shorten grep pattern
  2011-08-28  4:42 [PATCH] t5540-http-test: shorten grep pattern Brian Gernhardt
@ 2011-08-29  5:17 ` Junio C Hamano
  2011-08-29  6:42   ` [PATCH v2] " Brian Gernhardt
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2011-08-29  5:17 UTC (permalink / raw)
  To: Brian Gernhardt; +Cc: Git List

Brian Gernhardt <brian@gernhardtsoftware.com> writes:

> On OS X, the grep pattern
>
>     "\"OP .*/objects/$x2/X38_X40 HTTP/[.0-9]*\" 20[0-9] "
>
> is far too long ($x38 and $x40 represent 38 and 40 copies of
> [0-9a-f]).  In order to still be able to match this, use the sed
> invocation to replace what we're looking for a token.
>
> Signed-off-by: Brian Gernhardt <brian@gernhardtsoftware.com>
> ---
>  t/t5540-http-push.sh |    5 +++--
>  1 files changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/t/t5540-http-push.sh b/t/t5540-http-push.sh
> index a266ca5..5bf287d 100755
> --- a/t/t5540-http-push.sh
> +++ b/t/t5540-http-push.sh
> @@ -132,8 +132,9 @@ x38="$x5$x5$x5$x5$x5$x5$x5$x1$x1$x1"
>  x40="$x38$x2"
>  
>  test_expect_success 'PUT and MOVE sends object to URLs with SHA-1 hash suffix' '
> -	sed -e "s/PUT /OP /" -e "s/MOVE /OP /" "$HTTPD_ROOT_PATH"/access.log |
> -	grep -e "\"OP .*/objects/$x2/${x38}_$x40 HTTP/[.0-9]*\" 20[0-9] "
> +	sed -e "s/PUT /OP /" -e "s/MOVE /OP /" -e "s/$x40/X40/" -e "s/$x38/X38/"\
> +		"$HTTPD_ROOT_PATH"/access.log |
> +	grep -e "\"OP .*/objects/$x2/X38_X40 HTTP/[.0-9]*\" 20[0-9] "
>  
>  '

Hmm...

Is it sensible to replace $x40 with X40 and $x38 with X38 on any line
anywhere for the purpose of this test? As the downstream test is only
interested in a line with HTTP request line that asks for a specific path
under objects/??/?{38}_?{40}, wouldn't it make more sense to replace
occurrences of only such line?

	sed -n \
            -e "s/PUT /OP " \
	    -e "s/MOVE /OP /" \
	    -e "s|/objects/$x2/$x38_$x40|WANTED_PATH_REQUEST|p" \
	    "$HTTPD_ROOT_PATH/access.log" |
	grep -e "\"OP .*WANTED_PATH_REQUEST HTTP/[.0-9]*\" 20[0-9] "

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2] t5540-http-test: shorten grep pattern
  2011-08-29  5:17 ` Junio C Hamano
@ 2011-08-29  6:42   ` Brian Gernhardt
  0 siblings, 0 replies; 3+ messages in thread
From: Brian Gernhardt @ 2011-08-29  6:42 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git List

On OS X, the grep pattern

    "\"OP .*/objects/$x2/X38_X40 HTTP/[.0-9]*\" 20[0-9] "

is too long ($x38 and $x40 represent 38 and 40 copies of [0-9a-f]) for
grep to handle.  In order to still be able to match this, use the sed
invocation to replace what we're looking for with a token.

Improved-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Brian Gernhardt <brian@gernhardtsoftware.com>
---
 t/t5540-http-push.sh |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

On Aug 29, 2011, at 1:17 AM, Junio C Hamano wrote:

> Is it sensible to replace $x40 with X40 and $x38 with X38 on any line
> anywhere for the purpose of this test? As the downstream test is only
> interested in a line with HTTP request line that asks for a specific path
> under objects/??/?{38}_?{40}, wouldn't it make more sense to replace
> occurrences of only such line?

Yes, of course.  The reason it ended up the way it did was that I first
tried replacing $x40 with SHA-1, but that was still too long.  Your way
makes more sense in the end, although the $x38_$x40 bit needs to be
${x38}_$x40 so the shell looks for the right variable.

diff --git a/t/t5540-http-push.sh b/t/t5540-http-push.sh
index a266ca5..64767d8 100755
--- a/t/t5540-http-push.sh
+++ b/t/t5540-http-push.sh
@@ -132,8 +132,12 @@ x38="$x5$x5$x5$x5$x5$x5$x5$x1$x1$x1"
 x40="$x38$x2"
 
 test_expect_success 'PUT and MOVE sends object to URLs with SHA-1 hash suffix' '
-	sed -e "s/PUT /OP /" -e "s/MOVE /OP /" "$HTTPD_ROOT_PATH"/access.log |
-	grep -e "\"OP .*/objects/$x2/${x38}_$x40 HTTP/[.0-9]*\" 20[0-9] "
+	sed \
+		-e "s/PUT /OP /" \
+		-e "s/MOVE /OP /" \
+	    -e "s|/objects/$x2/${x38}_$x40|WANTED_PATH_REQUEST|" \
+		"$HTTPD_ROOT_PATH"/access.log |
+	grep -e "\"OP .*WANTED_PATH_REQUEST HTTP/[.0-9]*\" 20[0-9] "
 
 '
 
-- 
1.7.7.rc0.308.g517a2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-08-29  6:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-28  4:42 [PATCH] t5540-http-test: shorten grep pattern Brian Gernhardt
2011-08-29  5:17 ` Junio C Hamano
2011-08-29  6:42   ` [PATCH v2] " Brian Gernhardt

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).