Patchwork [1,of,5] hook: add a 'hashook' function to test for hook existence

login
register
mail settings
Submitter Boris Feld
Date Oct. 9, 2017, 6:36 p.m.
Message ID <29bb94cd7a882b572324.1507574179@FB>
Download mbox | patch
Permalink /patch/24661/
State Superseded
Headers show

Comments

Boris Feld - Oct. 9, 2017, 6:36 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1507460911 -7200
#      Sun Oct 08 13:08:31 2017 +0200
# Node ID 29bb94cd7a882b572324c07a7c2fdc974956e6e5
# Parent  8cef8f7d51d0f1e99889779ec1320d5c9c3b91de
# EXP-Topic b2.phases.hooks
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 29bb94cd7a88
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.

Patch

diff -r 8cef8f7d51d0 -r 29bb94cd7a88 mercurial/hook.py
--- a/mercurial/hook.py	Thu Oct 05 20:41:50 2017 -0700
+++ 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