📄 hooks.c
字号:
If the hook exists but is a broken symbolic link, set *BROKEN_LINK to TRUE, else if the hook program exists set *BROKEN_LINK to FALSE. Return the hook program if found, else return NULL and don't touch *BROKEN_LINK.*/static const char*check_hook_cmd(const char *hook, svn_boolean_t *broken_link, apr_pool_t *pool){ static const char* const check_extns[] = {#ifdef WIN32 /* For WIN32, we need to check with file name extension(s) added. As Windows Scripting Host (.wsf) files can accomodate (at least) JavaScript (.js) and VB Script (.vbs) code, extensions for the corresponding file types need not be enumerated explicitly. */ ".exe", ".cmd", ".bat", ".wsf", /* ### Any other extensions? */#else "",#endif NULL }; const char *const *extn; svn_error_t *err = NULL; svn_boolean_t is_special; for (extn = check_extns; *extn; ++extn) { const char *const hook_path = (**extn ? apr_pstrcat(pool, hook, *extn, 0) : hook); svn_node_kind_t kind; if (!(err = svn_io_check_resolved_path(hook_path, &kind, pool)) && kind == svn_node_file) { *broken_link = FALSE; return hook_path; } svn_error_clear(err); if (!(err = svn_io_check_special_path(hook_path, &kind, &is_special, pool)) && is_special == TRUE) { *broken_link = TRUE; return hook_path; } svn_error_clear(err); } return NULL;}/* Return an error for the failure of HOOK due to a broken symlink. */static svn_error_t *hook_symlink_error(const char *hook){ return svn_error_createf (SVN_ERR_REPOS_HOOK_FAILURE, NULL, _("Failed to run '%s' hook; broken symlink"), hook);}svn_error_t *svn_repos__hooks_start_commit(svn_repos_t *repos, const char *user, apr_pool_t *pool){ const char *hook = svn_repos_start_commit_hook(repos, pool); svn_boolean_t broken_link; if ((hook = check_hook_cmd(hook, &broken_link, pool)) && broken_link) { return hook_symlink_error(hook); } else if (hook) { const char *args[4]; args[0] = hook; args[1] = svn_repos_path(repos, pool); args[2] = user ? user : ""; args[3] = NULL; SVN_ERR(run_hook_cmd("start-commit", hook, args, TRUE, NULL, pool)); } return SVN_NO_ERROR;}svn_error_t *svn_repos__hooks_pre_commit(svn_repos_t *repos, const char *txn_name, apr_pool_t *pool){ const char *hook = svn_repos_pre_commit_hook(repos, pool); svn_boolean_t broken_link; if ((hook = check_hook_cmd(hook, &broken_link, pool)) && broken_link) { return hook_symlink_error(hook); } else if (hook) { const char *args[4]; args[0] = hook; args[1] = svn_repos_path(repos, pool); args[2] = txn_name; args[3] = NULL; SVN_ERR(run_hook_cmd("pre-commit", hook, args, TRUE, NULL, pool)); } return SVN_NO_ERROR;}svn_error_t *svn_repos__hooks_post_commit(svn_repos_t *repos, svn_revnum_t rev, apr_pool_t *pool){ const char *hook = svn_repos_post_commit_hook(repos, pool); svn_boolean_t broken_link; if ((hook = check_hook_cmd(hook, &broken_link, pool)) && broken_link) { return hook_symlink_error(hook); } else if (hook) { const char *args[4]; args[0] = hook; args[1] = svn_repos_path(repos, pool); args[2] = apr_psprintf(pool, "%ld", rev); args[3] = NULL; SVN_ERR(run_hook_cmd("post-commit", hook, args, TRUE, NULL, pool)); } return SVN_NO_ERROR;}svn_error_t *svn_repos__hooks_pre_revprop_change(svn_repos_t *repos, svn_revnum_t rev, const char *author, const char *name, const svn_string_t *new_value, char action, apr_pool_t *pool){ const char *hook = svn_repos_pre_revprop_change_hook(repos, pool); svn_boolean_t broken_link; if ((hook = check_hook_cmd(hook, &broken_link, pool)) && broken_link) { return hook_symlink_error(hook); } else if (hook) { const char *args[7]; apr_file_t *stdin_handle = NULL; char action_string[2]; /* Pass the new value as stdin to hook */ if (new_value) SVN_ERR(create_temp_file(&stdin_handle, new_value, pool)); else SVN_ERR(svn_io_file_open(&stdin_handle, SVN_NULL_DEVICE_NAME, APR_READ, APR_OS_DEFAULT, pool)); action_string[0] = action; action_string[1] = '\0'; args[0] = hook; args[1] = svn_repos_path(repos, pool); args[2] = apr_psprintf(pool, "%ld", rev); args[3] = author ? author : ""; args[4] = name; args[5] = action_string; args[6] = NULL; SVN_ERR(run_hook_cmd("pre-revprop-change", hook, args, TRUE, stdin_handle, pool)); SVN_ERR(svn_io_file_close(stdin_handle, pool)); } else { /* If the pre- hook doesn't exist at all, then default to MASSIVE PARANOIA. Changing revision properties is a lossy operation; so unless the repository admininstrator has *deliberately* created the pre-hook, disallow all changes. */ return svn_error_create (SVN_ERR_REPOS_DISABLED_FEATURE, NULL, _("Repository has not been enabled to accept revision propchanges;\n" "ask the administrator to create a pre-revprop-change hook")); } return SVN_NO_ERROR;}svn_error_t *svn_repos__hooks_post_revprop_change(svn_repos_t *repos, svn_revnum_t rev, const char *author, const char *name, svn_string_t *old_value, char action, apr_pool_t *pool){ const char *hook = svn_repos_post_revprop_change_hook(repos, pool); svn_boolean_t broken_link; if ((hook = check_hook_cmd(hook, &broken_link, pool)) && broken_link) { return hook_symlink_error(hook); } else if (hook) { const char *args[7]; apr_file_t *stdin_handle = NULL; char action_string[2]; /* Pass the old value as stdin to hook */ if (old_value) SVN_ERR(create_temp_file(&stdin_handle, old_value, pool)); else SVN_ERR(svn_io_file_open(&stdin_handle, SVN_NULL_DEVICE_NAME, APR_READ, APR_OS_DEFAULT, pool)); action_string[0] = action; action_string[1] = '\0'; args[0] = hook; args[1] = svn_repos_path(repos, pool); args[2] = apr_psprintf(pool, "%ld", rev); args[3] = author ? author : ""; args[4] = name; args[5] = action_string; args[6] = NULL; SVN_ERR(run_hook_cmd("post-revprop-change", hook, args, FALSE, stdin_handle, pool)); SVN_ERR(svn_io_file_close(stdin_handle, pool)); } return SVN_NO_ERROR;}svn_error_t *svn_repos__hooks_pre_lock(svn_repos_t *repos, const char *path, const char *username, apr_pool_t *pool){ const char *hook = svn_repos_pre_lock_hook(repos, pool); svn_boolean_t broken_link; if ((hook = check_hook_cmd(hook, &broken_link, pool)) && broken_link) { return hook_symlink_error(hook); } else if (hook) { const char *args[5]; args[0] = hook; args[1] = svn_repos_path(repos, pool); args[2] = path; args[3] = username; args[4] = NULL; SVN_ERR(run_hook_cmd("pre-lock", hook, args, TRUE, NULL, pool)); } return SVN_NO_ERROR;}svn_error_t *svn_repos__hooks_post_lock(svn_repos_t *repos, apr_array_header_t *paths, const char *username, apr_pool_t *pool){ const char *hook = svn_repos_post_lock_hook(repos, pool); svn_boolean_t broken_link; if ((hook = check_hook_cmd(hook, &broken_link, pool)) && broken_link) { return hook_symlink_error(hook); } else if (hook) { const char *args[5]; apr_file_t *stdin_handle = NULL; 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)); args[0] = hook; args[1] = svn_repos_path(repos, pool); args[2] = username; args[3] = NULL; args[4] = NULL; SVN_ERR(run_hook_cmd("post-lock", hook, args, FALSE, stdin_handle, pool)); SVN_ERR(svn_io_file_close(stdin_handle, pool)); } return SVN_NO_ERROR;}svn_error_t *svn_repos__hooks_pre_unlock(svn_repos_t *repos, const char *path, const char *username, apr_pool_t *pool){ const char *hook = svn_repos_pre_unlock_hook(repos, pool); svn_boolean_t broken_link; if ((hook = check_hook_cmd(hook, &broken_link, pool)) && broken_link) { return hook_symlink_error(hook); } else if (hook) { const char *args[5]; args[0] = hook; args[1] = svn_repos_path(repos, pool); args[2] = path; args[3] = username ? username : ""; args[4] = NULL; SVN_ERR(run_hook_cmd("pre-unlock", hook, args, TRUE, NULL, pool)); } return SVN_NO_ERROR;}svn_error_t *svn_repos__hooks_post_unlock(svn_repos_t *repos, apr_array_header_t *paths, const char *username, apr_pool_t *pool){ const char *hook = svn_repos_post_unlock_hook(repos, pool); svn_boolean_t broken_link; if ((hook = check_hook_cmd(hook, &broken_link, pool)) && broken_link) { return hook_symlink_error(hook); } else if (hook) { const char *args[5]; apr_file_t *stdin_handle = NULL; 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)); args[0] = hook; args[1] = svn_repos_path(repos, pool); args[2] = username ? username : ""; args[3] = NULL; args[4] = NULL; SVN_ERR(run_hook_cmd("post-unlock", hook, args, FALSE, stdin_handle, pool)); SVN_ERR(svn_io_file_close(stdin_handle, pool)); } return SVN_NO_ERROR;}/* * vim:ts=4:sw=4:expandtab:tw=80:fo=tcroq * vim:isk=a-z,A-Z,48-57,_,.,-,> * vim:cino=>1s,e0,n0,f0,{.5s,}0,^-.5s,=.5s,t0,+1s,c3,(0,u0,\:0 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -