# HG changeset patch # User Siddharth Agarwal # Date 2015-10-14 23:13:31 # Node ID a930d66a04af7105a546c6a340c1065d0130eebe # Parent 143b52fce68e5080db4ccb022bc859ae3e65de4e hook: factor out determination of hooks from running them This will allow other code to run a predetermined series of hooks. diff --git a/mercurial/hook.py b/mercurial/hook.py --- a/mercurial/hook.py +++ b/mercurial/hook.py @@ -162,14 +162,19 @@ def hook(ui, repo, name, throw=False, ** if not ui.callhooks: return False + hooks = [] + for hname, cmd in _allhooks(ui): + if hname.split('.')[0] == name and cmd: + hooks.append((hname, cmd)) + + return runhooks(ui, repo, name, hooks, throw=throw, **args) + +def runhooks(ui, repo, name, hooks, throw=False, **args): r = False oldstdout = -1 try: - for hname, cmd in _allhooks(ui): - if hname.split('.')[0] != name or not cmd: - continue - + for hname, cmd in hooks: if oldstdout == -1 and _redirect: try: stdoutno = sys.__stdout__.fileno()