# HG changeset patch # User Boris Feld # Date 1507460911 -7200 # Node ID e79b6300d97c6c70e032c78a4e18670c0a0e6e7a # Parent 0d1b8be8d8a803f8b664804540fade1215b9a923 hook: add a 'hashook' function to test for hook existence Preparing the data for some hooks can be expensive. Add a function to check if a hook exists so we can skip useless preparation if no hook is configured. diff -r 0d1b8be8d8a8 -r e79b6300d97c mercurial/hook.py --- a/mercurial/hook.py Fri Oct 13 22:42:17 2017 +0200 +++ b/mercurial/hook.py Sun Oct 08 13:08:31 2017 +0200 @@ -189,6 +189,15 @@ global _redirect _redirect = state +def hashook(ui, htype): + """return True if a hook is configured for 'htype'""" + if not ui.callhooks: + return False + for hname, cmd in _allhooks(ui): + if hname.split('.')[0] == htype and cmd: + return True + return False + def hook(ui, repo, htype, throw=False, **args): if not ui.callhooks: return False