subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmpil...@apache.org
Subject svn commit: r1464079 - in /subversion/trunk/subversion/libsvn_repos: hooks.c repos.h
Date Wed, 03 Apr 2013 15:43:10 GMT
Author: cmpilato
Date: Wed Apr  3 15:43:09 2013
New Revision: 1464079

URL: http://svn.apache.org/r1464079
Log:
Avoid parsing the hooks-env file with every hook invocation by caching
the results of the first such parsing in the svn_repos_t.

* subversion/libsvn_repos/repos.h
  (svn_repos_t): Add 'hooks_env' member.

* subversion/libsvn_repos/hooks.c
  (parse_hooks_env): Lose 'result_pool' and 'local_abspath'
    parameters; add 'repos'.  Now consult/populate a cache of this
    hooks-env data found in the svn_repos_t object.
  (svn_repos__hooks_start_commit,
   svn_repos__hooks_pre_commit,
   svn_repos__hooks_post_commit,
   svn_repos__hooks_pre_revprop_change,
   svn_repos__hooks_post_revprop_change,
   svn_repos__hooks_pre_lock,
   svn_repos__hooks_post_lock,
   svn_repos__hooks_pre_unlock,
   svn_repos__hooks_post_unlock): Update calls to parse_hooks_env().

Modified:
    subversion/trunk/subversion/libsvn_repos/hooks.c
    subversion/trunk/subversion/libsvn_repos/repos.h

Modified: subversion/trunk/subversion/libsvn_repos/hooks.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_repos/hooks.c?rev=1464079&r1=1464078&r2=1464079&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_repos/hooks.c (original)
+++ subversion/trunk/subversion/libsvn_repos/hooks.c Wed Apr  3 15:43:09 2013
@@ -410,30 +410,40 @@ parse_hooks_env_section(const char *name
   return TRUE;
 }
 
-/* Parse the hooks env file for this repository. */
+/* Set *HOOKS_ENV_P to the cached hash-form of the parsed hook-env
+   file for REPOS.  (If that information has not yet been cached, then
+   parse the file, cache the results, and *then* return them.)  */
 static svn_error_t *
 parse_hooks_env(apr_hash_t **hooks_env_p,
-                const char *local_abspath,
-                apr_pool_t *result_pool,
+                svn_repos_t *repos,
                 apr_pool_t *scratch_pool)
 {
   svn_config_t *cfg;
   struct parse_hooks_env_section_baton b;
 
-  if (local_abspath)
+  /* Easy out: we've already parsed the sucker! */
+  if (repos->hooks_env)
     {
-      SVN_ERR(svn_config_read2(&cfg, local_abspath, FALSE, TRUE, scratch_pool));
-      b.cfg = cfg;
-      b.hooks_env = apr_hash_make(result_pool);
-      svn_config_enumerate_sections2(cfg, parse_hooks_env_section, &b,
-                                     scratch_pool);
-      *hooks_env_p = b.hooks_env;
+      *hooks_env_p = repos->hooks_env;
+      return SVN_NO_ERROR;
     }
-  else
+
+  /* Easy out: no path to parse. */
+  if (! repos->hooks_env_path)
     {
       *hooks_env_p = NULL;
+      return SVN_NO_ERROR;
     }
 
+  /* Okay, parse the file, then cache and return the results. */
+  SVN_ERR(svn_config_read2(&cfg, repos->hooks_env_path,
+                           FALSE, TRUE, scratch_pool));
+  b.cfg = cfg;
+  b.hooks_env = apr_hash_make(repos->pool);
+  svn_config_enumerate_sections2(cfg, parse_hooks_env_section,
+                                 &b, scratch_pool);
+  *hooks_env_p = repos->hooks_env = b.hooks_env;
+
   return SVN_NO_ERROR;
 }
 
@@ -479,7 +489,7 @@ svn_repos__hooks_start_commit(svn_repos_
           capabilities_string = apr_pstrdup(pool, "");
         }
 
-      SVN_ERR(parse_hooks_env(&hooks_env, repos->hooks_env_path, pool, pool));
+      SVN_ERR(parse_hooks_env(&hooks_env, repos, pool));
 
       args[0] = hook;
       args[1] = svn_dirent_local_style(svn_repos_path(repos, pool), pool);
