git-svn: prepare SVN::Ra config pieces once
Memoizing these initialization functions saves some memory for long fetches which require scanning many unwanted revisions before any wanted revisions happen. Signed-off-by: Eric Wong <normalperson@yhbt.net>
Eric Wong committed
Oct 29, 2014 at 19:55 UTC
835e3ddeff2ae75b1fe71388686d44c536f2ed55
1 file changed
+36
-27
perl/Git/SVN/Ra.pm
+36
-27
@@ -2,6 +2,7 @@ package Git::SVN::Ra;
2
use vars qw/@ISA $config_dir $_ignore_refs_regex $_log_window_size/;
3
use strict;
4
use warnings;
5
+use Memoize;
6
use SVN::Client;
7
use Git::SVN::Utils qw(
8
canonicalize_url
@@ -76,6 +77,40 @@ sub _auth_providers () {
77
\@rv;
78
}
79
80
+sub prepare_config_once {
81
+ SVN::_Core::svn_config_ensure($config_dir, undef);
82
+ my ($baton, $callbacks) = SVN::Core::auth_open_helper(_auth_providers);
83
+ my $config = SVN::Core::config_get_config($config_dir);
84
+ my $dont_store_passwords = 1;
85
+ my $conf_t = $config->{'config'};
86
+
87
+ no warnings 'once';
88
+ # The usage of $SVN::_Core::SVN_CONFIG_* variables
89
+ # produces warnings that variables are used only once.
90
+ # I had not found the better way to shut them up, so
91
+ # the warnings of type 'once' are disabled in this block.
92
+ if (SVN::_Core::svn_config_get_bool($conf_t,
93
+ $SVN::_Core::SVN_CONFIG_SECTION_AUTH,
94
+ $SVN::_Core::SVN_CONFIG_OPTION_STORE_PASSWORDS,
95
+ 1) == 0) {
96
+ SVN::_Core::svn_auth_set_parameter($baton,
97
+ $SVN::_Core::SVN_AUTH_PARAM_DONT_STORE_PASSWORDS,
98
+ bless (\$dont_store_passwords, "_p_void"));
99
+ }
100
+ if (SVN::_Core::svn_config_get_bool($conf_t,
101
+ $SVN::_Core::SVN_CONFIG_SECTION_AUTH,
102
+ $SVN::_Core::SVN_CONFIG_OPTION_STORE_AUTH_CREDS,
103
+ 1) == 0) {
104
+ $Git::SVN::Prompt::_no_auth_cache = 1;
105
+ }
106
+
107
+ return ($config, $baton, $callbacks);
108
+} # no warnings 'once'
109
+
110
+INIT {
111
+ Memoize::memoize '_auth_providers';
112
+ Memoize::memoize 'prepare_config_once';
113
+}
114
115
sub new {
116
my ($class, $url) = @_;
@@ -84,34 +119,8 @@ sub new {
119
120
::_req_svn();
121
87
- SVN::_Core::svn_config_ensure($config_dir, undef);
88
- my ($baton, $callbacks) = SVN::Core::auth_open_helper(_auth_providers);
89
- my $config = SVN::Core::config_get_config($config_dir);
122
$RA = undef;
91
- my $dont_store_passwords = 1;
92
- my $conf_t = ${$config}{'config'};
93
- {
94
- no warnings 'once';
95
- # The usage of $SVN::_Core::SVN_CONFIG_* variables
96
- # produces warnings that variables are used only once.
97
- # I had not found the better way to shut them up, so
98
- # the warnings of type 'once' are disabled in this block.
99
- if (SVN::_Core::svn_config_get_bool($conf_t,
100
- $SVN::_Core::SVN_CONFIG_SECTION_AUTH,
101
- $SVN::_Core::SVN_CONFIG_OPTION_STORE_PASSWORDS,
102
- 1) == 0) {
103
- SVN::_Core::svn_auth_set_parameter($baton,
104
- $SVN::_Core::SVN_AUTH_PARAM_DONT_STORE_PASSWORDS,
105
- bless (\$dont_store_passwords, "_p_void"));
106
- }
107
- if (SVN::_Core::svn_config_get_bool($conf_t,
108
- $SVN::_Core::SVN_CONFIG_SECTION_AUTH,
109
- $SVN::_Core::SVN_CONFIG_OPTION_STORE_AUTH_CREDS,
110
- 1) == 0) {
111
- $Git::SVN::Prompt::_no_auth_cache = 1;
112
- }
113
- } # no warnings 'once'
114
-
123
+ my ($config, $baton, $callbacks) = prepare_config_once();
124
my $self = SVN::Ra->new(url => $url, auth => $baton,
125
config => $config,
126
pool => SVN::Pool->new,