Patchwork [2,of,8] templater: add revdesc function

login
register
mail settings
Submitter timeless@mozdev.org
Date Sept. 11, 2015, 3:36 a.m.
Message ID <cc0d4af57610091f9e63.1441942600@waste.org>
Download mbox | patch
Permalink /patch/10479/
State Rejected
Headers show

Comments

timeless@mozdev.org - Sept. 11, 2015, 3:36 a.m.
# HG changeset patch
# User timeless@mozdev.org
# Date 1441937881 14400
#      Thu Sep 10 22:18:01 2015 -0400
# Node ID cc0d4af57610091f9e637dd3a4b11f4ae6b78498
# Parent  404f89e718a2866eaed6eef778b9eafe00f1f9ae
templater: add revdesc function

revdesc takes a revision and returns its description

for use like:
  {revset("...") % "{revision|revdesc}"}
Yuya Nishihara - Sept. 11, 2015, 3:45 p.m.
On Thu, 10 Sep 2015 22:36:40 -0500, timeless@mozdev.org wrote:
> # HG changeset patch
> # User timeless@mozdev.org
> # Date 1441937881 14400
> #      Thu Sep 10 22:18:01 2015 -0400
> # Node ID cc0d4af57610091f9e637dd3a4b11f4ae6b78498
> # Parent  404f89e718a2866eaed6eef778b9eafe00f1f9ae
> templater: add revdesc function
> 
> revdesc takes a revision and returns its description
> 
> for use like:
>   {revset("...") % "{revision|revdesc}"}

I don't think it's good idea to add rev*() function for each template keyword.
Instead, we can

 a. switch the ctx by revset(), which is a behavior change

    {revset("...") % "{desc}"}
                     ~~~~~~~~
                     here mapping['ctx'] points to repo[revision]

 b. add function or operator that switches the ctx

    {revset("...") % "{desc[revision]}"}
    or
    {revset("...") % "{xxx(revision, desc)}"}
    or
    {revset("...")|xxx % "{desc}"}

> +  $ hg log -r 0 --template '{revset("0::0") % "summary:\t{revision|revdesc|firstline}\n"}\n'
> +  summary:	A1B1C1

Is there a real-world example how rev*() function will be used effectively?
Maybe it should be listed in help/templates.txt.

Regards,
timeless - Sept. 11, 2015, 5:40 p.m.
A real world example is something like revset(children(...)) %
{display information as one would for log per child}.

The previous patch included a full test template for log output, in
this series, pushgate stopped submitting patches at 8 (iirc the full
test was #11).

On Fri, Sep 11, 2015 at 11:45 AM, Yuya Nishihara <yuya@tcha.org> wrote:
> On Thu, 10 Sep 2015 22:36:40 -0500, timeless@mozdev.org wrote:
>> # HG changeset patch
>> # User timeless@mozdev.org
>> # Date 1441937881 14400
>> #      Thu Sep 10 22:18:01 2015 -0400
>> # Node ID cc0d4af57610091f9e637dd3a4b11f4ae6b78498
>> # Parent  404f89e718a2866eaed6eef778b9eafe00f1f9ae
>> templater: add revdesc function
>>
>> revdesc takes a revision and returns its description
>>
>> for use like:
>>   {revset("...") % "{revision|revdesc}"}
>
> I don't think it's good idea to add rev*() function for each template keyword.
> Instead, we can
>
>  a. switch the ctx by revset(), which is a behavior change
>
>     {revset("...") % "{desc}"}
>                      ~~~~~~~~
>                      here mapping['ctx'] points to repo[revision]
>
>  b. add function or operator that switches the ctx
>
>     {revset("...") % "{desc[revision]}"}
>     or
>     {revset("...") % "{xxx(revision, desc)}"}
>     or
>     {revset("...")|xxx % "{desc}"}
>
>> +  $ hg log -r 0 --template '{revset("0::0") % "summary:\t{revision|revdesc|firstline}\n"}\n'
>> +  summary:   A1B1C1
>
> Is there a real-world example how rev*() function will be used effectively?
> Maybe it should be listed in help/templates.txt.
>
> Regards,
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -554,6 +554,12 @@ 
     ctx = repo[rev]
     return ctx, repo
 
+def revdesc(context, mapping, args):
+    """:revdesc(rev): Show description.
+    See :hg:`help templates.desc`."""
+    ctx, repo = ctxrepo('revdesc', context, mapping, args)
+    return ctx.description().strip()
+
 def revset(context, mapping, args):
     """:revset(query[, formatargs...]): Execute a revision set query. See
     :hg:`help revset`."""
@@ -749,6 +755,7 @@ 
     "label": label,
     "localdate": localdate,
     "pad": pad,
+    "revdesc": revdesc,
     "revset": revset,
     "rstdoc": rstdoc,
     "shortest": shortest,
diff --git a/tests/test-log.t b/tests/test-log.t
--- a/tests/test-log.t
+++ b/tests/test-log.t
@@ -2094,4 +2094,15 @@ 
      date:        Thu Jan 01 00:00:00 1970 +0000
      summary:     A1B1C1
   
+Verify rev*() template functions
+
+  $ hg log -r 0 --template '{revset("0::0") % "changeset:\t{revision}\n"}\n'
+  changeset:	0
+  
+  $ hg log -r 0 --template '{revset("0::0") % "summary:\t{revision|revdesc|firstline}\n"}\n'
+  summary:	A1B1C1
+  
+  $ hg log -r . --template '{revdesc()}'
+  hg: parse error: revdesc expects one argument
+  [255]
   $ cd ..