Replace perl code with pure shell code
PATCH 1/1 Replace perl code with pure shell code
---git-clone.sh | 65 ++++++++++++++++++---------------------------------------
1 files changed, 21 insertions(+), 44 deletions(-)
git-clone.sh +0 -0
@@ -66,48 +66,6 @@ Perhaps git-update-server-info needs to be run there?"
rm -f "$GIT_DIR/REMOTE_HEAD"
}
-# Read git-fetch-pack -k output and store the remote branches.
-copy_refs='
-use File::Path qw(mkpath);
-use File::Basename qw(dirname);
-my $git_dir = $ARGV[0];
-my $use_separate_remote = $ARGV[1];
-my $origin = $ARGV[2];
-
-my $branch_top = ($use_separate_remote ? "remotes/$origin" : "heads");
-my $tag_top = "tags";
-
-sub store {
- my ($sha1, $name, $top) = @_;
- $name = "$git_dir/refs/$top/$name";
- mkpath(dirname($name));
- open O, ">", "$name";
- print O "$sha1\n";
- close O;
-}
-
-open FH, "<", "$git_dir/CLONE_HEAD";
-while (<FH>) {
- my ($sha1, $name) = /^([0-9a-f]{40})\s(.*)$/;
- next if ($name =~ /\^\173/);
- if ($name eq "HEAD") {
- open O, ">", "$git_dir/REMOTE_HEAD";
- print O "$sha1\n";
- close O;
- next;
- }
- if ($name =~ s/^refs\/heads\///) {
- store($sha1, $name, $branch_top);
- next;
- }
- if ($name =~ s/^refs\/tags\///) {
- store($sha1, $name, $tag_top);
- next;
- }
-}
-close FH;
-'
-
quiet=
local=no
use_local=no
@@ -332,8 +290,27 @@ test -d "$GIT_DIR/refs/reference-tmp" && rm -fr "$GIT_DIR/refs/reference-tmp" if test -f "$GIT_DIR/CLONE_HEAD"
then
# Read git-fetch-pack -k output and store the remote branches.
- @@PERL@@ -e "$copy_refs" "$GIT_DIR" "$use_separate_remote" "$origin" ||
- exit
+ if [ -n "$use_separate_remote" ]
+ then
+ branch_top="remotes/$origin"
+ else
+ branch_top="heads"
+ fi
+ tag_top="tags"
+ while read sha1 name
+ do
+ case "$name" in
+ HEAD)
+ destname="REMOTE_HEAD" ;;
+ refs/heads/*)
+ destname="refs/$branch_top/${name#refs/heads/}" ;;
+ refs/tags/*)
+ destname="refs/$tag_top/${name#refs/tags/}" ;;
+ *)
+ continue ;;
+ esac
+ git-update-ref -m "clone: from $repo" "$destname" "$sha1" ""
+ done < "$GIT_DIR/CLONE_HEAD"
fi
cd "$D" || exit
Signature · 1 line
1.5.0.rc1.196.geebfb
Quoted 7 lines · Simon 'corecode' Schubert
Signed-off-by Simon 'corecode' Schubert <[email protected]>...
git-clone.sh +0
-0
git-clone.sh Perhaps git-update-server-info needs to be run there?"
Quoted 7 lines
git-clone.sh +0
-5@@ -66,48 +66,6 @@ Perhaps git-update-server-info needs to be run there?" -open FH, "<", "$git_dir/CLONE_HEAD"; -while (<FH>) { - my ($sha1, $name) = /^([0-9a-f]{40})\s(.*)$/; - next if ($name =~ /\^\173/); - if ($name eq "HEAD") {
Thanks. I like the general direction, but not quite.
You exposed one outstanding bug, which is a hint about what is not quite right with your patch.
-- >8 --
[PATCH] update-ref: do not accept malformatted refs.
We used to use lock_any_ref_for_update() because the command needs to also update HEAD (which is not under refs/, so lock_ref_sha1() cannot be used). The function however did not check for refs with illegal characters in them.
Use check_ref_format() to catch malformed refs. For this check, we specifically do not want to say having less than two levels in the name is illegal to allow HEAD (and perhaps other special refs in the future).
---
builtin-update-ref.c +2 -4
@@ -61,10 +61,8 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix) lock =lock_any_ref_for_update (refname, oldval ? oldsha1 :NULL );if (!lock) -return 1 ; +die ("%s: cannot lock the ref" , refname);if (write_ref_sha1 (lock, sha1, msg) <0 ) -return 1 ; - -/* write_ref_sha1 always unlocks the ref, no need to do it explicitly */ +die ("%s: cannot update the ref" , refname);return 0 ; }
refs.c +2 -0
@@ -710,6 +710,8 @@ struct ref_lock *lock_ref_sha1(const char *ref, const unsigned char *old_sha1)struct ref_lock *lock_any_ref_for_update (const char *ref,const unsigned char *old_sha1) { +if (check_ref_format (ref) ==-1 ) +return NULL ;return lock_ref_sha1_basic (ref, old_sha1,NULL ); }
PATCH 1/1 Replace perl code with pure shell code
---
Quoted 8 lines
Review
Quoted 3 lines
(quoted diff) +0
-2- next if ($name =~ /\^\173/); - if ($name eq "HEAD") {Thanks. I like the general direction, but not quite.
You exposed one outstanding bug, which is a hint about what is not quite right with your patch.
I already wondered. What's those ^{} tags, and why is CLONE_HEAD littered with them?
git-clone.sh | 67 ++++++++++++++++++++--------------------------------------
1 files changed, 23 insertions(+), 44 deletions(-)
git-clone.sh +0 -0
@@ -66,48 +66,6 @@ Perhaps git-update-server-info needs to be run there?"
rm -f "$GIT_DIR/REMOTE_HEAD"
}
-# Read git-fetch-pack -k output and store the remote branches.
-copy_refs='
-use File::Path qw(mkpath);
-use File::Basename qw(dirname);
-my $git_dir = $ARGV[0];
-my $use_separate_remote = $ARGV[1];
-my $origin = $ARGV[2];
-
-my $branch_top = ($use_separate_remote ? "remotes/$origin" : "heads");
-my $tag_top = "tags";
-
-sub store {
- my ($sha1, $name, $top) = @_;
- $name = "$git_dir/refs/$top/$name";
- mkpath(dirname($name));
- open O, ">", "$name";
- print O "$sha1\n";
- close O;
-}
-
-open FH, "<", "$git_dir/CLONE_HEAD";
-while (<FH>) {
- my ($sha1, $name) = /^([0-9a-f]{40})\s(.*)$/;
- next if ($name =~ /\^\173/);
- if ($name eq "HEAD") {
- open O, ">", "$git_dir/REMOTE_HEAD";
- print O "$sha1\n";
- close O;
- next;
- }
- if ($name =~ s/^refs\/heads\///) {
- store($sha1, $name, $branch_top);
- next;
- }
- if ($name =~ s/^refs\/tags\///) {
- store($sha1, $name, $tag_top);
- next;
- }
-}
-close FH;
-'
-
quiet=
local=no
use_local=no
@@ -332,8 +290,29 @@ test -d "$GIT_DIR/refs/reference-tmp" && rm -fr "$GIT_DIR/refs/reference-tmp" if test -f "$GIT_DIR/CLONE_HEAD"
then
# Read git-fetch-pack -k output and store the remote branches.
- @@PERL@@ -e "$copy_refs" "$GIT_DIR" "$use_separate_remote" "$origin" ||
- exit
+ if [ -n "$use_separate_remote" ]
+ then
+ branch_top="remotes/$origin"
+ else
+ branch_top="heads"
+ fi
+ tag_top="tags"
+ while read sha1 name
+ do
+ case "$name" in
+ *^{*)
+ continue ;;
+ HEAD)
+ destname="REMOTE_HEAD" ;;
+ refs/heads/*)
+ destname="refs/$branch_top/${name#refs/heads/}" ;;
+ refs/tags/*)
+ destname="refs/$tag_top/${name#refs/tags/}" ;;
+ *)
+ continue ;;
+ esac
+ git-update-ref -m "clone: from $repo" "$destname" "$sha1" ""
+ done < "$GIT_DIR/CLONE_HEAD"
fi
cd "$D" || exit
Signature · 1 line
1.5.0.rc1.196.geebfb
Quoted 2 lines · Simon 'corecode' Schubert
I already wondered. What's those ^{} tags, and why is
CLONE_HEADlittered with them?
They are the deref of the thing without them.
As in, "foo" is a tag pointing at some object (probably a commit but not necessarily) then "foo^{}" is whatever "foo"'s tag points at.
Review
Quoted 3 lines
(quoted diff) +3
-0+ case "$name" in + *^{*) + continue ;;
Probably could just be:
case "$name" in
*^{})
continue ;;This is common in Git. ^{} on the end of a ref name shows up in the peek-remote/ls-remote output, but certainly is *not* a ref.
Sorry I missed that case eariler when I reviewed the patch. I thought about it and why it wasn't handled here, but then thought maybe it wasn't actually occuring in the input (that someone else higher up had filtered them out).
Signature · 1 line
Shawn.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Simon" == Simon 'corecode' Schubert <[email protected]> writes:
Simon> + destname="refs/$branch_top/${name#refs/heads/}" ;;
I don't think this is portable shell. At least Perl is the same everywhere. Ignore me if this is a shell syntax on something other than bash.
Signature · 4 lines
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 <[email protected]> <URL:http://www.stonehenge.com/merlyn/> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Quoted 6 lines · Randal L. Schwartz
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Simon" == Simon 'corecode' Schubert <[email protected]> writes:
Simon> + destname="refs/$branch_top/${name#refs/heads/}" ;;
I don't think this is portable shell. At least Perl is the same everywhere. Ignore me if this is a shell syntax on something other than bash.
According to "The Open Group Base Specifications Issue 6" [1]:
${parameter#word}
Remove Smallest Prefix Pattern. The word shall be expanded to
produce a pattern. The parameter expansion shall then result in parameter, with the smallest portion of the prefix matched by the pattern deleted.
We do require a POSIX-compliant version of sh already, right?
nikolai
[1] http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_02
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Nikolai" == Nikolai Weibull <[email protected]> writes:
Nikolai> We do require a POSIX-compliant version of sh already, right?
OK, sorry for raising the flag. I just know that writing portable shell is far trickier than writing portable Perl, so I get overly cautious on anything that wasn't in Unix V7.
Signature · 4 lines
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 <[email protected]> <URL:http://www.stonehenge.com/merlyn/> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Quoted 7 lines · [email protected] (Randal L. Schwartz) writes:
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Nikolai" == Nikolai Weibull <[email protected]> writes:
Nikolai> We do require a POSIX-compliant version of sh already, right?
OK, sorry for raising the flag. I just know that writing portable shell is far trickier than writing portable Perl, so I get overly cautious on anything that wasn't in Unix V7.
You seem to be as old fashioned as I am (I grew up with V7 shell). People complained often enough how antiquated my shell script (hence many but not all git Porcelain-ish) style is.
I have tried very hard to reject "Hey, it's in POSIX -- we'll use it and screw platforms that are not exactly POSIX". I only use POSIX as a yardstick to decide what to stay away from, as in "Let's not use ${parameter//pattern/string} -- it is not _even_ in POSIX".
Quoted 7 lines · Randal L. Schwartz
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Nikolai" == Nikolai Weibull <[email protected]> writes:
Nikolai> We do require a POSIX-compliant version of sh already, right?
OK, sorry for raising the flag. I just know that writing portable shell is far trickier than writing portable Perl, so I get overly cautious on anything that wasn't in Unix V7.
No problem; I wasn't sure on the current requirements myself :-). It's too bad that not all the great stuff one can find in Bash and Zsh were in the original...
nikolai
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Nikolai" == Nikolai Weibull <[email protected]> writes:
Quoted 2 lines · Randal L. Schwartz
Quoted 2 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Nikolai" == Nikolai Weibull <[email protected]> writes:
Nikolai> We do require a POSIX-compliant version of sh already, right?
Quoted 4 lines
Quoted 4 lines
OK, sorry for raising the flag. I just know that writing portable shell is far trickier than writing portable Perl, so I get overly cautious on anything that wasn't in Unix V7.
Nikolai> No problem; I wasn't sure on the current requirements myself :-). Nikolai> It's too bad that not all the great stuff one can find in Bash and Zsh Nikolai> were in the original...
I'll probably seem like a traitor to my tribe for saying this, but if zsh or gnu awk had been around at the time Perl was created, we wouldn't have seen Perl. Of course, Perl has gone far beyond the "awk replacement" as originally planned, but who knows what might have happened next?
Signature · 4 lines
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 <[email protected]> <URL:http://www.stonehenge.com/merlyn/> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Quoted 6 lines · Randal L. Schwartz
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Simon" == Simon 'corecode' Schubert <[email protected]> writes:
Simon> + destname="refs/$branch_top/${name#refs/heads/}" ;;
I don't think this is portable shell. At least Perl is the same everywhere. Ignore me if this is a shell syntax on something other than bash.
I think ${var#pattern} is a POSIX shell syntax.
Nevertheless Perl embedded in shell script is (a bit) horrible.
Signature · 3 lines
Jakub Narebski Warsaw, Poland ShadeHawk on #git
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Jakub" == Jakub Narebski <[email protected]> writes:
Jakub> Nevertheless Perl embedded in shell script is (a bit) horrible.
I will agree with that. Either all Perl, or all shell, unless there's an operation that begs for portability for which Perl can be an asset.
Signature · 4 lines
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 <[email protected]> <URL:http://www.stonehenge.com/merlyn/> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!