Patchwork [STABLE] help: add example of '[templates]' usage

login
register
mail settings
Submitter Mathias De Maré
Date Aug. 8, 2016, 2:53 p.m.
Message ID <bbcf7bff5bac8b56b619.1470667985@waste.org>
Download mbox | patch
Permalink /patch/16197/
State Superseded
Headers show

Comments

Mathias De Maré - Aug. 8, 2016, 2:53 p.m.
# HG changeset patch
# User Mathias De Maré <mathias.demare@gmail.com>
# Date 1470667662 -7200
#      Mon Aug 08 16:47:42 2016 +0200
# Branch stable
# Node ID bbcf7bff5bac8b56b61942a50a562f0d45448297
# Parent  b8f9cdca88077e97d4869320b9d18481fbe252ef
help: add example of '[templates]' usage
Anton Shestakov - Aug. 8, 2016, 3:47 p.m.
08.08.2016, 22:53, "Mathias De Mar" <mathias.demare@gmail.com>:
> # HG changeset patch
> # User Mathias De Maré <mathias.demare@gmail.com>
> # Date 1470667662 -7200
> # Mon Aug 08 16:47:42 2016 +0200
> # Branch stable
> # Node ID bbcf7bff5bac8b56b61942a50a562f0d45448297
> # Parent b8f9cdca88077e97d4869320b9d18481fbe252ef
> help: add example of '[templates]' usage
>
> diff --git a/mercurial/help/templates.txt b/mercurial/help/templates.txt
> --- a/mercurial/help/templates.txt
> +++ b/mercurial/help/templates.txt
> @@ -71,6 +71,21 @@
>  defines two symbol aliases, ``r`` and ``rn``, and a function alias
>  ``leftpad()``.
>
> +It's also possible to specify entirely new template commands,
> +using the ``templates`` section.
> +The syntax is the same as with ``templatealias``.

Nit: superfluous line break.

> +
> +For example,
> +
> +::
> +
> + [templates]
> + short = "{shortest(node, 8)}"

Nit: minlength of 8 is not very useful at all, here's what it's like on the hg repo:

$ hg log -T '{shortest(node, 8)|count}\n' | sort -u
8

So it's literally just wasting time checking that the first 8 characters are unique (and they all are for almost 30k changesets). smartlog template uses the default minlength of 4. Bitbucket, for example, shows just first 7 symbols (without any checks that shortest() does, even).

> +
> +defines a template, ``short``, which can be called like::
> +
> + $ hg log -r . -Tshort
> +

It probably should point out the difference between templatealias and templates.

