[PATCH V2] pager: fix the invocation of `more` on Windows

Matt Harbison mharbison72 at gmail.com
Tue Mar 21 22:58:30 EDT 2017


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1489983573 14400
#      Mon Mar 20 00:19:33 2017 -0400
# Node ID 8c2e2e2b2432bfa637ee569de11afcbc02b715b7
# Parent  d0b9e9803caff5f87020688c49ac6cdf017039d7
pager: fix the invocation of `more` on Windows

After 9335dc6b2a9c, with 'shell' being (mostly) set to False, invoking `more` no
longer worked.  Instead, a warning was printed and the pager was disabled.
Invoking `more.com` works.  Since a user may have configured 'pager.pager=more',
do this substitution at the end.  Surprisingly, `more` does allow for arguments,
so those are preserved.  This also allows `more` to work in MSYS.

Setting 'shell=False' runs the executable via CreateProcess(), which has rather
wonky rules for resolving an executable without an extension [1].  Resolving to
*.com is not among them.  Since 'shell=True' yields a cryptic error for a bad
$PAGER, and a *.exe program will work without specifying the extension, sticking
with current 'shell=False' seems like the right thing to do.  I don't think
there are any other *.com pagers out there, so this one special case seems OK.

If somebody wants to do something crazy that requires cmd.exe, I was able to get
normal paged output with 'pager.pager="cmd.exe /c more"'.  I assume you can
replace `more` with *.bat, *.vbs or various other creatures listed in $PATHEXT.

[1] https://msdn.microsoft.com/en-us/library/windows/desktop/ms682425(v=vs.85).aspx

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -844,6 +844,13 @@
         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 pagercmd == 'more' or pagercmd.startswith('more '):
+                pagercmd = 'more.com' + pagercmd[4:]
+
         self.debug('starting pager for command %r\n' % command)
         self.flush()
         self.pageractive = True


More information about the Mercurial-devel mailing list