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

login
register
mail settings
Submitter Matthew Turk
Date Nov. 21, 2013, 9:04 p.m.
Message ID <3d7f6e0ad51047f4eacf.1385067865@ridcully>
Download mbox | patch
Permalink /patch/3076/
State Superseded
Headers show

Comments

Matthew Turk - Nov. 21, 2013, 9:04 p.m.
# HG changeset patch
# User Matthew Turk <matthewturk@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.
Augie Fackler - Dec. 14, 2013, 4:56 p.m.
On Thu, Nov 21, 2013 at 04:04:25PM -0500, Matthew Turk wrote:
> # HG changeset patch
> # User Matthew Turk <matthewturk@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"

I'm confused. Is there some magic in the templater that causes the
get() call to use extrakeys?

>
> 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,
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
Matthew Turk - Dec. 14, 2013, 6:01 p.m.
On Sat, Dec 14, 2013 at 11:56 AM, Augie Fackler <raf@durin42.com> wrote:
> On Thu, Nov 21, 2013 at 04:04:25PM -0500, Matthew Turk wrote:
>> # HG changeset patch
>> # User Matthew Turk <matthewturk@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"
>
> I'm confused. Is there some magic in the templater that causes the
> get() call to use extrakeys?

Nope, I messed up the commit message.  I'll resend this this week, and
address the other comment on patch 1 as well, although I understand
they may end up being declined.

-Matt

>
>>
>> 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,
>> _______________________________________________
>> Mercurial-devel mailing list
>> Mercurial-devel@selenic.com
>> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

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,