mercurial/hook.py
branchstable
changeset 17963 6180dcb29ec5
parent 17428 72803c8edaa4
child 17964 2c63896783e3
equal deleted inserted replaced
17962:4c29668ca316 17963:6180dcb29ec5
   140 def hook(ui, repo, name, throw=False, **args):
   140 def hook(ui, repo, name, throw=False, **args):
   141     if not ui.callhooks:
   141     if not ui.callhooks:
   142         return False
   142         return False
   143 
   143 
   144     r = False
   144     r = False
   145 
       
   146     oldstdout = -1
   145     oldstdout = -1
   147     if _redirect:
       
   148         try:
       
   149             stdoutno = sys.__stdout__.fileno()
       
   150             stderrno = sys.__stderr__.fileno()
       
   151             # temporarily redirect stdout to stderr, if possible
       
   152             if stdoutno >= 0 and stderrno >= 0:
       
   153                 sys.__stdout__.flush()
       
   154                 oldstdout = os.dup(stdoutno)
       
   155                 os.dup2(stderrno, stdoutno)
       
   156         except AttributeError:
       
   157             # __stdout__/__stderr__ doesn't have fileno(), it's not a real file
       
   158             pass
       
   159 
   146 
   160     try:
   147     try:
   161         for hname, cmd in _allhooks(ui):
   148         for hname, cmd in _allhooks(ui):
   162             if hname.split('.')[0] != name or not cmd:
   149             if hname.split('.')[0] != name or not cmd:
   163                 continue
   150                 continue
       
   151 
       
   152             if oldstdout == -1 and _redirect:
       
   153                 try:
       
   154                     stdoutno = sys.__stdout__.fileno()
       
   155                     stderrno = sys.__stderr__.fileno()
       
   156                     # temporarily redirect stdout to stderr, if possible
       
   157                     if stdoutno >= 0 and stderrno >= 0:
       
   158                         sys.__stdout__.flush()
       
   159                         oldstdout = os.dup(stdoutno)
       
   160                         os.dup2(stderrno, stdoutno)
       
   161                 except AttributeError:
       
   162                     # __stdout__/__stderr__ has no fileno(), not a real file
       
   163                     pass
       
   164 
   164             if util.safehasattr(cmd, '__call__'):
   165             if util.safehasattr(cmd, '__call__'):
   165                 r = _pythonhook(ui, repo, name, hname, cmd, args, throw) or r
   166                 r = _pythonhook(ui, repo, name, hname, cmd, args, throw) or r
   166             elif cmd.startswith('python:'):
   167             elif cmd.startswith('python:'):
   167                 if cmd.count(':') >= 2:
   168                 if cmd.count(':') >= 2:
   168                     path, cmd = cmd[7:].rsplit(':', 1)
   169                     path, cmd = cmd[7:].rsplit(':', 1)