[PATCH 2 of 6 STABLE] pager: extract wrapped _runcommand function
Gregory Szorc
gregory.szorc at gmail.com
Tue Apr 25 03:22:50 EDT 2017
# HG changeset patch
# User Gregory Szorc <gregory.szorc at 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.
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']
More information about the Mercurial-devel
mailing list