hooks: for python hooks, consistently use __name__ etc as name, not the repr
There is no reason to expose unnecessary Python implementation details and
memory locations, also not in debug mode.
readablefunc was already creating a nice name - we move that functionality
up and reuse it.
We consider having a __call__ and being types.FunctionType sufficiently
similar and unify these two to just using the existing check for __call__.
--- a/mercurial/hook.py Sat Feb 15 01:23:12 2014 +0100
+++ b/mercurial/hook.py Sat Feb 15 01:23:12 2014 +0100
@@ -6,7 +6,7 @@
# GNU General Public License version 2 or any later version.
from i18n import _
-import os, sys, time, types
+import os, sys, time
import extensions, util, demandimport
def _pythonhook(ui, repo, name, hname, funcname, args, throw):
@@ -19,8 +19,10 @@
unmodified commands (e.g. mercurial.commands.update) can
be run as hooks without wrappers to convert return values.'''
- obj = funcname
- if not util.safehasattr(obj, '__call__'):
+ if util.safehasattr(funcname, '__call__'):
+ obj = funcname
+ funcname = obj.__module__ + "." + obj.__name__
+ else:
d = funcname.rfind('.')
if d == -1:
raise util.Abort(_('%s hook is invalid ("%s" not in '
@@ -101,11 +103,8 @@
finally:
sys.stdout, sys.stderr, sys.stdin = old
duration = time.time() - starttime
- readablefunc = funcname
- if isinstance(funcname, types.FunctionType):
- readablefunc = funcname.__module__ + "." + funcname.__name__
ui.log('pythonhook', 'pythonhook-%s: %s finished in %0.2f seconds\n',
- name, readablefunc, duration)
+ name, funcname, duration)
if r:
if throw:
raise util.Abort(_('%s hook failed') % hname)
--- a/tests/test-hook.t Sat Feb 15 01:23:12 2014 +0100
+++ b/tests/test-hook.t Sat Feb 15 01:23:12 2014 +0100
@@ -499,7 +499,7 @@
$ echo >> foo
$ hg ci --debug -d '0 0' -m 'change foo'
foo
- calling hook commit.auto: <function autohook at *> (glob)
+ calling hook commit.auto: hgext_hookext.autohook
Automatically installed hook
committed changeset 1:52998019f6252a2b893452765fcb0a47351a5708
--- a/tests/test-largefiles.t Sat Feb 15 01:23:12 2014 +0100
+++ b/tests/test-largefiles.t Sat Feb 15 01:23:12 2014 +0100
@@ -900,7 +900,7 @@
adding manifests
adding file changes
added 6 changesets with 16 changes to 8 files
- calling hook changegroup.lfiles: <function checkrequireslfiles at *> (glob)
+ calling hook changegroup.lfiles: hgext.largefiles.reposetup.checkrequireslfiles
(run 'hg update' to get a working copy)
pulling largefiles for revision 7
found 971fb41e78fea4f8e0ba5244784239371cb00591 in store