@@ -568,7 +578,7 @@ svn_repos__hooks_pre_commit(svn_repos_t 
         SVN_ERR(svn_io_file_open(&stdin_handle, SVN_NULL_DEVICE_NAME,
                                  APR_READ, APR_OS_DEFAULT, pool));
 
-      SVN_ERR(parse_hooks_env(&hooks_env, repos->hooks_env_path, pool, pool));
+      SVN_ERR(parse_hooks_env(&hooks_env, repos, pool));
 
       SVN_ERR(run_hook_cmd(NULL, SVN_REPOS__HOOK_PRE_COMMIT, hook, args,
                            hooks_env, stdin_handle, pool));
@@ -596,7 +606,7 @@ svn_repos__hooks_post_commit(svn_repos_t
       const char *args[5];
       apr_hash_t *hooks_env;
 
-      SVN_ERR(parse_hooks_env(&hooks_env, repos->hooks_env_path, pool, pool));
+      SVN_ERR(parse_hooks_env(&hooks_env, repos, pool));
 
       args[0] = hook;
       args[1] = svn_dirent_local_style(svn_repos_path(repos, pool), pool);
@@ -642,7 +652,7 @@ svn_repos__hooks_pre_revprop_change(svn_
         SVN_ERR(svn_io_file_open(&stdin_handle, SVN_NULL_DEVICE_NAME,
                                  APR_READ, APR_OS_DEFAULT, pool));
 
-      SVN_ERR(parse_hooks_env(&hooks_env, repos->hooks_env_path, pool, pool));
+      SVN_ERR(parse_hooks_env(&hooks_env, repos, pool));
 
       action_string[0] = action;
       action_string[1] = '\0';
@@ -707,7 +717,7 @@ svn_repos__hooks_post_revprop_change(svn
         SVN_ERR(svn_io_file_open(&stdin_handle, SVN_NULL_DEVICE_NAME,
                                  APR_READ, APR_OS_DEFAULT, pool));
 
-      SVN_ERR(parse_hooks_env(&hooks_env, repos->hooks_env_path, pool, pool));
+      SVN_ERR(parse_hooks_env(&hooks_env, repos, pool));
 
       action_string[0] = action;
       action_string[1] = '\0';
@@ -752,7 +762,7 @@ svn_repos__hooks_pre_lock(svn_repos_t *r
       svn_string_t *buf;
       apr_hash_t *hooks_env;
 
-      SVN_ERR(parse_hooks_env(&hooks_env, repos->hooks_env_path, pool, pool));
+      SVN_ERR(parse_hooks_env(&hooks_env, repos, pool));
 
       args[0] = hook;
       args[1] = svn_dirent_local_style(svn_repos_path(repos, pool), pool);
@@ -801,7 +811,7 @@ svn_repos__hooks_post_lock(svn_repos_t *
 
       SVN_ERR(create_temp_file(&stdin_handle, paths_str, pool));
 
-      SVN_ERR(parse_hooks_env(&hooks_env, repos->hooks_env_path, pool, pool));
+      SVN_ERR(parse_hooks_env(&hooks_env, repos, pool));
 
       args[0] = hook;
       args[1] = svn_dirent_local_style(svn_repos_path(repos, pool), pool);
@@ -839,7 +849,7 @@ svn_repos__hooks_pre_unlock(svn_repos_t 
       const char *args[7];
       apr_hash_t *hooks_env;
 
-      SVN_ERR(parse_hooks_env(&hooks_env, repos->hooks_env_path, pool, pool));
+      SVN_ERR(parse_hooks_env(&hooks_env, repos, pool));
 
       args[0] = hook;
       args[1] = svn_dirent_local_style(svn_repos_path(repos, pool), pool);
@@ -881,7 +891,7 @@ svn_repos__hooks_post_unlock(svn_repos_t
 
       SVN_ERR(create_temp_file(&stdin_handle, paths_str, pool));
 
-      SVN_ERR(parse_hooks_env(&hooks_env, repos->hooks_env_path, pool, pool));
+      SVN_ERR(parse_hooks_env(&hooks_env, repos, pool));
 
       args[0] = hook;
       args[1] = svn_dirent_local_style(svn_repos_path(repos, pool), pool);

Modified: subversion/trunk/subversion/libsvn_repos/repos.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_repos/repos.h?rev=1464079&r1=1464078&r2=1464079&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_repos/repos.h (original)
+++ subversion/trunk/subversion/libsvn_repos/repos.h Wed Apr  3 15:43:09 2013
@@ -151,6 +151,10 @@ struct svn_repos_t
      those constants' addresses, therefore). */
   apr_hash_t *repository_capabilities;
 
+  /* Parsed form of the 'hooks-env' configuration file (NULL if not
+     yet parsed). */
+  apr_hash_t *hooks_env;
+
   /* Pool from which this structure was allocated.  Also used for
      auxiliary repository-related data that requires a matching
      lifespan.  (As the svn_repos_t structure tends to be relatively



Mime
View raw message