Patchwork [6,of,6] changeset_templater: render template specified by templatespec tuple

login
register
mail settings
Submitter Yuya Nishihara
Date June 15, 2017, 2:52 p.m.
Message ID <c69382a6d901cd7924d2.1497538352@mimosa>
Download mbox | patch
Permalink /patch/21393/
State Accepted
Headers show

Comments

Yuya Nishihara - June 15, 2017, 2:52 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1491914304 -32400
#      Tue Apr 11 21:38:24 2017 +0900
# Node ID c69382a6d901cd7924d2406bbc544def75571db5
# Parent  5befb37abfc78fc575246560ae6358386a700887
changeset_templater: render template specified by templatespec tuple
via Mercurial-devel - June 16, 2017, 4:26 a.m.
On Thu, Jun 15, 2017 at 7:52 AM, Yuya Nishihara <yuya@tcha.org> wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1491914304 -32400
> #      Tue Apr 11 21:38:24 2017 +0900
> # Node ID c69382a6d901cd7924d2406bbc544def75571db5
> # Parent  5befb37abfc78fc575246560ae6358386a700887
> changeset_templater: render template specified by templatespec tuple

Queued, thanks. I assume the longer-term goal is to allow templating
of non-changsets. Thanks for working on that.
Yuya Nishihara - June 16, 2017, 12:54 p.m.
On Thu, 15 Jun 2017 21:26:01 -0700, Martin von Zweigbergk wrote:
> On Thu, Jun 15, 2017 at 7:52 AM, Yuya Nishihara <yuya@tcha.org> wrote:
> > # HG changeset patch
> > # User Yuya Nishihara <yuya@tcha.org>
> > # Date 1491914304 -32400
> > #      Tue Apr 11 21:38:24 2017 +0900
> > # Node ID c69382a6d901cd7924d2406bbc544def75571db5
> > # Parent  5befb37abfc78fc575246560ae6358386a700887
> > changeset_templater: render template specified by templatespec tuple
> 
> Queued, thanks. I assume the longer-term goal is to allow templating
> of non-changsets. Thanks for working on that.

The goal is slightly different, which will be partly included in the next
series. Thanks for reviewing.
Gregory Szorc - June 16, 2017, 3:59 p.m.
> On Jun 16, 2017, at 06:54, Yuya Nishihara <yuya@tcha.org> wrote:
> 
>> On Thu, 15 Jun 2017 21:26:01 -0700, Martin von Zweigbergk wrote:
>>> On Thu, Jun 15, 2017 at 7:52 AM, Yuya Nishihara <yuya@tcha.org> wrote:
>>> # HG changeset patch
>>> # User Yuya Nishihara <yuya@tcha.org>
>>> # Date 1491914304 -32400
>>> #      Tue Apr 11 21:38:24 2017 +0900
>>> # Node ID c69382a6d901cd7924d2406bbc544def75571db5
>>> # Parent  5befb37abfc78fc575246560ae6358386a700887
>>> changeset_templater: render template specified by templatespec tuple
>> 
>> Queued, thanks. I assume the longer-term goal is to allow templating
>> of non-changsets. Thanks for working on that.
> 
> The goal is slightly different, which will be partly included in the next
> series. Thanks for reviewing.

I didn't see this series and also made invasive changes to changeset_templater yesterday as part of working on show!

Your changes look great and I'll rebase my work. But now I wonder if we'll conflict with each other going forward. Here's what I was doing:

* allow changeset_templater to be constructed from a templater instance (show already has one loaded from a map file)
* allows specifying a prefix for template names so multiple *changeset keys can be defined in the same map file

My goal is to get show using the full map file based templater so other templates in the file can be referenced so there isn't a lot of duplication and long templates. I also wanted to facilitate variations of the changeset templates within the same map file.

You are the domain expert here, so if I beat you to a patchbomb, I'd encourage others to wait for Yuya's series, as it will probably be better.
Yuya Nishihara - June 16, 2017, 4:41 p.m.
On Fri, 16 Jun 2017 09:59:14 -0600, Gregory Szorc wrote:
> Your changes look great and I'll rebase my work. But now I wonder if we'll conflict with each other going forward. Here's what I was doing:
> 
> * allow changeset_templater to be constructed from a templater instance (show already has one loaded from a map file)

That's probably okay, but I think "show" shouldn't create a formatter when
changeset_templater is needed. Creating formatter (or changeset_templater)
may have a side effect such as printing a document header.

> * allows specifying a prefix for template names so multiple *changeset keys can be defined in the same map file

Yeah, I was thinking about that. The current API isn't the best for "show",
but perhaps that can be doable by passing result of
lookuptemplate(ui, 'showwork', opts['template']) to changeset_templater.

> My goal is to get show using the full map file based templater so other templates in the file can be referenced so there isn't a lot of duplication and long templates. I also wanted to facilitate variations of the changeset templates within the same map file.
> 
> You are the domain expert here, so if I beat you to a patchbomb, I'd encourage others to wait for Yuya's series, as it will probably be better.

Anyway, templater patches will be reviewed by me. ;)

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1593,7 +1593,9 @@  class changeset_templater(changeset_prin
             (self.ui.debugflag, 'debug'),
         ]
 
-        self._parts = {'header': '', 'footer': '', 'changeset': 'changeset',
+        self._tref = tmplspec.ref
+        self._parts = {'header': '', 'footer': '',
+                       tmplspec.ref: tmplspec.ref,
                        'docheader': '', 'docfooter': ''}
         for mode, postfix in tmplmodes:
             for t in self._parts:
@@ -1637,7 +1639,7 @@  class changeset_templater(changeset_prin
                     self.ui.write(h)
 
         # write changeset metadata, then patch if requested
-        key = self._parts['changeset']
+        key = self._parts[self._tref]
         self.ui.write(templater.stringify(self.t(key, **props)))
         self.showpatch(ctx, matchfn)