[PATCH 2 of 2 pager-dispatch-tweaks] dispatch: rearrange 'unknown command' code to better employ pager

Augie Fackler raf at durin42.com
Tue Feb 21 16:14:53 EST 2017


# HG changeset patch
# User Augie Fackler <augie at google.com>
# Date 1487704805 18000
#      Tue Feb 21 14:20:05 2017 -0500
# Node ID 52083816be40edfac2e3e052ebe4d828c6c4a1c6
# Parent  f489d1ec2070f25a09f571177b97d8284b3b1932
dispatch: rearrange 'unknown command' code to better employ pager

dispatch calls help like a ninja if you give it a truly unknown
command, and that might want to be paged. If it gets paged, then the
'hg: unknown command' text gets eaten by a grue, unless we call the
pager first. This change rearranges the codepaths so we can safely
only invoke the pager in the case where we'll have long output from
the help command code, rather than just a short message like "did you
mean stat instead of start" or "fetch is provided by the fetch
extension".

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -33,6 +33,7 @@ from . import (
     extensions,
     fancyopts,
     fileset,
+    help,
     hg,
     hook,
     profiling,
@@ -242,19 +243,24 @@ def callcatch(ui, func):
         _formatparse(ui.warn, inst)
         return -1
     except error.UnknownCommand as inst:
-        ui.warn(_("hg: unknown command '%s'\n") % inst.args[0])
+        nocmdmsg = _("hg: unknown command '%s'\n") % inst.args[0]
         try:
             # check if the command is in a disabled extension
             # (but don't check for extensions themselves)
-            commands.help_(ui, inst.args[0], unknowncmd=True)
+            formatted = help.formattedhelp(ui, inst.args[0], unknowncmd=True)
+            ui.warn(nocmdmsg)
+            ui.write(formatted)
         except (error.UnknownCommand, error.Abort):
             suggested = False
             if len(inst.args) == 2:
                 sim = _getsimilar(inst.args[1], inst.args[0])
                 if sim:
+                    ui.warn(nocmdmsg)
                     _reportsimilar(ui.warn, sim)
                     suggested = True
             if not suggested:
+                ui.pager('help')
+                ui.warn(nocmdmsg)
                 commands.help_(ui, 'shortlist')
     except IOError:
         raise


More information about the Mercurial-devel mailing list