diff --git a/hgext/pager.py b/hgext/pager.py --- a/hgext/pager.py +++ b/hgext/pager.py @@ -49,9 +49,27 @@ To ignore global commands like :hg:`vers to specify them in the global .hgrc ''' -import sys, os, signal +import sys, os, signal, shlex from mercurial import dispatch, util, extensions +def _runpager(p): + if not hasattr(os, 'fork'): + sys.stderr = sys.stdout = util.popen(p, 'wb') + return + fdin, fdout = os.pipe() + pid = os.fork() + if pid == 0: + os.close(fdin) + os.dup2(fdout, sys.stdout.fileno()) + os.dup2(fdout, sys.stderr.fileno()) + os.close(fdout) + return + os.dup2(fdin, sys.stdin.fileno()) + os.close(fdin) + os.close(fdout) + args = shlex.split(p) + os.execvp(args[0], args) + def uisetup(ui): def pagecmd(orig, ui, options, cmd, cmdfunc): p = ui.config("pager", "pager", os.environ.get("PAGER")) @@ -60,7 +78,7 @@ def uisetup(ui): if (cmd in attend or (cmd not in ui.configlist('pager', 'ignore') and not attend)): ui.setconfig('ui', 'interactive', False) - sys.stderr = sys.stdout = util.popen(p, "wb") + _runpager(p) if ui.configbool('pager', 'quiet'): signal.signal(signal.SIGPIPE, signal.SIG_DFL) return orig(ui, options, cmd, cmdfunc)