Patchwork [2,of,6,STABLE] pager: extract wrapped _runcommand function

login
register
mail settings
Submitter Gregory Szorc
Date April 25, 2017, 7:22 a.m.
Message ID <eb7d6dc353a3db12d159.1493104970@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/20290/
State Deferred
Headers show

Comments

Gregory Szorc - April 25, 2017, 7:22 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1493103445 25200
#      Mon Apr 24 23:57:25 2017 -0700
# Branch stable
# Node ID eb7d6dc353a3db12d1592bdc80233a270dfd90df
# Parent  a0ea86dd4d27b7ca7eb7c1e63cf6fb4a96b3cbe0
pager: extract wrapped _runcommand function

The function doesn't need to be inline in uisetup(). Let's extract it
to increase reading comprehension.

Patch

diff --git a/hgext/pager.py b/hgext/pager.py
--- a/hgext/pager.py
+++ b/hgext/pager.py
@@ -36,40 +36,39 @@  from mercurial import (
 # leave the attribute unspecified.
 testedwith = 'ships-with-hg-core'
 
-def uisetup(ui):
-
-    def pagecmd(orig, ui, options, cmd, cmdfunc):
-        if options['pager'] != 'auto' or ui.pageractive:
-            return orig(ui, options, cmd, cmdfunc)
-
-        usepager = False
-        attend = ui.configlist('pager', 'attend', attended)
-        ignore = ui.configlist('pager', 'ignore')
-        cmds, _ = cmdutil.findcmd(cmd, commands.table)
-
-        for cmd in cmds:
-            var = 'attend-%s' % cmd
-            if ui.config('pager', var):
-                usepager = ui.configbool('pager', var)
-                break
-            if (cmd in attend or
-                 (cmd not in ignore and not attend)):
-                usepager = True
-                break
-
-        if usepager:
-            # Slight hack: the attend list is supposed to override
-            # the ignore list for the pager extension, but the
-            # core code doesn't know about attend, so we have to
-            # lobotomize the ignore list so that the extension's
-            # behavior is preserved.
-            ui.setconfig('pager', 'ignore', '', 'pager')
-            ui.pager('extension-via-attend-' + cmd)
-        else:
-            ui.disablepager()
-
+def _pagerruncommand(orig, ui, options, cmd, cmdfunc):
+    if options['pager'] != 'auto' or ui.pageractive:
         return orig(ui, options, cmd, cmdfunc)
 
-    extensions.wrapfunction(dispatch, '_runcommand', pagecmd)
+    usepager = False
+    attend = ui.configlist('pager', 'attend', attended)
+    ignore = ui.configlist('pager', 'ignore')
+    cmds, _ = cmdutil.findcmd(cmd, commands.table)
+
+    for cmd in cmds:
+        var = 'attend-%s' % cmd
+        if ui.config('pager', var):
+            usepager = ui.configbool('pager', var)
+            break
+        if (cmd in attend or
+                (cmd not in ignore and not attend)):
+            usepager = True
+            break
+
+    if usepager:
+        # Slight hack: the attend list is supposed to override
+        # the ignore list for the pager extension, but the
+        # core code doesn't know about attend, so we have to
+        # lobotomize the ignore list so that the extension's
+        # behavior is preserved.
+        ui.setconfig('pager', 'ignore', '', 'pager')
+        ui.pager('extension-via-attend-' + cmd)
+    else:
+        ui.disablepager()
+
+    return orig(ui, options, cmd, cmdfunc)
+
+def uisetup(ui):
+    extensions.wrapfunction(dispatch, '_runcommand', _pagerruncommand)
 
 attended = ['annotate', 'cat', 'diff', 'export', 'glog', 'log', 'qdiff']