tags: unblock log-like template keywords and functions
authorYuya Nishihara <yuya@tcha.org>
Fri, 08 Jun 2018 22:16:23 +0900
changeset 38430 5d9b765dbe15
parent 38429 8399438bc7ef
child 38431 d6686f864a70
tags: unblock log-like template keywords and functions It checks if ctx will be used in template since loading ctx per revision could take extra 10-100msec in total depending on the number of tags.
mercurial/commands.py
tests/test-tags.t
--- a/mercurial/commands.py	Fri Jun 08 22:10:22 2018 +0900
+++ b/mercurial/commands.py	Fri Jun 08 22:16:23 2018 +0900
@@ -5438,6 +5438,7 @@
     opts = pycompat.byteskwargs(opts)
     ui.pager('tags')
     fm = ui.formatter('tags', opts)
+    contexthint = fm.contexthint('tag rev node type')
     hexfunc = fm.hexfunc
     tagtype = ""
 
@@ -5450,6 +5451,8 @@
             tagtype = 'local'
 
         fm.startitem()
+        if 'ctx' in contexthint:
+            fm.context(ctx=repo[n])
         fm.write('tag', '%s', t, label=label)
         fmt = " " * (30 - encoding.colwidth(t)) + ' %5d:%s'
         fm.condwrite(not ui.quiet, 'rev node', fmt,
--- a/tests/test-tags.t	Fri Jun 08 22:10:22 2018 +0900
+++ b/tests/test-tags.t	Fri Jun 08 22:16:23 2018 +0900
@@ -610,6 +610,27 @@
   localtag                           0:bbd179dfa0a7 local
   globaltag                          0:bbd179dfa0a7
 
+Templated output:
+
+ (immediate values)
+
+  $ hg tags -T '{pad(tag, 9)} {rev}:{node} ({type})\n'
+  tip       1:a0b6fe111088c8c29567d3876cc466aa02927cae ()
+  localtag  0:bbd179dfa0a71671c253b3ae0aa1513b60d199fa (local)
+  globaltag 0:bbd179dfa0a71671c253b3ae0aa1513b60d199fa ()
+
+ (ctx/revcache dependent)
+
+  $ hg tags -T '{pad(tag, 9)} {rev} {file_adds}\n'
+  tip       1 .hgtags
+  localtag  0 foo
+  globaltag 0 foo
+
+  $ hg tags -T '{pad(tag, 9)} {rev}:{node|shortest}\n'
+  tip       1:a0b6
+  localtag  0:bbd1
+  globaltag 0:bbd1
+
 Test for issue3911
 
   $ hg tag -r 0 -l localtag2