hgext/pager.py
branchstable
changeset 11182 3c368a1c962d
parent 10516 80a1161bc3b5
child 11186 a890cc501501
child 11240 ccb4057e19e6
--- a/hgext/pager.py	Thu May 13 11:30:50 2010 -0500
+++ b/hgext/pager.py	Mon May 03 14:00:34 2010 -0500
@@ -49,9 +49,27 @@
 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)