comparison mercurial/hook.py @ 30482:39d13b8c101d

py3: bulk replace sys.stdin/out/err by util's Almost all sys.stdin/out/err in hgext/ and mercurial/ are replaced by util's. There are a few exceptions: - lsprof.py and statprof.py are untouched since they are a kind of vendor code and they never import mercurial modules right now. - ui._readline() needs to replace sys.stdin and stdout to pass them to raw_input(). We'll need another workaround here.
author Yuya Nishihara <yuya@tcha.org>
date Thu, 20 Oct 2016 23:53:36 +0900
parents 5564fcd031df
children 20a42325fdef
comparison
equal deleted inserted replaced
30481:277f4fe6d01a 30482:39d13b8c101d
207 207
208 try: 208 try:
209 for hname, cmd in hooks: 209 for hname, cmd in hooks:
210 if oldstdout == -1 and _redirect: 210 if oldstdout == -1 and _redirect:
211 try: 211 try:
212 stdoutno = sys.stdout.fileno() 212 stdoutno = util.stdout.fileno()
213 stderrno = sys.stderr.fileno() 213 stderrno = util.stderr.fileno()
214 # temporarily redirect stdout to stderr, if possible 214 # temporarily redirect stdout to stderr, if possible
215 if stdoutno >= 0 and stderrno >= 0: 215 if stdoutno >= 0 and stderrno >= 0:
216 sys.stdout.flush() 216 util.stdout.flush()
217 oldstdout = os.dup(stdoutno) 217 oldstdout = os.dup(stdoutno)
218 os.dup2(stderrno, stdoutno) 218 os.dup2(stderrno, stdoutno)
219 except (OSError, AttributeError): 219 except (OSError, AttributeError):
220 # files seem to be bogus, give up on redirecting (WSGI, etc) 220 # files seem to be bogus, give up on redirecting (WSGI, etc)
221 pass 221 pass
253 res[hname] = r, raised 253 res[hname] = r, raised
254 254
255 # The stderr is fully buffered on Windows when connected to a pipe. 255 # The stderr is fully buffered on Windows when connected to a pipe.
256 # A forcible flush is required to make small stderr data in the 256 # A forcible flush is required to make small stderr data in the
257 # remote side available to the client immediately. 257 # remote side available to the client immediately.
258 sys.stderr.flush() 258 util.stderr.flush()
259 finally: 259 finally:
260 if _redirect and oldstdout >= 0: 260 if _redirect and oldstdout >= 0:
261 sys.stdout.flush() # write hook output to stderr fd 261 util.stdout.flush() # write hook output to stderr fd
262 os.dup2(oldstdout, stdoutno) 262 os.dup2(oldstdout, stdoutno)
263 os.close(oldstdout) 263 os.close(oldstdout)
264 264
265 return res 265 return res