##// END OF EJS Templates
pager: fork and exec pager as parent process...
Brodie Rao -
r11182:3c368a1c stable
parent child Browse files
Show More
@@ -333,11 +333,14 b' def extsetup(ui):'
333
333
334 def _setupcmd(ui, cmd, table, func, effectsmap):
334 def _setupcmd(ui, cmd, table, func, effectsmap):
335 '''patch in command to command table and load effect map'''
335 '''patch in command to command table and load effect map'''
336 # check isatty() before anything else changes it (like pager)
337 isatty = sys.__stdout__.isatty()
338
336 def nocolor(orig, *args, **opts):
339 def nocolor(orig, *args, **opts):
337
340
338 if (opts['no_color'] or opts['color'] == 'never' or
341 if (opts['no_color'] or opts['color'] == 'never' or
339 (opts['color'] == 'auto' and (os.environ.get('TERM') == 'dumb'
342 (opts['color'] == 'auto' and (os.environ.get('TERM') == 'dumb'
340 or not sys.__stdout__.isatty()))):
343 or not isatty))):
341 del opts['no_color']
344 del opts['no_color']
342 del opts['color']
345 del opts['color']
343 return orig(*args, **opts)
346 return orig(*args, **opts)
@@ -49,9 +49,27 b' To ignore global commands like "hg versi'
49 specify them in the global .hgrc
49 specify them in the global .hgrc
50 '''
50 '''
51
51
52 import sys, os, signal
52 import sys, os, signal, shlex
53 from mercurial import dispatch, util, extensions
53 from mercurial import dispatch, util, extensions
54
54
55 def _runpager(p):
56 if not hasattr(os, 'fork'):
57 sys.stderr = sys.stdout = util.popen(p, 'wb')
58 return
59 fdin, fdout = os.pipe()
60 pid = os.fork()
61 if pid == 0:
62 os.close(fdin)
63 os.dup2(fdout, sys.stdout.fileno())
64 os.dup2(fdout, sys.stderr.fileno())
65 os.close(fdout)
66 return
67 os.dup2(fdin, sys.stdin.fileno())
68 os.close(fdin)
69 os.close(fdout)
70 args = shlex.split(p)
71 os.execvp(args[0], args)
72
55 def uisetup(ui):
73 def uisetup(ui):
56 def pagecmd(orig, ui, options, cmd, cmdfunc):
74 def pagecmd(orig, ui, options, cmd, cmdfunc):
57 p = ui.config("pager", "pager", os.environ.get("PAGER"))
75 p = ui.config("pager", "pager", os.environ.get("PAGER"))
@@ -60,7 +78,7 b' def uisetup(ui):'
60 if (cmd in attend or
78 if (cmd in attend or
61 (cmd not in ui.configlist('pager', 'ignore') and not attend)):
79 (cmd not in ui.configlist('pager', 'ignore') and not attend)):
62 ui.setconfig('ui', 'interactive', False)
80 ui.setconfig('ui', 'interactive', False)
63 sys.stderr = sys.stdout = util.popen(p, "wb")
81 _runpager(p)
64 if ui.configbool('pager', 'quiet'):
82 if ui.configbool('pager', 'quiet'):
65 signal.signal(signal.SIGPIPE, signal.SIG_DFL)
83 signal.signal(signal.SIGPIPE, signal.SIG_DFL)
66 return orig(ui, options, cmd, cmdfunc)
84 return orig(ui, options, cmd, cmdfunc)
General Comments 0
You need to be logged in to leave comments. Login now