# HG changeset patch # User Mads Kiilerich # Date 1601551392 -7200 # Node ID 86bf9873645f18980d56d281e6e57fa4d2f8af33 # Parent aa695851519627de8e9f03e962d0fd09f0a1013b rcextensions: drop unused (and thus misleading) return values Note that Mercurial only will check the hook exit value for some kinds of hooks. diff -r aa6958515196 -r 86bf9873645f kallithea/config/rcextensions/__init__.py --- a/kallithea/config/rcextensions/__init__.py Sat Oct 03 23:47:52 2020 +0200 +++ b/kallithea/config/rcextensions/__init__.py Thu Oct 01 13:23:12 2020 +0200 @@ -48,7 +48,6 @@ :param group_id: :param created_by: """ - return 0 CREATE_REPO_HOOK = _crrepohook @@ -107,7 +106,6 @@ :param emails: :param created_by: """ - return 0 CREATE_USER_HOOK = _cruserhook @@ -136,7 +134,6 @@ :param deleted_by: :param deleted_on: """ - return 0 DELETE_REPO_HOOK = _dlrepohook @@ -170,7 +167,6 @@ :param emails: :param deleted_by: """ - return 0 DELETE_USER_HOOK = _dluserhook @@ -195,7 +191,6 @@ :param repository: repository name :param pushed_revs: list of pushed revisions """ - return 0 PUSH_HOOK = _pushhook @@ -219,7 +214,6 @@ :param action: pull :param repository: repository name """ - return 0 PULL_HOOK = _pullhook diff -r aa6958515196 -r 86bf9873645f kallithea/lib/hooks.py --- a/kallithea/lib/hooks.py Sat Oct 03 23:47:52 2020 +0200 +++ b/kallithea/lib/hooks.py Thu Oct 01 13:23:12 2020 +0200 @@ -101,8 +101,6 @@ kw.update(ex) callback(**kw) - return 0 - def log_push_action(ui, repo, node, node_last, **kwargs): """ @@ -116,7 +114,6 @@ """ revs = [ascii_str(repo[r].hex()) for r in mercurial.scmutil.revrange(repo, [b'%s:%s' % (node, node_last)])] process_pushed_raw_ids(revs) - return 0 def process_pushed_raw_ids(revs): @@ -174,9 +171,7 @@ kw.update(repository_dict) kw.update({'created_by': created_by}) kw.update(kwargs) - return callback(**kw) - - return 0 + callback(**kw) def check_allowed_create_user(user_dict, created_by, **kwargs): @@ -220,9 +215,7 @@ from kallithea import EXTENSIONS callback = getattr(EXTENSIONS, 'CREATE_USER_HOOK', None) if callable(callback): - return callback(created_by=created_by, **user_dict) - - return 0 + callback(created_by=created_by, **user_dict) def log_delete_repository(repository_dict, deleted_by, **kwargs): @@ -256,9 +249,7 @@ kw.update({'deleted_by': deleted_by, 'deleted_on': time.time()}) kw.update(kwargs) - return callback(**kw) - - return 0 + callback(**kw) def log_delete_user(user_dict, deleted_by, **kwargs): @@ -292,9 +283,7 @@ from kallithea import EXTENSIONS callback = getattr(EXTENSIONS, 'DELETE_USER_HOOK', None) if callable(callback): - return callback(deleted_by=deleted_by, **user_dict) - - return 0 + callback(deleted_by=deleted_by, **user_dict) def _hook_environment(repo_path): @@ -330,13 +319,17 @@ def handle_git_pre_receive(repo_path, git_stdin_lines): - """Called from Git pre-receive hook""" + """Called from Git pre-receive hook. + The returned value is used as hook exit code and must be 0. + """ # Currently unused. TODO: remove? return 0 def handle_git_post_receive(repo_path, git_stdin_lines): - """Called from Git post-receive hook""" + """Called from Git post-receive hook. + The returned value is used as hook exit code and must be 0. + """ try: baseui, repo = _hook_environment(repo_path) except HookEnvironmentError as e: @@ -399,7 +392,9 @@ # Almost exactly like Mercurial contrib/hg-ssh: def rejectpush(ui, **kwargs): - """Mercurial hook to be installed as pretxnopen and prepushkey for read-only repos""" + """Mercurial hook to be installed as pretxnopen and prepushkey for read-only repos. + Return value 1 will make the hook fail and reject the push. + """ ex = get_hook_environment() ui.warn(safe_bytes("Push access to %r denied\n" % ex.repository)) return 1