subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i...@apache.org
Subject svn commit: r1463902 - in /subversion/trunk/subversion/libsvn_repos: hooks.c repos.c repos.h
Date Wed, 03 Apr 2013 10:01:45 GMT
Author: ivan
Date: Wed Apr  3 10:01:45 2013
New Revision: 1463902

URL: http://svn.apache.org/r1463902
Log:
Read repository hooks environment file just before hook execution.

* subversion/libsvn_repos/repos.c
  (parse_hooks_env_option_baton, parse_hooks_env_option, 
   parse_hooks_env_section_baton, parse_hooks_env_section, parse_hooks_env):
   Move to subversion/libsvn_repos/hooks.c.
  (svn_repos_hooks_setenv): Just save new hooks enviroment file path without
   reading file.
  (create_svn_repos_t): Initialize hooks_env_path to NULL.

* subversion/libsvn_repos/hooks.c
  (): Include "svn_config.h"
  (parse_hooks_env_option_baton, parse_hooks_env_option, 
   parse_hooks_env_section_baton, parse_hooks_env_section, 
   parse_hooks_env): Moved from subversion/libsvn_repos/repos.c.
  (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): Read hooks environment file and pass it 
   run_hook_cmd().

* subversion/libsvn_repos/repos.h
  (svn_repos_t): Add HOOKS_ENV_PATH and remove HOOKS_ENV.

Modified:
    subversion/trunk/subversion/libsvn_repos/hooks.c
    subversion/trunk/subversion/libsvn_repos/repos.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=1463902&r1=1463901&r2=1463902&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_repos/hooks.c (original)
+++ subversion/trunk/subversion/libsvn_repos/hooks.c Wed Apr  3 10:01:45 2013
@@ -27,6 +27,7 @@
 #include <apr_pools.h>
 #include <apr_file_io.h>
 
+#include "svn_config.h"
 #include "svn_hash.h"
 #include "svn_error.h"
 #include "svn_dirent_uri.h"
@@ -355,6 +356,87 @@ check_hook_cmd(const char *hook, svn_boo
   return NULL;
 }
 
+/* Baton for parse_hooks_env_option. */
+struct parse_hooks_env_option_baton {
+  /* The name of the section being parsed. If not the default section,
+   * the section name should match the name of a hook to which the
+   * options apply. */
+  const char *section;
+  apr_hash_t *hooks_env;
+} parse_hooks_env_option_baton;
+
+/* An implementation of svn_config_enumerator2_t.
+ * Set environment variable NAME to value VALUE in the environment for
+ * all hooks (in case the current section is the default section),
+ * or the hook with the name corresponding to the current section's name. */
+static svn_boolean_t
+parse_hooks_env_option(const char *name, const char *value,
+                       void *baton, apr_pool_t *pool)
+{
+  struct parse_hooks_env_option_baton *bo = baton;
+  apr_pool_t *result_pool = apr_hash_pool_get(bo->hooks_env);
+  apr_hash_t *hook_env;
+  
+  hook_env = svn_hash_gets(bo->hooks_env, bo->section);
+  if (hook_env == NULL)
+    {
+      hook_env = apr_hash_make(result_pool);
+      svn_hash_sets(bo->hooks_env, apr_pstrdup(result_pool, bo->section),
+                    hook_env);
+    }
+  svn_hash_sets(hook_env, apr_pstrdup(result_pool, name),
+                apr_pstrdup(result_pool, value));
+
+  return TRUE;
+}
+
+struct parse_hooks_env_section_baton {
+  svn_config_t *cfg;
+  apr_hash_t *hooks_env;
+} parse_hooks_env_section_baton;
+
+/* An implementation of svn_config_section_enumerator2_t. */
+static svn_boolean_t
+parse_hooks_env_section(const char *name, void *baton, apr_pool_t *pool)
+{
+  struct parse_hooks_env_section_baton *b = baton;
+  struct parse_hooks_env_option_baton bo;
+
+  bo.section = name;
+  bo.hooks_env = b->hooks_env;
+
+  (void)svn_config_enumerate2(b->cfg, name, parse_hooks_env_option, &bo, pool);
+
+  return TRUE;
+}
+
+/* Parse the hooks env file for this repository. */
+static svn_error_t *
+parse_hooks_env(apr_hash_t **hooks_env_p,
+                const char *local_abspath,
+                apr_pool_t *result_pool,
+                apr_pool_t *scratch_pool)
+{
+  svn_config_t *cfg;
+  int n;
+  struct parse_hooks_env_section_baton b;
+
+  if (local_abspath)
+    {
+      SVN_ERR(svn_config_read2(&cfg, local_abspath, FALSE, TRUE, scratch_pool));
+      b.cfg = cfg;
+      b.hooks_env = apr_hash_make(result_pool);
+      n = svn_config_enumerate_sections2(cfg, parse_hooks_env_section, &b,
+                                         scratch_pool);
+      *hooks_env_p = b.hooks_env;
+    }
+  else
+    {
+      *hooks_env_p = NULL;
+    }
+
+  return SVN_NO_ERROR;
+}
 
 /* Return an error for the failure of HOOK due to a broken symlink. */
 static svn_error_t *
