Patchwork [15,of,15] cmdutil: use '[committemplate]' section like as map file for style definition

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Aug. 2, 2014, 1:02 p.m.
Message ID <ee832d729d973bd5e60f.1406984544@feefifofum>
Download mbox | patch
Permalink /patch/5243/
State Accepted
Commit de5cee8ba0880b336b323c4cc1130dee3ecdcaed
Headers show

Comments

Katsunori FUJIWARA - Aug. 2, 2014, 1:02 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1406983587 -32400
#      Sat Aug 02 21:46:27 2014 +0900
# Node ID ee832d729d973bd5e60f2bafcd3df559293602ab
# Parent  db6e59e045dec018344a2eff0c854d446a2bcffa
cmdutil: use '[committemplate]' section like as map file for style definition

Before this patch, each template definitions for 'changeset*' in
'[committemplate]' section have to be written fully from scratch,
even though many parts of them may be common.

This patch uses '[committemplate]' section like as the map file for
the style definition. All items other than 'changeset' can be referred
from others.

This can reduce total cost of template customization in
 '[committemplate]' section.

When the commit template other than '[committemplate] changeset'
is chosen by 'editform', putting '[committemplate] changeset'
value into the cache of the templater causes unexpected result,
because the templater stores the specified (= chosen) template
definition into own cache as 'changeset' at construction time.

This is the reason why '[committemplate] changeset' can't be referred
from others.
Pierre-Yves David - Aug. 5, 2014, 3:06 a.m.
g

On 08/02/2014 06:02 AM, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
> # Date 1406983587 -32400
> #      Sat Aug 02 21:46:27 2014 +0900
> # Node ID ee832d729d973bd5e60f2bafcd3df559293602ab
> # Parent  db6e59e045dec018344a2eff0c854d446a2bcffa
> cmdutil: use '[committemplate]' section like as map file for style definition

I love this series and its looks overall good (but for previously made 
comment)

I will happily push a V2 with:

- Improvement docstring for the new argument
- core command prefixed with `core` (or an explanation of why this would 
be a terrible idea)
Matt Mackall - Aug. 5, 2014, 8:03 p.m.
On Mon, 2014-08-04 at 20:06 -0700, Pierre-Yves David wrote:
> g
> 
> On 08/02/2014 06:02 AM, FUJIWARA Katsunori wrote:
> > # HG changeset patch
> > # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
> > # Date 1406983587 -32400
> > #      Sat Aug 02 21:46:27 2014 +0900
> > # Node ID ee832d729d973bd5e60f2bafcd3df559293602ab
> > # Parent  db6e59e045dec018344a2eff0c854d446a2bcffa
> > cmdutil: use '[committemplate]' section like as map file for style definition
> 
> I love this series and its looks overall good (but for previously made 
> comment)
> 
> I will happily push a V2 with:
> 
> - Improvement docstring for the new argument
> - core command prefixed with `core` (or an explanation of why this would 
> be a terrible idea)

I've gone ahead and taken this series as is. I'm not terribly concerned
by the namespace collision thing, not enough to insist on adding 'core'
everywhere. The docstring thing can be fixed by followup patch,
definitely not worth another 15 patches in my mailbox.

FYI, I'd rather this sort of series be structured/sent as 2/3 patches to
add the core feature + N patches to add all the users after the core
bits had been accepted. Long series with tricky bits mixed in = bottom
of review stack.

Other things I'd like to see happen here:
- send full HGEDITFORM environment variable to $EDITOR if it wants to do
its own templating of some sort
- have a form for merge commits

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2222,6 +2222,10 @@ 
     except SyntaxError, inst:
         raise util.Abort(inst.args[0])
 
+    for k, v in repo.ui.configitems('committemplate'):
+        if k != 'changeset':
+            t.t.cache[k] = v
+
     if not extramsg:
         extramsg = '' # ensure that extramsg is string
 
diff --git a/mercurial/help/config.txt b/mercurial/help/config.txt
--- a/mercurial/help/config.txt
+++ b/mercurial/help/config.txt
@@ -419,6 +419,17 @@ 
 only for :hg:`tag --remove`, but ``changeset.tag`` customizes the
 commit message for :hg:`tag` regardless of ``--remove`` option.
 
+In this section, items other than ``changeset`` can be referred from
+others. For example, the configuration to list committed files up
+below can be referred as ``{listupfiles}``::
+
+    [committemplate]
+    listupfiles = {file_adds %
+       "HG: added {file}\n"     }{file_mods %
+       "HG: changed {file}\n"   }{file_dels %
+       "HG: removed {file}\n"   }{if(files, "",
+       "HG: no files changed\n")}
+
 ``decode/encode``
 -----------------
 
diff --git a/tests/test-mq-qrefresh-replace-log-message.t b/tests/test-mq-qrefresh-replace-log-message.t
--- a/tests/test-mq-qrefresh-replace-log-message.t
+++ b/tests/test-mq-qrefresh-replace-log-message.t
@@ -32,17 +32,19 @@ 
 
   $ cat >> .hg/hgrc <<EOF
   > [committemplate]
+  > listupfiles = {file_adds %
+  >    "HG: added {file}\n"     }{file_mods %
+  >    "HG: changed {file}\n"   }{file_dels %
+  >    "HG: removed {file}\n"   }{if(files, "",
+  >    "HG: no files changed\n")}
+  > 
   > changeset = HG: this is customized commit template
   >     {desc}\n\n
   >     HG: Enter commit message.  Lines beginning with 'HG:' are removed.
   >     HG: {extramsg}
   >     HG: --
   >     HG: user: {author}
-  >     HG: branch '{branch}'\n{file_adds %
-  >    "HG: added {file}\n"     }{file_mods %
-  >    "HG: changed {file}\n"   }{file_dels %
-  >    "HG: removed {file}\n"   }{if(files, "",
-  >    "HG: no files changed\n")}
+  >     HG: branch '{branch}'\n{listupfiles}
   > EOF
 
   $ echo bbbb > file