comparison mercurial/hook.py @ 37119:d4a2e0d5d042

procutil: bulk-replace util.std* to point to new module
author Yuya Nishihara <yuya@tcha.org>
date Sat, 24 Mar 2018 15:09:33 +0900
parents 9c636ec1ef37
children a8a902d7176e
comparison
equal deleted inserted replaced
37118:5be286db5fb5 37119:d4a2e0d5d042
16 encoding, 16 encoding,
17 error, 17 error,
18 extensions, 18 extensions,
19 pycompat, 19 pycompat,
20 util, 20 util,
21 )
22 from .utils import (
23 procutil,
21 ) 24 )
22 25
23 def _pythonhook(ui, repo, htype, hname, funcname, args, throw): 26 def _pythonhook(ui, repo, htype, hname, funcname, args, throw):
24 '''call python hook. hook is callable object, looked up as 27 '''call python hook. hook is callable object, looked up as
25 name in python module. if callable returns "true", hook 28 name in python module. if callable returns "true", hook
220 223
221 try: 224 try:
222 for hname, cmd in hooks: 225 for hname, cmd in hooks:
223 if oldstdout == -1 and _redirect: 226 if oldstdout == -1 and _redirect:
224 try: 227 try:
225 stdoutno = util.stdout.fileno() 228 stdoutno = procutil.stdout.fileno()
226 stderrno = util.stderr.fileno() 229 stderrno = procutil.stderr.fileno()
227 # temporarily redirect stdout to stderr, if possible 230 # temporarily redirect stdout to stderr, if possible
228 if stdoutno >= 0 and stderrno >= 0: 231 if stdoutno >= 0 and stderrno >= 0:
229 util.stdout.flush() 232 procutil.stdout.flush()
230 oldstdout = os.dup(stdoutno) 233 oldstdout = os.dup(stdoutno)
231 os.dup2(stderrno, stdoutno) 234 os.dup2(stderrno, stdoutno)
232 except (OSError, AttributeError): 235 except (OSError, AttributeError):
233 # files seem to be bogus, give up on redirecting (WSGI, etc) 236 # files seem to be bogus, give up on redirecting (WSGI, etc)
234 pass 237 pass
267 res[hname] = r, raised 270 res[hname] = r, raised
268 finally: 271 finally:
269 # The stderr is fully buffered on Windows when connected to a pipe. 272 # The stderr is fully buffered on Windows when connected to a pipe.
270 # A forcible flush is required to make small stderr data in the 273 # A forcible flush is required to make small stderr data in the
271 # remote side available to the client immediately. 274 # remote side available to the client immediately.
272 util.stderr.flush() 275 procutil.stderr.flush()
273 276
274 if _redirect and oldstdout >= 0: 277 if _redirect and oldstdout >= 0:
275 util.stdout.flush() # write hook output to stderr fd 278 procutil.stdout.flush() # write hook output to stderr fd
276 os.dup2(oldstdout, stdoutno) 279 os.dup2(oldstdout, stdoutno)
277 os.close(oldstdout) 280 os.close(oldstdout)
278 281
279 return res 282 return res