gitweb-lib.sh: Set up PATH to use perl from /usr/bin
PATCH 1/1 gitweb-lib.sh: Set up PATH to use perl from /usr/bin
When there are different version of perl installed on the machine, the $PATH may point out a different version of perl than /usr/bin. One example is to have /opt/local/bin/perl before /usr/bin/perl.
Sanitize the PATH by adding /usr/bin at the beginning
---
On my Mac OS machine t9501-gitweb-standalone-http-status.sh failed because perl was found under /opt/local/bin instead of of /usr/bin.
/opt/local/bin is coming from Macports.
The problem with different perl installations on the same machine may hit more people than just me.
There are different solutions, please help to find the best one:
a) Delete perl from /opt/local/bin
b) Put /opt/local/bin at the end of the PATH
c) Change gitweb-lib.sh to set up the PATH to /usr/bin, because that is what the file gitweb_config.perl generated by gitweb-lib.sh expects.
t/gitweb-lib.sh | 3 +++ 1 file changed, 3 insertions(+)
t/gitweb-lib.sh +3 -0
@@ -113,4 +113,7 @@ perl -MCGI -MCGI::Util -MCGI::Carp -e 0 >/dev/null 2>&1 || { test_done } +PATH=/usr/bin/:$PATH +export PATH + gitweb_init
Signature · 1 line
1.7.10.rc0.17.g74595.dirty
Quoted 5 lines · Torsten Bögershausen
When there are different version of perl installed on the machine, the $PATH may point out a different version of perl than
/usr/bin. One example is to have/opt/local/bin/perlbefore/usr/bin/perl.Sanitize the PATH by adding
/usr/binat the beginning
Hm, I see that most scripts have #!/usr/bin/perl, and only two have #!env perl [1]. So in general we usally rely on using perl in /usr/bin.
But your patch affects other stuff than perl, and unconditionally changing PATH set by the user is not nice, as it affect programs called recursively. Wouldn't simply replacing all calls to bare perl in t/gitweb-lib.sh with invocations of /usr/bin/perl be better?
[1]
% git grep 'env perl\b'
git-relink.perl:#!/usr/bin/env perl
git-svn.perl:#!/usr/bin/env perl
-
Zbyszek
Quoted 8 lines · Zbigniew Jędrzejewski-Szmek
Quoted 5 lines · Torsten Bögershausen
When there are different version of perl installed on the machine, the $PATH may point out a different version of perl than
/usr/bin. One example is to have/opt/local/bin/perlbefore/usr/bin/perl.Sanitize the PATH by adding
/usr/binat the beginningHm, I see that most scripts have #!/usr/bin/perl, and only two have #!env perl [1]. So in general we usally rely on using perl in
/usr/bin.
The Makefile substitutes $PERL_PATH on the #!-line of each perl script during its "build" step (which is really just copying the file to its final name and running "chmod +x").
So even though the source files say /usr/bin/perl, we are not relying on that. If you look at the Makefile rule carefully, you will see that even "#!/usr/bin/env perl" gets replaced, too. Those scripts should probably be updated, since the mention of env is simply confusing.
Quoted 4 lines
But your patch affects other stuff than perl, and unconditionally changing PATH set by the user is not nice, as it affect programs called recursively. Wouldn't simply replacing all calls to bare perl in
t/gitweb-lib.shwith invocations of/usr/bin/perlbe better?
Yes, although they should use $PERL_PATH rather than hardcoding /usr/bin.
-Peff
Quoted 2 lines · Zbigniew Jędrzejewski-Szmek
Hm, I see that most scripts have #!/usr/bin/perl, and only two have #!env perl [1]. So in general we usally rely on using perl in
/usr/bin.
The #!/usr/bin/env variants should be eradicated. Our Makefile rewrites "#!.*perl" with "#!$PERL_PATH" in scripted Porcelains before installing, so /usr/bin/perl is the right thing to write there.
Quoted 8 lines · Junio C Hamano
Quoted 2 lines · Zbigniew Jędrzejewski-Szmek
Hm, I see that most scripts have #!/usr/bin/perl, and only two have #!env perl [1]. So in general we usally rely on using perl in
/usr/bin.The #!/usr/bin/env variants should be eradicated. Our
Makefilerewrites "#!.*perl" with "#!$PERL_PATH" in scripted Porcelains before installing, so/usr/bin/perlis the right thing to write there.
This would be trivial, as it is only two files.
But I don't see why we would use a different perl in
git-am.sh: perl -ne 'BEGIN { $subject = 0 }
git-am.sh: perl -M'POSIX qw(strftime)' -ne 'BEGIN { $subject = 0 }
git-request-pull.sh:ref=$(git ls-remote "$url" | perl -e "$find_matching_ref" "$head" "$headrev")
git-submodule.sh: perl -e '
test-sha1.sh: perl -pe 'y/\000/g/'
test-sha1.sh: perl -pe 'y/\000/g/'and lot of files in t/. Shouldn't those be replaced too?
Quoted 3 lines · Jeff King
The
Makefilesubstitutes $PERL_PATH on the #!-line of each perl script during its "build" step (which is really just copying the file to its final name and running "chmod +x").
Thank you for the explanation. I never noticed this, since I don't set PERL_PATH myself.
Zbyszek
Quoted 8 lines · Zbigniew Jędrzejewski-Szmek
But I don't see why we would use a different perl in
git-am.sh: perl -ne 'BEGIN { $subject = 0 } git-am.sh: perl -M'POSIX qw(strftime)' -ne 'BEGIN { $subject = 0 } git-request-pull.sh:ref=$(git ls-remote "$url" | perl -e "$find_matching_ref" "$head" "$headrev") git-submodule.sh: perl -e ' test-sha1.sh: perl -pe 'y/\000/g/' test-sha1.sh: perl -pe 'y/\000/g/'and lot of files in t/. Shouldn't those be replaced too?
No. There are two ways in which we use perl:
1. To run our complex scripts like gitweb, git-svn, etc. These require a reasonably modern perl version, and the user must specify it with PERL_PATH if it is not in /usr/bin.
2. To run little snippets that _could_ be written in sed or awk, but which cause portability problems on crappy versions of those tools. These should run under any version of perl5.
It's OK to use 'perl' from the path for (2), because we are not asking very much of perl in that case.
I think the patch we want is just:
t/gitweb-lib.sh +1 -1
@@ -69,7 +69,7 @@ gitweb_run () { # written to web server logs, so we are not interested in that: # we are interested only in properly formatted errors/warnings rm -f gitweb.log && - perl -- "$SCRIPT_NAME" \ + "$PERL_PATH" -- "$SCRIPT_NAME" \ >gitweb.output 2>gitweb.log && perl -w -e ' open O, ">gitweb.headers";
no? Torsten, does that fix your problem?
-Peff
Thanks for all answers,
Quoted 16 lines
I think the patch we want is just:
t/gitweb-lib.sh +1
-1@@ -69,7 +69,7 @@ gitweb_run () { # written to web server logs, so we are not interested in that: # we are interested only in properly formatted errors/warnings rm -f gitweb.log && - perl -- "$SCRIPT_NAME" \ + "$PERL_PATH" -- "$SCRIPT_NAME" \ >gitweb.output 2>gitweb.log && perl -w -e ' open O, ">gitweb.headers";
Quoted 1 line
no? Torsten, does that fix your problem?
Yes, it does.
Should we go for that solution ?
/Torsten
PATCH 1/1 t/gitweb-lib: use $PERL_PATH to run gitweb
The current code runs "perl gitweb.cgi" to test gitweb. This will use whatever version of perl happens to be first in the PATH. We are better off using the specific perl that the user specified via PERL_PATH, which matches what gets put on the #!-line of the built gitweb.cgi.
---
Quoted 2 lines · Torsten Bögershausen
Quoted 1 line
Torsten, does that fix your problem?
Yes, it does.
OK, here it is with a commit message.
t/gitweb-lib.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
t/gitweb-lib.sh +1 -1
@@ -69,7 +69,7 @@ gitweb_run () { # written to web server logs, so we are not interested in that: # we are interested only in properly formatted errors/warnings rm -f gitweb.log && - perl -- "$SCRIPT_NAME" \ + "$PERL_PATH" -- "$SCRIPT_NAME" \ >gitweb.output 2>gitweb.log && perl -w -e ' open O, ">gitweb.headers";
Signature · 1 line
1.7.10.630.g31718
PATCH 1/1 Consistently use perl from /usr/bin/ for scripts
While the majority of scripts use '#!/usr/bin/perl', some use '#!/usr/bin/env perl'. In the end there is no difference, because the Makefile rewrites "#!.*perl" with "#!$PERL_PATH" in scripted Porcelains before installing. Nevertheless, the second form can be misleading, because it suggests that perl found first in $PATH will be used.
--- git-relink.perl | 2 +- git-svn.perl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
git-relink.perl +1 -1
@@ -1,4 +1,4 @@ -#!/usr/bin/env perl +#!/usr/bin/perl # Copyright 2005, Ryan Anderson <[email protected]> # Distribution permitted under the GPL v2, as distributed # by the Free Software Foundation.
git-svn.perl +1 -1
@@ -1,4 +1,4 @@ -#!/usr/bin/env perl +#!/usr/bin/perl # Copyright (C) 2006, Eric Wong <[email protected]> # License: GPL v2 or later use 5.008;
Signature · 1 line
1.7.10.539.g8ecdfe
Re: [PATCH] Consistently use perl from /usr/bin/ for scripts
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Zbigniew" == Zbigniew Jędrzejewski-Szmek <[email protected]> writes:
Zbigniew> Suggested-by: Junio C Hamano <[email protected]> Zbigniew> Signed-off-by: Zbigniew Jędrzejewski-Szmek <[email protected]>
And I strongly support this change. Too many things use that env trick, and it really isn't the proper solution to this.
Signature · 4 lines
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 <[email protected]> <URL:http://www.stonehenge.com/merlyn/> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc. See http://methodsandmessages.posterous.com/ for Smalltalk discussion
Quoted 17 lines · Torsten Bögershausen
Thanks for all answers,
Quoted 16 lines
I think the patch we want is just:
t/gitweb-lib.sh +1
-1@@ -69,7 +69,7 @@ gitweb_run () { # written to web server logs, so we are not interested in that: # we are interested only in properly formatted errors/warnings rm -f gitweb.log && - perl -- "$SCRIPT_NAME" \ + "$PERL_PATH" -- "$SCRIPT_NAME" \ >gitweb.output 2>gitweb.log && perl -w -e ' open O, ">gitweb.headers";
Quoted 4 lines
Quoted 1 line
no? Torsten, does that fix your problem?
Yes, it does.
Should we go for that solution ?
Sounds good.
Quoted 9 lines · Torsten Bögershausen
When there are different version of perl installed on the machine, the $PATH may point out a different version of perl than
/usr/bin. One example is to have/opt/local/bin/perlbefore/usr/bin/perl.
...t/gitweb-lib.sh +0
-0
t/gitweb-lib.sh perl -MCGI -MCGI::Util -MCGI::Carp -e 0 >/dev/null 2>&1 || { · line 119
Quoted 7 lines
t/gitweb-lib.sh +3
-0@@ -113,4 +113,7 @@ perl -MCGI -MCGI::Util -MCGI::Carp -e 0 >/dev/null 2>&1 || { test_done } +PATH=/usr/bin/:$PATH +export PATH + gitweb_init
This is wrong.
What makes you think /usr/bin always has saner version of tools than those in the directories that the user explicitly listed earlier on her $PATH?
If anything it should be honoring $PERL_PATH that is set in the Makefile.