summaryrefslogtreecommitdiff
path: root/mercurial/hook.py
diff options
context:
space:
mode:
Diffstat (limited to 'mercurial/hook.py')
-rw-r--r--mercurial/hook.py32
1 files changed, 8 insertions, 24 deletions
diff --git a/mercurial/hook.py b/mercurial/hook.py
index 9831353..0d92e91 100644
--- a/mercurial/hook.py
+++ b/mercurial/hook.py
@@ -21,14 +21,14 @@ def _pythonhook(ui, repo, name, hname, funcname, args, throw):
ui.note(_("calling hook %s: %s\n") % (hname, funcname))
obj = funcname
- if not util.safehasattr(obj, '__call__'):
+ if not hasattr(obj, '__call__'):
d = funcname.rfind('.')
if d == -1:
raise util.Abort(_('%s hook is invalid ("%s" not in '
'a module)') % (hname, funcname))
modname = funcname[:d]
oldpaths = sys.path
- if util.mainfrozen():
+ if hasattr(sys, "frozen"):
# binary installs require sys.path manipulation
modpath, modfile = os.path.split(modname)
if modpath and modfile:
@@ -60,13 +60,13 @@ def _pythonhook(ui, repo, name, hname, funcname, args, throw):
raise util.Abort(_('%s hook is invalid '
'("%s" is not defined)') %
(hname, funcname))
- if not util.safehasattr(obj, '__call__'):
+ if not hasattr(obj, '__call__'):
raise util.Abort(_('%s hook is invalid '
'("%s" is not callable)') %
(hname, funcname))
try:
try:
- # redirect IO descriptors to the ui descriptors so hooks
+ # redirect IO descriptors the the ui descriptors so hooks
# that write directly to these don't mess up the command
# protocol when running through the command server
old = sys.stdout, sys.stderr, sys.stdin
@@ -99,7 +99,7 @@ def _exthook(ui, repo, name, cmd, args, throw):
env = {}
for k, v in args.iteritems():
- if util.safehasattr(v, '__call__'):
+ if hasattr(v, '__call__'):
v = v()
if isinstance(v, dict):
# make the dictionary element order stable across Python
@@ -124,23 +124,12 @@ def _exthook(ui, repo, name, cmd, args, throw):
ui.warn(_('warning: %s hook %s\n') % (name, desc))
return r
-def _allhooks(ui):
- hooks = []
- for name, cmd in ui.configitems('hooks'):
- if not name.startswith('priority'):
- priority = ui.configint('hooks', 'priority.%s' % name, 0)
- hooks.append((-priority, len(hooks), name, cmd))
- return [(k, v) for p, o, k, v in sorted(hooks)]
-
_redirect = False
def redirect(state):
global _redirect
_redirect = state
def hook(ui, repo, name, throw=False, **args):
- if not ui.callhooks:
- return False
-
r = False
oldstdout = -1
@@ -150,7 +139,6 @@ def hook(ui, repo, name, throw=False, **args):
stderrno = sys.__stderr__.fileno()
# temporarily redirect stdout to stderr, if possible
if stdoutno >= 0 and stderrno >= 0:
- sys.__stdout__.flush()
oldstdout = os.dup(stdoutno)
os.dup2(stderrno, stdoutno)
except AttributeError:
@@ -158,10 +146,10 @@ def hook(ui, repo, name, throw=False, **args):
pass
try:
- for hname, cmd in _allhooks(ui):
+ for hname, cmd in ui.configitems('hooks'):
if hname.split('.')[0] != name or not cmd:
continue
- if util.safehasattr(cmd, '__call__'):
+ if hasattr(cmd, '__call__'):
r = _pythonhook(ui, repo, name, hname, cmd, args, throw) or r
elif cmd.startswith('python:'):
if cmd.count(':') >= 2:
@@ -169,11 +157,7 @@ def hook(ui, repo, name, throw=False, **args):
path = util.expandpath(path)
if repo:
path = os.path.join(repo.root, path)
- try:
- mod = extensions.loadpath(path, 'hghook.%s' % hname)
- except Exception:
- ui.write(_("loading %s hook failed:\n") % hname)
- raise
+ mod = extensions.loadpath(path, 'hghook.%s' % hname)
hookfn = getattr(mod, cmd)
else:
hookfn = cmd[7:].strip()