Patchwork [1,of,6,STABLE] pager: unindent large block

login
register
mail settings
Submitter Gregory Szorc
Date April 25, 2017, 7:22 a.m.
Message ID <a0ea86dd4d27b7ca7eb7.1493104969@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/20291/
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 1493103578 25200
#      Mon Apr 24 23:59:38 2017 -0700
# Branch stable
# Node ID a0ea86dd4d27b7ca7eb7c1e63cf6fb4a96b3cbe0
# Parent  40cf693fc07d846502f9c15a1602880ca99d7b56
pager: unindent large block

I like using early return to avoid long indented blocks.

While I was here, I inlined the "auto" variable.

Patch

diff --git a/hgext/pager.py b/hgext/pager.py
--- a/hgext/pager.py
+++ b/hgext/pager.py
@@ -39,33 +39,35 @@  testedwith = 'ships-with-hg-core'
 def uisetup(ui):
 
     def pagecmd(orig, ui, options, cmd, cmdfunc):
-        auto = options['pager'] == 'auto'
-        if auto and not ui.pageractive:
-            usepager = False
-            attend = ui.configlist('pager', 'attend', attended)
-            ignore = ui.configlist('pager', 'ignore')
-            cmds, _ = cmdutil.findcmd(cmd, commands.table)
+        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
+        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()
+        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)
 
     extensions.wrapfunction(dispatch, '_runcommand', pagecmd)