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

Re: [PATCH] t/gitweb-lib: Split HTTP response with non-GNU sed

From
Jakub Narebski <jnareb@gmail.com>
Date
Nov 24, 2009, 16:59 UTC
Message-ID
<200911241759.28972.jnareb@gmail.com>
In-Reply-To
<7vocmtyu3v.fsf@alter.siamese.dyndns.org>
On Mon, 23 Nov 2009, Junio C Hamano wrote:
Show 5 quoted lines
> Brian Gernhardt <brian@gernhardtsoftware.com> writes:
> 
> > Recognizing \r in a regex is something GNU sed will do, but other sed
> > implementation's won't.  (Found with BSD sed on OS X.) So use a
> > literal carriage return instead.
[...]
Show 17 quoted lines
> > diff --git a/t/gitweb-lib.sh b/t/gitweb-lib.sh
> > index 32b841d..35dda58 100644
> > --- a/t/gitweb-lib.sh
> > +++ b/t/gitweb-lib.sh
> > @@ -52,8 +52,8 @@ gitweb_run () {
> >         rm -f gitweb.log &&
> >         perl -- "$SCRIPT_NAME" \
> >                 >gitweb.output 2>gitweb.log &&
> > -       sed -e   '/^\r$/q' <gitweb.output >gitweb.headers &&
> > -       sed -e '1,/^\r$/d' <gitweb.output >gitweb.body    &&
> > +       sed -e   '/^
> > $/q' <gitweb.output >gitweb.headers &&
> > +       sed -e '1,/^
> > $/d' <gitweb.output >gitweb.body    &&
> >         if grep '^[[]' gitweb.log >/dev/null 2>&1; then false; else
> > true; fi 
> >         # gitweb.log is left for debugging

If we were to do it this way, I would prefer to set and then use 'cr' or 'crlf' variable (in sed expression).

Show 18 quoted lines
> 
> I'd actually prefer not having to deal with this issue.  How about doing
> something like this instead?
> 
>  t/gitweb-lib.sh |   14 ++++++++++++--
>  1 files changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/t/gitweb-lib.sh b/t/gitweb-lib.sh
> index 32b841d..3121950 100644
> --- a/t/gitweb-lib.sh
> +++ b/t/gitweb-lib.sh
> @@ -52,8 +52,18 @@ gitweb_run () {
>  	rm -f gitweb.log &&
>  	perl -- "$SCRIPT_NAME" \
>  		>gitweb.output 2>gitweb.log &&
> -	sed -e   '/^\r$/q' <gitweb.output >gitweb.headers &&
> -	sed -e '1,/^\r$/d' <gitweb.output >gitweb.body    &&
> +	perl -w -e '
"perl", or "$PERL", or "$PERL_PATH"?
> +		open O, ">gitweb.headers";
Well, modern Perl would use here
+		open my $fh, ">", "gitweb.headers";
But it is not that important here.
Show 14 quoted lines
> +		while (<>) {
> +			print O;
> +			last if (/^\r$/ || /^$/);
> +		}
> +		open O, ">gitweb.body";
> +		while (<>) {
> +			print O;
> +		}
> +		close O;
> +	' gitweb.output &&
>  	if grep '^[[]' gitweb.log >/dev/null 2>&1; then false; else true; fi
>  
>  	# gitweb.log is left for debugging
> 

This is a good solution. We test Perl script anyway (so Perl is required for running this test), and this way we can do this portably and in one pass (one fork).

-- 
Jakub Narebski
Poland
Previous: Brian Gernhardt
Message 4 of 4 in “t/gitweb-lib: Split HTTP response with non-GNU sed”
  1. t/gitweb-lib: Split HTTP response with non-GNU sedBrian Gernhardt, Nov 23, 2009
  2. Junio C HamanoNov 23, 2009
  3. Brian GernhardtNov 23, 2009
  4. Jakub NarebskiNov 24, 2009

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.