[PATCH 3 of 3] template: add extrakeys (dict) keyword to templater

Matthew Turk matthewturk at gmail.com
Thu Nov 21 15:04:25 CST 2013


# HG changeset patch
# User Matthew Turk <matthewturk at gmail.com>
# Date 1385067325 18000
#      Thu Nov 21 15:55:25 2013 -0500
# Node ID 3d7f6e0ad51047f4eacf68abcba12dcaecb0081b
# Parent  547837e59d439af3c907931ca65cab911d00dfe3
template: add extrakeys (dict) keyword to templater

This returns the 'extras' dictionary to the templater.  It enables utilization
of templates such as:

hg log -r 0 --template "{get(extras, 'convert_revision')}\n"

where 'convert_revision' is the key in the 'extras' dictionary.  This should
allow for subsequent template styles to be written that perform meaningful
queries on the extras dict, for use in things like repository conversions,
additional metadata and so on.

For example, in my primary project repository, extras contains amend_source,
branch, close, convert_revision, rebase_source, source, transplant_source.

diff -r 547837e59d43 -r 3d7f6e0ad510 mercurial/templatekw.py
--- a/mercurial/templatekw.py	Thu Nov 21 15:47:26 2013 -0500
+++ b/mercurial/templatekw.py	Thu Nov 21 15:55:25 2013 -0500
@@ -226,6 +226,10 @@
     f = _showlist('extra', c, plural='extras', **args)
     return _hybrid(f, c, lambda x: '%s=%s' % (x['key'], x['value']))
 
+def showextrakeys(**args):
+    """:extrakeys: The 'extras' attribute as a dict."""
+    return args['ctx'].extra()
+
 def showfileadds(**args):
     """:file_adds: List of strings. Files added by this changeset."""
     repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
@@ -362,6 +366,7 @@
     'desc': showdescription,
     'diffstat': showdiffstat,
     'extras': showextras,
+    'extrakeys': showextrakeys,
     'file_adds': showfileadds,
     'file_copies': showfilecopies,
     'file_copies_switch': showfilecopiesswitch,


More information about the Mercurial-devel mailing list