Merge with stable
authorMatt Mackall <mpm@selenic.com>
Sun, 16 May 2010 14:38:32 -0500
changeset 11186 a890cc501501
parent 11185 6d7cf82453be (current diff)
parent 11182 3c368a1c962d (diff)
child 11189 3ef2572de32f
Merge with stable
hgext/color.py
hgext/pager.py
--- a/hgext/pager.py	Sat May 15 23:33:22 2010 -0400
+++ b/hgext/pager.py	Sun May 16 14:38:32 2010 -0500
@@ -49,9 +49,27 @@
 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 @@
             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)