@@ -383,6 +465,7 @@ svn_repos__hooks_start_commit(svn_repos_
     {
       const char *args[6];
       char *capabilities_string;
+      apr_hash_t *hooks_env;
 
       if (capabilities)
         {
@@ -397,6 +480,8 @@ 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));
+
       args[0] = hook;
       args[1] = svn_dirent_local_style(svn_repos_path(repos, pool), pool);
       args[2] = user ? user : "";
@@ -405,7 +490,7 @@ svn_repos__hooks_start_commit(svn_repos_
       args[5] = NULL;
 
       SVN_ERR(run_hook_cmd(NULL, SVN_REPOS__HOOK_START_COMMIT, hook, args,
-                           repos->hooks_env, NULL, pool));
+                           hooks_env, NULL, pool));
     }
 
   return SVN_NO_ERROR;
@@ -464,6 +549,7 @@ svn_repos__hooks_pre_commit(svn_repos_t 
       const char *args[4];
       svn_fs_access_t *access_ctx;
       apr_file_t *stdin_handle = NULL;
+      apr_hash_t *hooks_env;
 
       args[0] = hook;
       args[1] = svn_dirent_local_style(svn_repos_path(repos, pool), pool);
@@ -483,8 +569,10 @@ 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(run_hook_cmd(NULL, SVN_REPOS__HOOK_PRE_COMMIT, hook, args,
-                           repos->hooks_env, stdin_handle, pool));
+                           hooks_env, stdin_handle, pool));
     }
 
   return SVN_NO_ERROR;
@@ -507,6 +595,9 @@ svn_repos__hooks_post_commit(svn_repos_t
   else if (hook)
     {
       const char *args[5];
+      apr_hash_t *hooks_env;
+
+      SVN_ERR(parse_hooks_env(&hooks_env, repos->hooks_env_path, pool, pool));
 
       args[0] = hook;
       args[1] = svn_dirent_local_style(svn_repos_path(repos, pool), pool);
@@ -515,7 +606,7 @@ svn_repos__hooks_post_commit(svn_repos_t
       args[4] = NULL;
 
       SVN_ERR(run_hook_cmd(NULL, SVN_REPOS__HOOK_POST_COMMIT, hook, args,
-                           repos->hooks_env, NULL, pool));
+                           hooks_env, NULL, pool));
     }
 
   return SVN_NO_ERROR;
@@ -543,6 +634,7 @@ svn_repos__hooks_pre_revprop_change(svn_
       const char *args[7];
       apr_file_t *stdin_handle = NULL;
       char action_string[2];
+      apr_hash_t *hooks_env;
 
       /* Pass the new value as stdin to hook */
       if (new_value)
@@ -551,6 +643,8 @@ 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));
+
       action_string[0] = action;
       action_string[1] = '\0';
 
