[PATCH 6 of 6 STABLE] pager: expand partial commands in pager.attend-% (issue5527)

Gregory Szorc gregory.szorc at gmail.com
Tue Apr 25 03:22:54 EDT 2017


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1493104878 25200
#      Tue Apr 25 00:21:18 2017 -0700
# Branch stable
# Node ID 167dcc29e8d47edb7dbd44c00f3da2927e82471b
# Parent  3dd8a2d6584eb02016a9db1b06eb69ff8f054e2d
pager: expand partial commands in pager.attend-% (issue5527)

Previously, if a pager.attend-% config option is using a partial
command name, the option has no effect because we only look for
config options having exact values of the primary command name and
its full aliases. I think this is a poor end-user experience, as
many users may e.g. type `hg st` and want "pager.attend-st" to
"just work."

This commit implements support for expanding partial command names
and aliases in pager.attend-% config options.

There is a more concise way to implement this feature: just set
pager.attend-<full> when iterating pager.attend-% options. However,
I'm not comfortable setting those options because I'm not sure of
the implications.

We should probably also expand pager.attend and pager.ignore
similarly. I'm starting with this patch to test the waters.

diff --git a/hgext/pager.py b/hgext/pager.py
--- a/hgext/pager.py
+++ b/hgext/pager.py
@@ -40,6 +40,28 @@ def _pagerruncommand(orig, ui, options, 
     if options['pager'] != 'auto' or ui.pageractive:
         return orig(ui, options, cmd, cmdfunc)
 
+    # Expand partial commands in pager.attend-% options.
+    reverseoptions = {}
+    for key, value in ui.configitems('pager'):
+        if not key.startswith('attend-'):
+            continue
+
+        command = key[len('attend-'):]
+        cmds, _ = cmdutil.findpossible(command, commands.table)
+
+        # Exact match. Config entry is fine.
+        if command in cmds:
+            continue
+
+        # Maps to an ambiguous command. No clear action to take.
+        if len(cmds) > 1:
+            continue
+
+        # Else, the name maps to another command. Set the config option.
+        if cmds:
+            actualcommand = cmds.keys()[0]
+            reverseoptions.setdefault(actualcommand, set()).add(command)
+
     usepager = False
     attend = ui.configlist('pager', 'attend', attended)
     ignore = ui.configlist('pager', 'ignore')
@@ -50,6 +72,18 @@ def _pagerruncommand(orig, ui, options, 
         if ui.config('pager', var):
             usepager = ui.configbool('pager', var)
             break
+
+        havereverse = False
+        for reversename in reverseoptions.get(cmd, []):
+            var = 'attend-%s' % reversename
+            if ui.config('pager', var):
+                usepager = ui.configbool('pager', var)
+                havereverse = True
+                break
+
+        if havereverse:
+            break
+
         if (cmd in attend or
                 (cmd not in ignore and not attend)):
             usepager = True
diff --git a/tests/test-pager.t b/tests/test-pager.t
--- a/tests/test-pager.t
+++ b/tests/test-pager.t
@@ -94,13 +94,14 @@ Abbreviated command alias should also be
   paged! 'summary:     modify a 10\n'
   paged! '\n'
 
-Attend for an abbreviated command does not work
+Attend for an abbreviated command works
+(TODO broken without pager extension enabled)
 
   $ hg --config pager.attend-ident=true ident
   46106edeeb38 tip
 
   $ hg --config extensions.pager= --config pager.attend-ident=true ident
-  46106edeeb38 tip
+  paged! '46106edeeb38 tip\n'
 
 Pager should not start if stdout is not a tty.
 


More information about the Mercurial-devel mailing list