mercurial/hook.py
branchstable
changeset 23415 cdbb85489c41
parent 21797 b009dd135aa0
child 23426 19ebd2f88fc7
equal deleted inserted replaced
23414:759202b64f49 23415:cdbb85489c41
     5 # This software may be used and distributed according to the terms of the
     5 # This software may be used and distributed according to the terms of the
     6 # GNU General Public License version 2 or any later version.
     6 # GNU General Public License version 2 or any later version.
     7 
     7 
     8 from i18n import _
     8 from i18n import _
     9 import os, sys, time
     9 import os, sys, time
    10 import extensions, util, demandimport
    10 import extensions, util, demandimport, error
    11 
    11 
    12 def _pythonhook(ui, repo, name, hname, funcname, args, throw):
    12 def _pythonhook(ui, repo, name, hname, funcname, args, throw):
    13     '''call python hook. hook is callable object, looked up as
    13     '''call python hook. hook is callable object, looked up as
    14     name in python module. if callable returns "true", hook
    14     name in python module. if callable returns "true", hook
    15     fails, else passes. if hook raises exception, treated as
    15     fails, else passes. if hook raises exception, treated as
   105         duration = time.time() - starttime
   105         duration = time.time() - starttime
   106         ui.log('pythonhook', 'pythonhook-%s: %s finished in %0.2f seconds\n',
   106         ui.log('pythonhook', 'pythonhook-%s: %s finished in %0.2f seconds\n',
   107                name, funcname, duration)
   107                name, funcname, duration)
   108     if r:
   108     if r:
   109         if throw:
   109         if throw:
   110             raise util.Abort(_('%s hook failed') % hname)
   110             raise error.HookAbort(_('%s hook failed') % hname)
   111         ui.warn(_('warning: %s hook failed\n') % hname)
   111         ui.warn(_('warning: %s hook failed\n') % hname)
   112     return r
   112     return r
   113 
   113 
   114 def _exthook(ui, repo, name, cmd, args, throw):
   114 def _exthook(ui, repo, name, cmd, args, throw):
   115     ui.note(_("running hook %s: %s\n") % (name, cmd))
   115     ui.note(_("running hook %s: %s\n") % (name, cmd))
   140     ui.log('exthook', 'exthook-%s: %s finished in %0.2f seconds\n',
   140     ui.log('exthook', 'exthook-%s: %s finished in %0.2f seconds\n',
   141            name, cmd, duration)
   141            name, cmd, duration)
   142     if r:
   142     if r:
   143         desc, r = util.explainexit(r)
   143         desc, r = util.explainexit(r)
   144         if throw:
   144         if throw:
   145             raise util.Abort(_('%s hook %s') % (name, desc))
   145             raise error.HookAbort(_('%s hook %s') % (name, desc))
   146         ui.warn(_('warning: %s hook %s\n') % (name, desc))
   146         ui.warn(_('warning: %s hook %s\n') % (name, desc))
   147     return r
   147     return r
   148 
   148 
   149 def _allhooks(ui):
   149 def _allhooks(ui):
   150     hooks = []
   150     hooks = []