# HG changeset patch # User Mads Kiilerich # Date 1534283015 -7200 # Node ID c55338638085a0e72f913c37f17170eb11e327b0 # Parent 475eaccc844b5736d6f19de75fb38cb97a282ed0 hooks: empower the Git entry points and avoid the big handle_git_receive dispatch Use the new _hook_environment and enjoy the small and clean hooks. Just moving code - no change. diff -r 475eaccc844b -r c55338638085 kallithea/lib/hooks.py --- a/kallithea/lib/hooks.py Wed Aug 08 02:23:11 2018 +0200 +++ b/kallithea/lib/hooks.py Tue Aug 14 23:43:35 2018 +0200 @@ -357,16 +357,6 @@ return 0 -def handle_git_pre_receive(repo_path, git_stdin_lines, env): - """Called from Git pre-receive hook""" - return handle_git_receive(repo_path, git_stdin_lines, env, hook_type='pre') - - -def handle_git_post_receive(repo_path, git_stdin_lines, env): - """Called from Git post-receive hook""" - return handle_git_receive(repo_path, git_stdin_lines, env, hook_type='post') - - def _hook_environment(repo_path, env): """ Create a light-weight environment for stand-alone scripts and return an UI and the @@ -404,32 +394,24 @@ baseui = make_ui('db') return baseui, repo -def handle_git_receive(repo_path, git_stdin_lines, env, hook_type): - """ - A really hacky method that is run by git post-receive hook and logs - a push action together with pushed revisions. It's executed by subprocess - thus needs all info to be able to create an on the fly app environment, - connect to database and run the logging code. Hacky as sh*t but works. - :param repo_path: - :param revs: - :param env: - """ +def handle_git_pre_receive(repo_path, git_stdin_lines, env): + """Called from Git pre-receive hook""" + baseui, repo = _hook_environment(repo_path, env) + scm_repo = repo.scm_instance + push_lock_handling(baseui, scm_repo) + + +def handle_git_post_receive(repo_path, git_stdin_lines, env): + """Called from Git post-receive hook""" baseui, repo = _hook_environment(repo_path, env) - if hook_type == 'pre': - scm_repo = repo.scm_instance - else: - # post push should never use the cached instance - scm_repo = repo.scm_instance_no_cache() + # the post push hook should never use the cached instance + scm_repo = repo.scm_instance_no_cache() _hooks = dict(baseui.configitems('hooks')) or {} - - if hook_type == 'pre': - push_lock_handling(baseui, scm_repo) - # if push hook is enabled via web interface - elif hook_type == 'post' and _hooks.get(Ui.HOOK_PUSH_LOG): + if _hooks.get(Ui.HOOK_PUSH_LOG): rev_data = [] for l in git_stdin_lines: old_rev, new_rev, ref = l.strip().split(' ')