Patchwork pager: improve support for various flavors of `more` on Windows

login
register
mail settings
Submitter Matt Harbison
Date March 25, 2017, 2:56 a.m.
Message ID <6ee410f4af75125e9984.1490410600@Envy>
Download mbox | patch
Permalink /patch/19653/
State Accepted
Headers show

Comments

Matt Harbison - March 25, 2017, 2:56 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1490409608 14400
#      Fri Mar 24 22:40:08 2017 -0400
# Node ID 6ee410f4af75125e9984c42100285ee70501655c
# Parent  62728577ba63efee83460a09ef311b330a5fea13
pager: improve support for various flavors of `more` on Windows

Hardcoding 'more' -> 'more.com' means that 'more.exe' from MSYS would need to be
configured with its *.exe extension.  This will resolve to either one, as
cmd.exe would have done if the command ran through the shell.

Something that's maybe problematic with this is it comes after 'pageractive' and
various ui configs have been set by the calling method.  But the other early
exits in this method don't undo those changes either.
Yuya Nishihara - March 25, 2017, 5:12 a.m.
On Fri, 24 Mar 2017 22:56:40 -0400, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1490409608 14400
> #      Fri Mar 24 22:40:08 2017 -0400
> # Node ID 6ee410f4af75125e9984c42100285ee70501655c
> # Parent  62728577ba63efee83460a09ef311b330a5fea13
> pager: improve support for various flavors of `more` on Windows

Looks good, queued, thanks.

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -844,15 +844,6 @@ 
         if not pagercmd:
             return
 
-        if pycompat.osname == 'nt':
-            # `more` cannot be invoked with shell=False, but `more.com` can.
-            # Hide this implementation detail from the user, so we can also get
-            # sane bad PAGER behavior.  If args are also given, the space in the
-            # command line forces shell=True, so that case doesn't need to be
-            # handled here.
-            if pagercmd == 'more':
-                pagercmd = 'more.com'
-
         self.debug('starting pager for command %r\n' % command)
         self.flush()
         self.pageractive = True
@@ -879,6 +870,21 @@ 
         # simple pager command configurations, we can degrade
         # gracefully and tell the user about their broken pager.
         shell = any(c in command for c in "|&;<>()$`\\\"' \t\n*?[#~=%")
+
+        if pycompat.osname == 'nt' and not shell:
+            # Window's built-in `more` cannot be invoked with shell=False, but
+            # its `more.com` can.  Hide this implementation detail from the
+            # user so we can also get sane bad PAGER behavior.  MSYS has
+            # `more.exe`, so do a cmd.exe style resolution of the executable to
+            # determine which one to use.
+            fullcmd = util.findexe(command)
+            if not fullcmd:
+                self.warn(_("missing pager command '%s', skipping pager\n")
+                          % command)
+                return
+
+            command = fullcmd
+
         try:
             pager = subprocess.Popen(
                 command, shell=shell, bufsize=-1,