提交 c5f71ad0 编写于 作者: S Sam Vilain 提交者: Junio C Hamano

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: NEric Wong <normalperson@yhbt.net>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 efd8f793
...@@ -38,14 +38,16 @@ ...@@ -38,14 +38,16 @@
use Git; use Git;
BEGIN { BEGIN {
my $s; # import functions from Git into our packages, en masse
no strict 'refs';
foreach (qw/command command_oneline command_noisy command_output_pipe foreach (qw/command command_oneline command_noisy command_output_pipe
command_input_pipe command_close_pipe/) { command_input_pipe command_close_pipe/) {
$s .= "*SVN::Git::Editor::$_ = *SVN::Git::Fetcher::$_ = ". for my $package ( qw(SVN::Git::Editor SVN::Git::Fetcher
"*Git::SVN::Migration::$_ = ". Git::SVN::Migration Git::SVN::Log Git::SVN),
"*Git::SVN::Log::$_ = *Git::SVN::$_ = *$_ = *Git::$_; "; __PACKAGE__) {
*{"${package}::$_"} = \&{"Git::$_"};
}
} }
eval $s;
} }
my ($SVN); my ($SVN);
...@@ -846,26 +848,26 @@ BEGIN ...@@ -846,26 +848,26 @@ BEGIN
# some options are read globally, but can be overridden locally # some options are read globally, but can be overridden locally
# per [svn-remote "..."] section. Command-line options will *NOT* # per [svn-remote "..."] section. Command-line options will *NOT*
# override options set in an [svn-remote "..."] section # override options set in an [svn-remote "..."] section
my $e; no strict 'refs';
foreach (qw/follow_parent no_metadata use_svm_props for my $option (qw/follow_parent no_metadata use_svm_props
use_svnsync_props/) { use_svnsync_props/) {
my $key = $_; my $key = $option;
$key =~ tr/_//d; $key =~ tr/_//d;
$e .= "sub $_ { my $prop = "-$option";
my (\$self) = \@_; *$option = sub {
return \$self->{-$_} if exists \$self->{-$_}; my ($self) = @_;
my \$k = \"svn-remote.\$self->{repo_id}\.$key\"; return $self->{$prop} if exists $self->{$prop};
eval { command_oneline(qw/config --get/, \$k) }; my $k = "svn-remote.$self->{repo_id}.$key";
if (\$@) { eval { command_oneline(qw/config --get/, $k) };
\$self->{-$_} = \$Git::SVN::_$_; if ($@) {
$self->{$prop} = ${"Git::SVN::_$option"};
} else { } else {
my \$v = command_oneline(qw/config --bool/,\$k); my $v = command_oneline(qw/config --bool/,$k);
\$self->{-$_} = \$v eq 'false' ? 0 : 1; $self->{$prop} = $v eq 'false' ? 0 : 1;
} }
return \$self->{-$_} }\n"; return $self->{$prop};
}
} }
$e .= "1;\n";
eval $e or die $@;
} }
my %LOCKFILES; my %LOCKFILES;
...@@ -2899,17 +2901,17 @@ package Git::SVN::Ra; ...@@ -2899,17 +2901,17 @@ package Git::SVN::Ra;
BEGIN { BEGIN {
# enforce temporary pool usage for some simple functions # enforce temporary pool usage for some simple functions
my $e; no strict 'refs';
foreach (qw/rev_proplist get_latest_revnum get_uuid get_repos_root/) { for my $f (qw/rev_proplist get_latest_revnum get_uuid get_repos_root/) {
$e .= "sub $_ { my $SUPER = "SUPER::$f";
my \$self = shift; *$f = sub {
my \$pool = SVN::Pool->new; my $self = shift;
my \@ret = \$self->SUPER::$_(\@_,\$pool); my $pool = SVN::Pool->new;
\$pool->clear; my @ret = $self->$SUPER(@_,$pool);
wantarray ? \@ret : \$ret[0]; }\n"; $pool->clear;
wantarray ? @ret : $ret[0];
};
} }
eval "$e; 1;" or die $@;
} }
sub new { sub new {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册