Mercurial > hg > mercurial-source
diff mercurial/hook.py @ 35470:e79b6300d97c
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.
author | Boris Feld <boris.feld@octobus.net> |
---|---|
date | Sun, 08 Oct 2017 13:08:31 +0200 (2017-10-08) |
parents | 799db2af824c |
children | 056a9c8813aa |
line wrap: on
line diff
--- a/mercurial/hook.py +++ b/mercurial/hook.py @@ -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