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

login
register
mail settings
Submitter Boris Feld
Date Oct. 11, 2017, 2:02 p.m.
Message ID <1a64b2bcd0209ea3b906.1507730547@FB>
Download mbox | patch
Permalink /patch/24734/
State Accepted
Headers show

Comments

Boris Feld - Oct. 11, 2017, 2:02 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 1a64b2bcd0209ea3b906f458818db6f29cebbcd7
# Parent  4a6a337f9c682bdf1659295f871dc43ff33677ca
# EXP-Topic b2.phases.hooks
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 1a64b2bcd020
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.
Augie Fackler - Oct. 14, 2017, 5:28 a.m.
On Wed, Oct 11, 2017 at 04:02:27PM +0200, Boris Feld wrote:
> # HG changeset patch
> # User Boris Feld <boris.feld@octobus.net>
> # Date 1507460911 -7200
> #      Sun Oct 08 13:08:31 2017 +0200
> # Node ID 1a64b2bcd0209ea3b906f458818db6f29cebbcd7
> # Parent  4a6a337f9c682bdf1659295f871dc43ff33677ca
> # EXP-Topic b2.phases.hooks
> # Available At https://bitbucket.org/octobus/mercurial-devel/
> #              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 1a64b2bcd020
> hook: add a 'hashook' function to test for hook existence

queued, thanks

The rest of these have bitrotted. Could you rebase and resend them
(after seeing my comment on the next patch.) Thanks!

Patch

diff --git a/mercurial/hook.py b/mercurial/hook.py
--- 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