##// END OF EJS Templates
pager: preserve Hg's exit code (and fix Windows support) (issue3225)...
Brodie Rao -
r16631:369741ef stable
parent child Browse files
Show More
@@ -53,37 +53,27 b' used. Use a boolean value like yes, no, '
53 normal behavior.
53 normal behavior.
54 '''
54 '''
55
55
56 import sys, os, signal, shlex, errno
56 import atexit, sys, os, signal, subprocess
57 from mercurial import commands, dispatch, util, extensions
57 from mercurial import commands, dispatch, util, extensions
58 from mercurial.i18n import _
58 from mercurial.i18n import _
59
59
60 def _runpager(p):
60 def _runpager(p):
61 if not util.safehasattr(os, 'fork'):
61 pager = subprocess.Popen(p, shell=True, bufsize=-1,
62 sys.stdout = util.popen(p, 'wb')
62 close_fds=util.closefds, stdin=subprocess.PIPE,
63 if util.isatty(sys.stderr):
63 stdout=sys.stdout, stderr=sys.stderr)
64 sys.stderr = sys.stdout
64
65 return
65 stdout = os.dup(sys.stdout.fileno())
66 fdin, fdout = os.pipe()
66 stderr = os.dup(sys.stderr.fileno())
67 pid = os.fork()
67 os.dup2(pager.stdin.fileno(), sys.stdout.fileno())
68 if pid == 0:
68 if util.isatty(sys.stderr):
69 os.close(fdin)
69 os.dup2(pager.stdin.fileno(), sys.stderr.fileno())
70 os.dup2(fdout, sys.stdout.fileno())
70
71 if util.isatty(sys.stderr):
71 @atexit.register
72 os.dup2(fdout, sys.stderr.fileno())
72 def killpager():
73 os.close(fdout)
73 pager.stdin.close()
74 return
74 os.dup2(stdout, sys.stdout.fileno())
75 os.dup2(fdin, sys.stdin.fileno())
75 os.dup2(stderr, sys.stderr.fileno())
76 os.close(fdin)
76 pager.wait()
77 os.close(fdout)
78 try:
79 os.execvp('/bin/sh', ['/bin/sh', '-c', p])
80 except OSError, e:
81 if e.errno == errno.ENOENT:
82 # no /bin/sh, try executing the pager directly
83 args = shlex.split(p)
84 os.execvp(args[0], args)
85 else:
86 raise
87
77
88 def uisetup(ui):
78 def uisetup(ui):
89 if ui.plain() or '--debugger' in sys.argv or not util.isatty(sys.stdout):
79 if ui.plain() or '--debugger' in sys.argv or not util.isatty(sys.stdout):
General Comments 0
You need to be logged in to leave comments. Login now