@@ -563,7 +657,7 @@ svn_repos__hooks_pre_revprop_change(svn_
       args[6] = NULL;
 
       SVN_ERR(run_hook_cmd(NULL, SVN_REPOS__HOOK_PRE_REVPROP_CHANGE, hook,
-                           args, repos->hooks_env, stdin_handle, pool));
+                           args, hooks_env, stdin_handle, pool));
 
       SVN_ERR(svn_io_file_close(stdin_handle, pool));
     }
@@ -605,6 +699,7 @@ svn_repos__hooks_post_revprop_change(svn
       const char *args[7];
       apr_file_t *stdin_handle = NULL;
       char action_string[2];
+      apr_hash_t *hooks_env;
 
       /* Pass the old value as stdin to hook */
       if (old_value)
@@ -613,6 +708,8 @@ 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));
+
       action_string[0] = action;
       action_string[1] = '\0';
 
@@ -625,7 +722,7 @@ svn_repos__hooks_post_revprop_change(svn
       args[6] = NULL;
 
       SVN_ERR(run_hook_cmd(NULL, SVN_REPOS__HOOK_POST_REVPROP_CHANGE, hook,
-                           args, repos->hooks_env, stdin_handle, pool));
+                           args, hooks_env, stdin_handle, pool));
 
       SVN_ERR(svn_io_file_close(stdin_handle, pool));
     }
