changeset 7355:efe7ed15e12c

hooks: cleanup and documentation of the installed Git hooks
author Mads Kiilerich <mads@kiilerich.com>
date Wed, 08 Aug 2018 02:23:11 +0200
parents 51ef4b681634
children 39bdf0ab2862
files kallithea/config/post_receive_tmpl.py kallithea/config/pre_receive_tmpl.py
diffstat 2 files changed, 34 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/config/post_receive_tmpl.py	Wed Aug 08 02:23:11 2018 +0200
+++ b/kallithea/config/post_receive_tmpl.py	Wed Aug 08 02:23:11 2018 +0200
@@ -1,28 +1,34 @@
+"""Kallithea Git hook
+
+This hook is installed and maintained by Kallithea. It will be overwritten
+by Kallithea - don't customize it manually!
+
+When Kallithea invokes Git, the KALLITHEA_EXTRAS environment variable will
+contain additional info like the Kallithea instance and user info that this
+hook will use.
+"""
+
 import os
 import sys
 
-# set output mode on windows to binary for stderr
-# this prevents python (or the windows console) from replacing \n with  \r\n
-# git doesn't display remote output lines that contain \r
-# and therefore without this modification git would displayes empty lines
-# instead of the exception output
+# Set output mode on windows to binary for stderr.
+# This prevents python (or the windows console) from replacing \n with \r\n.
+# Git doesn't display remote output lines that contain \r,
+# and therefore without this modification git would display empty lines
+# instead of the exception output.
 if sys.platform == "win32":
     import msvcrt
     msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY)
 
 KALLITHEA_HOOK_VER = '_TMPL_'
 os.environ['KALLITHEA_HOOK_VER'] = KALLITHEA_HOOK_VER
-from kallithea.lib.hooks import handle_git_post_receive as _handler
+import kallithea.lib.hooks
 
 
 def main():
     repo_path = os.path.abspath('.')
     git_stdin_lines = sys.stdin.readlines()
-    # os.environ is modified here by a subprocess call that
-    # runs git and later git executes this hook.
-    # Environ gets some additional info from kallithea system
-    # like IP or username from basic-auth
-    sys.exit(_handler(repo_path, git_stdin_lines, os.environ))
+    sys.exit(kallithea.lib.hooks.handle_git_post_receive(repo_path, git_stdin_lines, os.environ))
 
 
 if __name__ == '__main__':
--- a/kallithea/config/pre_receive_tmpl.py	Wed Aug 08 02:23:11 2018 +0200
+++ b/kallithea/config/pre_receive_tmpl.py	Wed Aug 08 02:23:11 2018 +0200
@@ -1,28 +1,34 @@
+"""Kallithea Git hook
+
+This hook is installed and maintained by Kallithea. It will be overwritten
+by Kallithea - don't customize it manually!
+
+When Kallithea invokes Git, the KALLITHEA_EXTRAS environment variable will
+contain additional info like the Kallithea instance and user info that this
+hook will use.
+"""
+
 import os
 import sys
 
-# set output mode on windows to binary for stderr
-# this prevents python (or the windows console) from replacing \n with  \r\n
-# git doesn't display remote output lines that contain \r
-# and therefore without this modification git would displayes empty lines
-# instead of the exception output
+# Set output mode on windows to binary for stderr.
+# This prevents python (or the windows console) from replacing \n with \r\n.
+# Git doesn't display remote output lines that contain \r,
+# and therefore without this modification git would display empty lines
+# instead of the exception output.
 if sys.platform == "win32":
     import msvcrt
     msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY)
 
 KALLITHEA_HOOK_VER = '_TMPL_'
 os.environ['KALLITHEA_HOOK_VER'] = KALLITHEA_HOOK_VER
-from kallithea.lib.hooks import handle_git_pre_receive as _handler
+import kallithea.lib.hooks
 
 
 def main():
     repo_path = os.path.abspath('.')
     git_stdin_lines = sys.stdin.readlines()
-    # os.environ is modified here by a subprocess call that
-    # runs git and later git executes this hook.
-    # Environ gets some additional info from kallithea system
-    # like IP or username from basic-auth
-    sys.exit(_handler(repo_path, git_stdin_lines, os.environ))
+    sys.exit(kallithea.lib.hooks.handle_git_pre_receive(repo_path, git_stdin_lines, os.environ))
 
 
 if __name__ == '__main__':