@matheusbsbs / matheus-bagliano / commits / c5f71ad099
Fork 0

git-svn: avoid string eval for defining functions

You don't need to use string eval to define new functions; assigning a code reference to the target symbol table is enough. Acked-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Sam Vilain committed Jun 15, 2007 at 15:43 UTC c5f71ad09994b46d80878ce72d1ca6f59935d952
1 file changed +33 -31
git-svn.perl
+33 -31
@@ -38,14 +38,16 @@ use IPC::Open3;
38 use Git;
39
40 BEGIN {
41 - my $s;
41 + # import functions from Git into our packages, en masse
42 + no strict 'refs';
43 foreach (qw/command command_oneline command_noisy command_output_pipe
44 command_input_pipe command_close_pipe/) {
44 - $s .= "*SVN::Git::Editor::$_ = *SVN::Git::Fetcher::$_ = ".
45 - "*Git::SVN::Migration::$_ = ".
46 - "*Git::SVN::Log::$_ = *Git::SVN::$_ = *$_ = *Git::$_; ";
45 + for my $package ( qw(SVN::Git::Editor SVN::Git::Fetcher
46 + Git::SVN::Migration Git::SVN::Log Git::SVN),
47 + __PACKAGE__) {
48 + *{"${package}::$_"} = \&{"Git::$_"};
49 + }
50 }
48 - eval $s;
51 }
52
53 my ($SVN);
@@ -846,26 +848,26 @@ BEGIN {
848 # some options are read globally, but can be overridden locally
849 # per [svn-remote "..."] section. Command-line options will *NOT*
850 # override options set in an [svn-remote "..."] section
849 - my $e;
850 - foreach (qw/follow_parent no_metadata use_svm_props
851 - use_svnsync_props/) {
852 - my $key = $_;
851 + no strict 'refs';
852 + for my $option (qw/follow_parent no_metadata use_svm_props
853 + use_svnsync_props/) {
854 + my $key = $option;
855 $key =~ tr/_//d;
854 - $e .= "sub $_ {
855 - my (\$self) = \@_;
856 - return \$self->{-$_} if exists \$self->{-$_};
857 - my \$k = \"svn-remote.\$self->{repo_id}\.$key\";
858 - eval { command_oneline(qw/config --get/, \$k) };
859 - if (\$@) {
860 - \$self->{-$_} = \$Git::SVN::_$_;
856 + my $prop = "-$option";
857 + *$option = sub {
858 + my ($self) = @_;
859 + return $self->{$prop} if exists $self->{$prop};
860 + my $k = "svn-remote.$self->{repo_id}.$key";
861 + eval { command_oneline(qw/config --get/, $k) };
862 + if ($@) {
863 + $self->{$prop} = ${"Git::SVN::_$option"};
864 } else {
862 - my \$v = command_oneline(qw/config --bool/,\$k);
863 - \$self->{-$_} = \$v eq 'false' ? 0 : 1;
865 + my $v = command_oneline(qw/config --bool/,$k);
866 + $self->{$prop} = $v eq 'false' ? 0 : 1;
867 }
865 - return \$self->{-$_} }\n";
868 + return $self->{$prop};
869 + }
870 }
867 - $e .= "1;\n";
868 - eval $e or die $@;
871 }
872
873 my %LOCKFILES;
@@ -2899,17 +2901,17 @@ my ($can_do_switch, %ignored_err, $RA);
2901
2902 BEGIN {
2903 # enforce temporary pool usage for some simple functions
2902 - my $e;
2903 - foreach (qw/rev_proplist get_latest_revnum get_uuid get_repos_root/) {
2904 - $e .= "sub $_ {
2905 - my \$self = shift;
2906 - my \$pool = SVN::Pool->new;
2907 - my \@ret = \$self->SUPER::$_(\@_,\$pool);
2908 - \$pool->clear;
2909 - wantarray ? \@ret : \$ret[0]; }\n";
2904 + no strict 'refs';
2905 + for my $f (qw/rev_proplist get_latest_revnum get_uuid get_repos_root/) {
2906 + my $SUPER = "SUPER::$f";
2907 + *$f = sub {
2908 + my $self = shift;
2909 + my $pool = SVN::Pool->new;
2910 + my @ret = $self->$SUPER(@_,$pool);
2911 + $pool->clear;
2912 + wantarray ? @ret : $ret[0];
2913 + };
2914 }
2911 -
2912 - eval "$e; 1;" or die $@;
2915 }
2916
2917 sub new {