Patchwork [3,of,3] templatekw: add verbosity keyword to select template by -q/-v/--debug flag

login
register
mail settings
Submitter Yuya Nishihara
Date Nov. 2, 2017, 1:33 p.m.
Message ID <946badd65a139cbb5015.1509629606@mimosa>
Download mbox | patch
Permalink /patch/25347/
State Accepted
Headers show

Comments

Yuya Nishihara - Nov. 2, 2017, 1:33 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1508575601 -32400
#      Sat Oct 21 17:46:41 2017 +0900
# Node ID 946badd65a139cbb50150f23471db136a42d7814
# Parent  369af8fed661bef2b0b061f2eac4c932d4f753ae
templatekw: add verbosity keyword to select template by -q/-v/--debug flag

This can be used in conjunction with the ifeq() function.
Augie Fackler - Nov. 7, 2017, 4:20 p.m.
On Thu, Nov 02, 2017 at 10:33:26PM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1508575601 -32400
> #      Sat Oct 21 17:46:41 2017 +0900
> # Node ID 946badd65a139cbb50150f23471db136a42d7814
> # Parent  369af8fed661bef2b0b061f2eac4c932d4f753ae
> templatekw: add verbosity keyword to select template by -q/-v/--debug flag

queued, thanks

Patch

diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -885,6 +885,19 @@  def showinstabilities(**args):
     return showlist('instability', args['ctx'].instabilities(), args,
                     plural='instabilities')
 
+@templatekeyword('verbosity')
+def showverbosity(ui, **args):
+    """String. The current output verbosity in 'debug', 'quiet', 'verbose',
+    or ''."""
+    # see cmdutil.changeset_templater for priority of these flags
+    if ui.debugflag:
+        return 'debug'
+    elif ui.quiet:
+        return 'quiet'
+    elif ui.verbose:
+        return 'verbose'
+    return ''
+
 def loadkeyword(ui, extname, registrarobj):
     """Load template keyword from specified registrarobj
     """
diff --git a/tests/test-command-template.t b/tests/test-command-template.t
--- a/tests/test-command-template.t
+++ b/tests/test-command-template.t
@@ -2876,6 +2876,17 @@  Test diff function:
   @@ -0,0 +1,1 @@
   +second
 
+ui verbosity:
+
+  $ hg log -l1 -T '{verbosity}\n'
+  
+  $ hg log -l1 -T '{verbosity}\n' --debug
+  debug
+  $ hg log -l1 -T '{verbosity}\n' --quiet
+  quiet
+  $ hg log -l1 -T '{verbosity}\n' --verbose
+  verbose
+
   $ cd ..