{"thread":{"id":"37837","subject":"[PATCH] git-svn: prepare SVN::Ra config pieces once","startedAt":"2014-10-29T19:55:02Z","lastAt":"2014-10-29T19:55:02Z","messageCount":1,"participants":["Eric Wong"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"251194","messageId":"20141029195502.GA5729@dcvr.yhbt.net","threadId":"37837","inReplyTo":null,"subject":"[PATCH] git-svn: prepare SVN::Ra config pieces once","fromName":"Eric Wong","fromEmail":"normalperson@yhbt.net","sentAt":"2014-10-29T19:55:02Z","receivedAt":"2014-10-29T19:55:02Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"Memoizing these initialization functions saves some memory for\nlong fetches which require scanning many unwanted revisions\nbefore any wanted revisions happen.\n\nSigned-off-by: Eric Wong <normalperson@yhbt.net>\n---\n perl/Git/SVN/Ra.pm | 63 +++++++++++++++++++++++++++++++-----------------------\n 1 file changed, 36 insertions(+), 27 deletions(-)\n\ndiff --git a/perl/Git/SVN/Ra.pm b/perl/Git/SVN/Ra.pm\nindex 5bc5b4e..75cdac9 100644\n--- a/perl/Git/SVN/Ra.pm\n+++ b/perl/Git/SVN/Ra.pm\n@@ -2,6 +2,7 @@ package Git::SVN::Ra;\n use vars qw/@ISA $config_dir $_ignore_refs_regex $_log_window_size/;\n use strict;\n use warnings;\n+use Memoize;\n use SVN::Client;\n use Git::SVN::Utils qw(\n \tcanonicalize_url\n@@ -76,6 +77,40 @@ sub _auth_providers () {\n \t\\@rv;\n }\n \n+sub prepare_config_once {\n+\tSVN::_Core::svn_config_ensure($config_dir, undef);\n+\tmy ($baton, $callbacks) = SVN::Core::auth_open_helper(_auth_providers);\n+\tmy $config = SVN::Core::config_get_config($config_dir);\n+\tmy $dont_store_passwords = 1;\n+\tmy $conf_t = $config->{'config'};\n+\n+\tno warnings 'once';\n+\t# The usage of $SVN::_Core::SVN_CONFIG_* variables\n+\t# produces warnings that variables are used only once.\n+\t# I had not found the better way to shut them up, so\n+\t# the warnings of type 'once' are disabled in this block.\n+\tif (SVN::_Core::svn_config_get_bool($conf_t,\n+\t    $SVN::_Core::SVN_CONFIG_SECTION_AUTH,\n+\t    $SVN::_Core::SVN_CONFIG_OPTION_STORE_PASSWORDS,\n+\t    1) == 0) {\n+\t\tSVN::_Core::svn_auth_set_parameter($baton,\n+\t\t    $SVN::_Core::SVN_AUTH_PARAM_DONT_STORE_PASSWORDS,\n+\t\t    bless (\\$dont_store_passwords, \"_p_void\"));\n+\t}\n+\tif (SVN::_Core::svn_config_get_bool($conf_t,\n+\t    $SVN::_Core::SVN_CONFIG_SECTION_AUTH,\n+\t    $SVN::_Core::SVN_CONFIG_OPTION_STORE_AUTH_CREDS,\n+\t    1) == 0) {\n+\t\t$Git::SVN::Prompt::_no_auth_cache = 1;\n+\t}\n+\n+\treturn ($config, $baton, $callbacks);\n+} # no warnings 'once'\n+\n+INIT {\n+\tMemoize::memoize '_auth_providers';\n+\tMemoize::memoize 'prepare_config_once';\n+}\n \n sub new {\n \tmy ($class, $url) = @_;\n@@ -84,34 +119,8 @@ sub new {\n \n \t::_req_svn();\n \n-\tSVN::_Core::svn_config_ensure($config_dir, undef);\n-\tmy ($baton, $callbacks) = SVN::Core::auth_open_helper(_auth_providers);\n-\tmy $config = SVN::Core::config_get_config($config_dir);\n \t$RA = undef;\n-\tmy $dont_store_passwords = 1;\n-\tmy $conf_t = ${$config}{'config'};\n-\t{\n-\t\tno warnings 'once';\n-\t\t# The usage of $SVN::_Core::SVN_CONFIG_* variables\n-\t\t# produces warnings that variables are used only once.\n-\t\t# I had not found the better way to shut them up, so\n-\t\t# the warnings of type 'once' are disabled in this block.\n-\t\tif (SVN::_Core::svn_config_get_bool($conf_t,\n-\t\t    $SVN::_Core::SVN_CONFIG_SECTION_AUTH,\n-\t\t    $SVN::_Core::SVN_CONFIG_OPTION_STORE_PASSWORDS,\n-\t\t    1) == 0) {\n-\t\t\tSVN::_Core::svn_auth_set_parameter($baton,\n-\t\t\t    $SVN::_Core::SVN_AUTH_PARAM_DONT_STORE_PASSWORDS,\n-\t\t\t    bless (\\$dont_store_passwords, \"_p_void\"));\n-\t\t}\n-\t\tif (SVN::_Core::svn_config_get_bool($conf_t,\n-\t\t    $SVN::_Core::SVN_CONFIG_SECTION_AUTH,\n-\t\t    $SVN::_Core::SVN_CONFIG_OPTION_STORE_AUTH_CREDS,\n-\t\t    1) == 0) {\n-\t\t\t$Git::SVN::Prompt::_no_auth_cache = 1;\n-\t\t}\n-\t} # no warnings 'once'\n-\n+\tmy ($config, $baton, $callbacks) = prepare_config_once();\n \tmy $self = SVN::Ra->new(url => $url, auth => $baton,\n \t                      config => $config,\n \t\t\t      pool => SVN::Pool->new,\n-- \nEW\n"}]}