Author: stsp Date: Thu Feb 2 23:29:11 2012 New Revision: 1239926 URL: http://svn.apache.org/viewvc?rev=1239926&view=rev Log: Add a public libsvn_repos API to set the environment of hook scripts.
The default environment of hooks is still empty. Users of libsvn_repos may optionally call svn_repos_hooks_setenv() to configure an environment that all hooks will run in. Nothing does so yet so this commit makes no functional change. * subversion/libsvn_repos/repos.h (svn_repos_t): Add new hooks_env field. * subversion/include/svn_repos.h (svn_repos_hooks_setenv): Declare. * subversion/libsvn_repos/repos.c (svn_repos_hooks_setenv): New. * subversion/libsvn_repos/hooks.c (run_hook_cmd): New parameter hooks_env. Use svn_io_start_cmd3() to run hooks. It supports passing an environment to the child process. (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): Pass the repository's hooks environment to run_hook_cmd(). Modified: subversion/trunk/subversion/include/svn_repos.h 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/include/svn_repos.h URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_repos.h?rev=1239926&r1=1239925&r2=1239926&view=diff ============================================================================== --- subversion/trunk/subversion/include/svn_repos.h (original) +++ subversion/trunk/subversion/include/svn_repos.h Thu Feb 2 23:29:11 2012 @@ -764,6 +764,13 @@ const char * svn_repos_post_unlock_hook(svn_repos_t *repos, apr_pool_t *pool); +/** Set the environment that @ repos's hooks will inherit. + * If this function is not called, hooks will run in an empty environment. + * @since New in 1.8. */ +void +svn_repos_hooks_setenv(svn_repos_t *repos, + const char *const *hooks_env); + /** @} */ /* ---------------------------------------------------------------*/ Modified: subversion/trunk/subversion/libsvn_repos/hooks.c URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_repos/hooks.c?rev=1239926&r1=1239925&r2=1239926&view=diff ============================================================================== --- subversion/trunk/subversion/libsvn_repos/hooks.c (original) +++ subversion/trunk/subversion/libsvn_repos/hooks.c Thu Feb 2 23:29:11 2012 @@ -174,6 +174,7 @@ run_hook_cmd(svn_string_t **result, const char *name, const char *cmd, const char **args, + const char *const *hooks_env, apr_file_t *stdin_handle, apr_pool_t *pool) { @@ -196,7 +197,7 @@ run_hook_cmd(svn_string_t **result, (apr_err, _("Can't create null stdout for hook '%s'"), cmd); } - err = svn_io_start_cmd2(&cmd_proc, ".", cmd, args, FALSE, + err = svn_io_start_cmd3(&cmd_proc, ".", cmd, args, hooks_env, FALSE, FALSE, stdin_handle, result != NULL, null_handle, TRUE, NULL, pool); @@ -358,8 +359,8 @@ svn_repos__hooks_start_commit(svn_repos_ args[3] = capabilities_string; args[4] = NULL; - SVN_ERR(run_hook_cmd(NULL, SVN_REPOS__HOOK_START_COMMIT, hook, args, NULL, - pool)); + SVN_ERR(run_hook_cmd(NULL, SVN_REPOS__HOOK_START_COMMIT, hook, args, + repos->hooks_env, NULL, pool)); } return SVN_NO_ERROR; @@ -438,7 +439,7 @@ svn_repos__hooks_pre_commit(svn_repos_t APR_READ, APR_OS_DEFAULT, pool)); SVN_ERR(run_hook_cmd(NULL, SVN_REPOS__HOOK_PRE_COMMIT, hook, args, - stdin_handle, pool)); + repos->hooks_env, stdin_handle, pool)); } return SVN_NO_ERROR; @@ -466,8 +467,8 @@ svn_repos__hooks_post_commit(svn_repos_t args[2] = apr_psprintf(pool, "%ld", rev); args[3] = NULL; - SVN_ERR(run_hook_cmd(NULL, SVN_REPOS__HOOK_POST_COMMIT, hook, args, NULL, - pool)); + SVN_ERR(run_hook_cmd(NULL, SVN_REPOS__HOOK_POST_COMMIT, hook, args, + repos->hooks_env, NULL, pool)); } return SVN_NO_ERROR; @@ -514,8 +515,8 @@ svn_repos__hooks_pre_revprop_change(svn_ args[5] = action_string; args[6] = NULL; - SVN_ERR(run_hook_cmd(NULL, SVN_REPOS__HOOK_PRE_REVPROP_CHANGE, hook, args, - stdin_handle, pool)); + SVN_ERR(run_hook_cmd(NULL, SVN_REPOS__HOOK_PRE_REVPROP_CHANGE, hook, + args, repos->hooks_env, stdin_handle, pool)); SVN_ERR(svn_io_file_close(stdin_handle, pool)); } @@ -577,7 +578,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, stdin_handle, pool)); + args, repos->hooks_env, stdin_handle, pool)); SVN_ERR(svn_io_file_close(stdin_handle, pool)); } @@ -615,8 +616,8 @@ svn_repos__hooks_pre_lock(svn_repos_t *r args[5] = steal_lock ? "1" : "0"; args[6] = NULL; - SVN_ERR(run_hook_cmd(&buf, SVN_REPOS__HOOK_PRE_LOCK, hook, args, NULL, - pool)); + SVN_ERR(run_hook_cmd(&buf, SVN_REPOS__HOOK_PRE_LOCK, hook, args, + repos->hooks_env, NULL, pool)); if (token) /* No validation here; the FS will take care of that. */ @@ -660,7 +661,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, - stdin_handle, pool)); + repos->hooks_env, stdin_handle, pool)); SVN_ERR(svn_io_file_close(stdin_handle, pool)); } @@ -696,8 +697,8 @@ svn_repos__hooks_pre_unlock(svn_repos_t args[5] = break_lock ? "1" : "0"; args[6] = NULL; - SVN_ERR(run_hook_cmd(NULL, SVN_REPOS__HOOK_PRE_UNLOCK, hook, args, NULL, - pool)); + SVN_ERR(run_hook_cmd(NULL, SVN_REPOS__HOOK_PRE_UNLOCK, hook, args, + repos->hooks_env, NULL, pool)); } return SVN_NO_ERROR; @@ -734,7 +735,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, - stdin_handle, pool)); + repos->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=1239926&r1=1239925&r2=1239926&view=diff ============================================================================== --- subversion/trunk/subversion/libsvn_repos/repos.c (original) +++ subversion/trunk/subversion/libsvn_repos/repos.c Thu Feb 2 23:29:11 2012 @@ -165,6 +165,12 @@ svn_repos_post_revprop_change_hook(svn_r pool); } +void +svn_repos_hooks_setenv(svn_repos_t *repos, + const char *const *hooks_env) +{ + repos->hooks_env = hooks_env; +} static svn_error_t * create_repos_dir(const char *path, apr_pool_t *pool) Modified: subversion/trunk/subversion/libsvn_repos/repos.h URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_repos/repos.h?rev=1239926&r1=1239925&r2=1239926&view=diff ============================================================================== --- subversion/trunk/subversion/libsvn_repos/repos.h (original) +++ subversion/trunk/subversion/libsvn_repos/repos.h Thu Feb 2 23:29:11 2012 @@ -140,6 +140,10 @@ 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. */ + const char *const *hooks_env; };