# HG changeset patch # User Mads Kiilerich # Date 2014-02-15 00:23:12 # Node ID 5bd6a9fec10305c8c0cfc79877cbf8f5871c2a30 # Parent 9d9f8ccffeadb8bb706920ebbdd4f70da8b6d9f0 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__. diff --git a/mercurial/hook.py b/mercurial/hook.py --- a/mercurial/hook.py +++ b/mercurial/hook.py @@ -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 @@ def _pythonhook(ui, repo, name, hname, f 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 @@ def _pythonhook(ui, repo, name, hname, f 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) diff --git a/tests/test-hook.t b/tests/test-hook.t --- a/tests/test-hook.t +++ b/tests/test-hook.t @@ -499,7 +499,7 @@ make sure --traceback works $ echo >> foo $ hg ci --debug -d '0 0' -m 'change foo' foo - calling hook commit.auto: (glob) + calling hook commit.auto: hgext_hookext.autohook Automatically installed hook committed changeset 1:52998019f6252a2b893452765fcb0a47351a5708 diff --git a/tests/test-largefiles.t b/tests/test-largefiles.t --- a/tests/test-largefiles.t +++ b/tests/test-largefiles.t @@ -900,7 +900,7 @@ redo pull with --lfrev and check it pull adding manifests adding file changes added 6 changesets with 16 changes to 8 files - calling hook changegroup.lfiles: (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