@@ -654,6 +751,9 @@ svn_repos__hooks_pre_lock(svn_repos_t *r
     {
       const char *args[7];
       svn_string_t *buf;
+      apr_hash_t *hooks_env;
+
+      SVN_ERR(parse_hooks_env(&hooks_env, repos->hooks_env_path, pool, pool));
 
       args[0] = hook;
       args[1] = svn_dirent_local_style(svn_repos_path(repos, pool), pool);
@@ -664,7 +764,7 @@ svn_repos__hooks_pre_lock(svn_repos_t *r
       args[6] = NULL;
 
       SVN_ERR(run_hook_cmd(&buf, SVN_REPOS__HOOK_PRE_LOCK, hook, args,
-                           repos->hooks_env, NULL, pool));
+                           hooks_env, NULL, pool));
 
       if (token)
         /* No validation here; the FS will take care of that. */
@@ -695,12 +795,15 @@ svn_repos__hooks_post_lock(svn_repos_t *
     {
       const char *args[5];
       apr_file_t *stdin_handle = NULL;
+      apr_hash_t *hooks_env;
       svn_string_t *paths_str = svn_string_create(svn_cstring_join
                                                   (paths, "\n", pool),
                                                   pool);
 
       SVN_ERR(create_temp_file(&stdin_handle, paths_str, pool));
 
+      SVN_ERR(parse_hooks_env(&hooks_env, repos->hooks_env_path, pool, pool));
+
       args[0] = hook;
       args[1] = svn_dirent_local_style(svn_repos_path(repos, pool), pool);
       args[2] = username;
@@ -708,7 +811,7 @@ svn_repos__hooks_post_lock(svn_repos_t *
       args[4] = NULL;
 
       SVN_ERR(run_hook_cmd(NULL, SVN_REPOS__HOOK_POST_LOCK, hook, args,
-                           repos->hooks_env, stdin_handle, pool));
+                           hooks_env, stdin_handle, pool));
 
       SVN_ERR(svn_io_file_close(stdin_handle, pool));
     }
@@ -735,6 +838,9 @@ svn_repos__hooks_pre_unlock(svn_repos_t 
   else if (hook)
     {
       const char *args[7];
+      apr_hash_t *hooks_env;
+
+      SVN_ERR(parse_hooks_env(&hooks_env, repos->hooks_env_path, pool, pool));
 
       args[0] = hook;
       args[1] = svn_dirent_local_style(svn_repos_path(repos, pool), pool);
@@ -745,7 +851,7 @@ svn_repos__hooks_pre_unlock(svn_repos_t 
       args[6] = NULL;
 
       SVN_ERR(run_hook_cmd(NULL, SVN_REPOS__HOOK_PRE_UNLOCK, hook, args,
-                           repos->hooks_env, NULL, pool));
+                           hooks_env, NULL, pool));
     }
 
   return SVN_NO_ERROR;
@@ -769,12 +875,15 @@ svn_repos__hooks_post_unlock(svn_repos_t
     {
       const char *args[5];
       apr_file_t *stdin_handle = NULL;
+      apr_hash_t *hooks_env;
       svn_string_t *paths_str = svn_string_create(svn_cstring_join
                                                   (paths, "\n", pool),
                                                   pool);
 
       SVN_ERR(create_temp_file(&stdin_handle, paths_str, pool));
 
+      SVN_ERR(parse_hooks_env(&hooks_env, repos->hooks_env_path, pool, pool));
+
       args[0] = hook;
       args[1] = svn_dirent_local_style(svn_repos_path(repos, pool), pool);
       args[2] = username ? username : "";
@@ -782,7 +891,7 @@ svn_repos__hooks_post_unlock(svn_repos_t
       args[4] = NULL;
 
       SVN_ERR(run_hook_cmd(NULL, SVN_REPOS__HOOK_POST_UNLOCK, hook, args,
-                           repos->hooks_env, stdin_handle, pool));
+                           hooks_env, stdin_handle, pool));
 
       SVN_ERR(svn_io_file_close(stdin_handle, pool));
     }

Modified: subversion/trunk/subversion/libsvn_repos/repos.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_repos/repos.c?rev=1463902&r1=1463901&r2=1463902&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_repos/repos.c (original)
+++ subversion/trunk/subversion/libsvn_repos/repos.c Wed Apr  3 10:01:45 2013
@@ -1164,82 +1164,6 @@ create_conf(svn_repos_t *repos, apr_pool
   return SVN_NO_ERROR;
 }
 
-/* Baton for parse_hooks_env_option. */
-struct parse_hooks_env_option_baton {
-  /* The name of the section being parsed. If not the default section,
-   * the section name should match the name of a hook to which the
-   * options apply. */
-  const char *section;
-  apr_hash_t *hooks_env;
-} parse_hooks_env_option_baton;
-
-/* An implementation of svn_config_enumerator2_t.
- * Set environment variable NAME to value VALUE in the environment for
- * all hooks (in case the current section is the default section),
- * or the hook with the name corresponding to the current section's name. */
-static svn_boolean_t
-parse_hooks_env_option(const char *name, const char *value,
-                       void *baton, apr_pool_t *pool)
-{
-  struct parse_hooks_env_option_baton *bo = baton;
-  apr_pool_t *result_pool = apr_hash_pool_get(bo->hooks_env);
-  apr_hash_t *hook_env;
-  
-  hook_env = svn_hash_gets(bo->hooks_env, bo->section);
-  if (hook_env == NULL)
-    {
-      hook_env = apr_hash_make(result_pool);
-      svn_hash_sets(bo->hooks_env, apr_pstrdup(result_pool, bo->section),
-                    hook_env);
-    }
-  svn_hash_sets(hook_env, apr_pstrdup(result_pool, name),
-                apr_pstrdup(result_pool, value));
-
-  return TRUE;
-}
-
-struct parse_hooks_env_section_baton {
-  svn_config_t *cfg;
-  apr_hash_t *hooks_env;
-} parse_hooks_env_section_baton;
-
-/* An implementation of svn_config_section_enumerator2_t. */
-static svn_boolean_t
-parse_hooks_env_section(const char *name, void *baton, apr_pool_t *pool)
-{
-  struct parse_hooks_env_section_baton *b = baton;
-  struct parse_hooks_env_option_baton bo;
-
-  bo.section = name;
-  bo.hooks_env = b->hooks_env;
-
-  (void)svn_config_enumerate2(b->cfg, name, parse_hooks_env_option, &bo, pool);
-
-  return TRUE;
-}
-
-/* Parse the hooks env file for this repository. */
-static svn_error_t *
-parse_hooks_env(svn_repos_t *repos,
-                const char *local_abspath,
-                apr_pool_t *result_pool,
-                apr_pool_t *scratch_pool)
-{
-  svn_config_t *cfg;
-  int n;
-  struct parse_hooks_env_section_baton b;
-
-  SVN_ERR(svn_config_read2(&cfg, local_abspath, FALSE, TRUE, scratch_pool));
-  b.cfg = cfg;
-  b.hooks_env = apr_hash_make(result_pool);
-  n = svn_config_enumerate_sections2(cfg, parse_hooks_env_section, &b,
-                                     scratch_pool);
-  if (n > 0)
-    repos->hooks_env = b.hooks_env;
-
-  return SVN_NO_ERROR;
-}
-
 svn_error_t *
 svn_repos_hooks_setenv(svn_repos_t *repos,
                        const char *hooks_env_path,
@@ -1247,13 +1171,11 @@ svn_repos_hooks_setenv(svn_repos_t *repo
                        apr_pool_t *scratch_pool)
 {
   if (hooks_env_path == NULL)
-    hooks_env_path = svn_dirent_join(repos->conf_path,
-                                     SVN_REPOS__CONF_HOOKS_ENV, scratch_pool);
+    repos->hooks_env_path = svn_dirent_join(repos->conf_path,
+                                            SVN_REPOS__CONF_HOOKS_ENV, result_pool);
   else if (!svn_dirent_is_absolute(hooks_env_path))
-    hooks_env_path = svn_dirent_join(repos->conf_path, hooks_env_path,
-                                     scratch_pool);
-
-  SVN_ERR(parse_hooks_env(repos, hooks_env_path, result_pool, scratch_pool));
+    repos->hooks_env_path = svn_dirent_join(repos->conf_path, hooks_env_path,
+                                            result_pool);
 
   return SVN_NO_ERROR;
 }
@@ -1273,8 +1195,8 @@ create_svn_repos_t(const char *path, apr
   repos->conf_path = svn_dirent_join(path, SVN_REPOS__CONF_DIR, pool);
   repos->hook_path = svn_dirent_join(path, SVN_REPOS__HOOK_DIR, pool);
   repos->lock_path = svn_dirent_join(path, SVN_REPOS__LOCK_DIR, pool);
+  repos->hooks_env_path = NULL;
   repos->repository_capabilities = apr_hash_make(pool);
-  repos->hooks_env = NULL;
 
   return repos;
 }

Modified: subversion/trunk/subversion/libsvn_repos/repos.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_repos/repos.h?rev=1463902&r1=1463901&r2=1463902&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_repos/repos.h (original)
+++ subversion/trunk/subversion/libsvn_repos/repos.h Wed Apr  3 10:01:45 2013
@@ -126,6 +126,10 @@ struct svn_repos_t
   /* The format number of this repository. */
   int format;
 
+  /* The path to the repository's hooks enviroment file. If NULL, hooks run
+   * in an empty environment. */
+  const char *hooks_env_path;
+
   /* The FS backend in use within this repository. */
   const char *fs_type;
 
@@ -146,18 +150,6 @@ struct svn_repos_t
      sufficiently well-informed internal code may just compare against
      those constants' addresses, therefore). */
   apr_hash_t *repository_capabilities;
-
-  /* The environment inherited to hook scripts. If NULL, hooks run
-   * in an empty environment.
-   *
-   * This is a nested hash table.
-   * The entry with name SVN_REPOS__HOOKS_ENV_DEFAULT_SECTION contains the
-   * default environment for all hooks in form of an apr_hash_t with keys
-   * and values describing the names and values of environment variables.
-   * Defaults can be overridden by an entry matching the name of a hook.
-   * E.g. an entry with the name SVN_REPOS__HOOK_PRE_COMMIT provides the
-   * environment specific to the pre-commit hook. */
-  apr_hash_t *hooks_env;
 };
 
 



Mime
View raw message