(hg help config also doesn't mention [templates], only web.templates)
Yuya Nishihara - Aug. 8, 2016, 3:48 p.m.
On Mon, 08 Aug 2016 09:53:05 -0500, Mathias De Maré wrote:
> # HG changeset patch
> # User Mathias De Maré <mathias.demare@gmail.com>
> # Date 1470667662 -7200
> #      Mon Aug 08 16:47:42 2016 +0200
> # Branch stable
> # Node ID bbcf7bff5bac8b56b61942a50a562f0d45448297
> # Parent  b8f9cdca88077e97d4869320b9d18481fbe252ef
> help: add example of '[templates]' usage
> 
> diff --git a/mercurial/help/templates.txt b/mercurial/help/templates.txt
> --- a/mercurial/help/templates.txt
> +++ b/mercurial/help/templates.txt
> @@ -71,6 +71,21 @@
>  defines two symbol aliases, ``r`` and ``rn``, and a function alias
>  ``leftpad()``.
>  
> +It's also possible to specify entirely new template commands,
> +using the ``templates`` section.
> +The syntax is the same as with ``templatealias``.

Nit: they aren't exactly the same. Aliases are expressions, but templates
are template strings, e.g.

  [templatealias]
  # function = function
  utcdate(date) = localdate(date, "UTC")
  # keyword = '"' template-string '"' ('"' starts a template string)
  revnode = "{rev}:{node|short}"

  [templates]
  # name = template-string (optionally quoted)
  short = "{shortest(node, 8)}"

Maybe we can say "the same as ``ui.logtemplate``."
Mathias De Maré - Aug. 8, 2016, 4:11 p.m.
On Mon, Aug 8, 2016 at 5:47 PM, Anton Shestakov <engored@ya.ru> wrote:

> 08.08.2016, 22:53, "Mathias De Mar" <mathias.demare@gmail.com>:
> > # HG changeset patch
> > # User Mathias De Maré <mathias.demare@gmail.com>
> > # Date 1470667662 -7200
> > # Mon Aug 08 16:47:42 2016 +0200
> > # Branch stable
> > # Node ID bbcf7bff5bac8b56b61942a50a562f0d45448297
> > # Parent b8f9cdca88077e97d4869320b9d18481fbe252ef
> > help: add example of '[templates]' usage
> >
> > diff --git a/mercurial/help/templates.txt b/mercurial/help/templates.txt
> > --- a/mercurial/help/templates.txt
> > +++ b/mercurial/help/templates.txt
> > @@ -71,6 +71,21 @@
> >  defines two symbol aliases, ``r`` and ``rn``, and a function alias
> >  ``leftpad()``.
> >
> > +It's also possible to specify entirely new template commands,
> > +using the ``templates`` section.
> > +The syntax is the same as with ``templatealias``.
>
> Nit: superfluous line break.
>
Thanks, I'll change this.

>
> > +
> > +For example,
> > +
> > +::
> > +
> > + [templates]
> > + short = "{shortest(node, 8)}"
>
> Nit: minlength of 8 is not very useful at all, here's what it's like on
> the hg repo:
>
> $ hg log -T '{shortest(node, 8)|count}\n' | sort -u
> 8
>
> So it's literally just wasting time checking that the first 8 characters
> are unique (and they all are for almost 30k changesets). smartlog template
> uses the default minlength of 4. Bitbucket, for example, shows just first 7
> symbols (without any checks that shortest() does, even).
>

Thanks, I'll change it to 4.

>
> > +
> > +defines a template, ``short``, which can be called like::
> > +
> > + $ hg log -r . -Tshort
> > +
>
> It probably should point out the difference between templatealias and
> templates.
>
> (hg help config also doesn't mention [templates], only web.templates)
>

Thanks, I'll mention the difference and will add [templates] to config.txt
as well.


On Mon, Aug 8, 2016 at 5:48 PM, Yuya Nishihara <yuya@tcha.org> wrote:

> On Mon, 08 Aug 2016 09:53:05 -0500, Mathias De Maré wrote:
> > +It's also possible to specify entirely new template commands,
> > +using the ``templates`` section.
> > +The syntax is the same as with ``templatealias``.
>
> Nit: they aren't exactly the same. Aliases are expressions, but templates
> are template strings, e.g.
>
>   [templatealias]
>   # function = function
>   utcdate(date) = localdate(date, "UTC")
>   # keyword = '"' template-string '"' ('"' starts a template string)
>   revnode = "{rev}:{node|short}"
>
>   [templates]
>   # name = template-string (optionally quoted)
>   short = "{shortest(node, 8)}"
>
> Maybe we can say "the same as ``ui.logtemplate``."
>

I'll mention the difference, but I won't compare to ui.logtemplate (as
that's not mentioned in templates.txt).

I'll resubmit with the comments addressed.

Patch

diff --git a/mercurial/help/templates.txt b/mercurial/help/templates.txt
--- a/mercurial/help/templates.txt
+++ b/mercurial/help/templates.txt
@@ -71,6 +71,21 @@ 
 defines two symbol aliases, ``r`` and ``rn``, and a function alias
 ``leftpad()``.
 
+It's also possible to specify entirely new template commands,
+using the ``templates`` section.
+The syntax is the same as with ``templatealias``.
+
+For example,
+
+::
+
+  [templates]
+  short = "{shortest(node, 8)}"
+
+defines a template, ``short``, which can be called like::
+
+  $ hg log -r . -Tshort
+
 Some sample command line templates:
 
 - Format lists, e.g. files::