Patchwork [14,of,15] cmdutil: look commit template definition up by specified 'editform'

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Aug. 2, 2014, 1:02 p.m.
Message ID <db6e59e045dec018344a.1406984543@feefifofum>
Download mbox | patch
Permalink /patch/5242/
State Accepted
Commit 9d92b9d1e28252cc1ede6ca4cf91e6aff1f15c98
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 db6e59e045dec018344a2eff0c854d446a2bcffa
# Parent  7dd2c4c37c96712ba828a5bd0a0f32f2e16f7d28
cmdutil: look commit template definition up by specified 'editform'

Before this patch, '[committemplate] changeset' definition is shared
between all actions invoking 'commitforceeditor()'.

This prevents template definition from showing action specific
messages: for example, 'hg tag --remove' may need specific
message to call attention, but showing it may be redundant for
other actions.

This patch looks commit template definition up by specified
'editform' introduced by prior patches. 'editform' are
dot-separated list of names, and treated as hierarchical one.
Pierre-Yves David - Aug. 5, 2014, 2:54 a.m.
On 08/02/2014 06:02 AM, FUJIWARA Katsunori wrote:
> diff --git a/mercurial/help/config.txt b/mercurial/help/config.txt
> --- a/mercurial/help/config.txt
> +++ b/mercurial/help/config.txt
> @@ -388,6 +388,37 @@
>   - :hg:`tag`
>   - :hg:`transplant`
>
> +Configuring items below instead of ``changeset`` allows showing
> +customized message only for specific actions, or showing different
> +messages for each actions.
> +
> +- ``changeset.backout`` for :hg:`backout`
> +- ``changeset.commit.amend`` for :hg:`commit --amend`
> +- ``changeset.commit.normal`` for :hg:`commit` without ``--amend``
> +- ``changeset.fetch`` for :hg:`fetch` (impling merge commit)
> +- ``changeset.gpg.sign`` for :hg:`sign`
> +- ``changeset.graft`` for :hg:`graft`
> +- ``changeset.histedit.edit`` for ``edit`` of :hg:`histedit`
> +- ``changeset.histedit.fold`` for ``fold`` of :hg:`histedit`
> +- ``changeset.histedit.mess`` for ``mess`` of :hg:`histedit`
> +- ``changeset.histedit.pick`` for ``pick`` of :hg:`histedit`
> +- ``changeset.import.bypass`` for :hg:`import --bypass`
> +- ``changeset.import.normal`` for :hg:`import` without ``--bypass``
> +- ``changeset.mq.qnew`` for :hg:`qnew`
> +- ``changeset.mq.qfold`` for :hg:`qfold`
> +- ``changeset.mq.qrefresh`` for :hg:`qrefresh`
> +- ``changeset.rebase.collapse`` for :hg:`rebase --collapse`
> +- ``changeset.rebase.normal`` for :hg:`rebase` without ``--collapse``
> +- ``changeset.shelve.shelve`` for :hg:`shelve`
> +- ``changeset.tag.add`` for :hg:`tag` without ``--remove``
> +- ``changeset.tag.remove`` for :hg:`tag --remove`
> +- ``changeset.transplant`` for :hg:`transplant`

I wish this list could be generated to avoid it to lag behind. But I do 
not see easy trick to enforce that.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2187,9 +2187,15 @@ 
                       editform=''):
     if not extramsg:
         extramsg = _("Leave message empty to abort commit.")
-    tmpl = repo.ui.config('committemplate', 'changeset', '').strip()
-    if tmpl:
-        committext = buildcommittemplate(repo, ctx, subs, extramsg, tmpl)
+
+    forms = [e for e in editform.split('.') if e]
+    forms.insert(0, 'changeset')
+    while forms:
+        tmpl = repo.ui.config('committemplate', '.'.join(forms))
+        if tmpl:
+            committext = buildcommittemplate(repo, ctx, subs, extramsg, tmpl)
+            break
+        forms.pop()
     else:
         committext = buildcommittext(repo, ctx, subs, extramsg)
 
diff --git a/mercurial/help/config.txt b/mercurial/help/config.txt
--- a/mercurial/help/config.txt
+++ b/mercurial/help/config.txt
@@ -388,6 +388,37 @@ 
 - :hg:`tag`
 - :hg:`transplant`
 
+Configuring items below instead of ``changeset`` allows showing
+customized message only for specific actions, or showing different
+messages for each actions.
+
+- ``changeset.backout`` for :hg:`backout`
+- ``changeset.commit.amend`` for :hg:`commit --amend`
+- ``changeset.commit.normal`` for :hg:`commit` without ``--amend``
+- ``changeset.fetch`` for :hg:`fetch` (impling merge commit)
+- ``changeset.gpg.sign`` for :hg:`sign`
+- ``changeset.graft`` for :hg:`graft`
+- ``changeset.histedit.edit`` for ``edit`` of :hg:`histedit`
+- ``changeset.histedit.fold`` for ``fold`` of :hg:`histedit`
+- ``changeset.histedit.mess`` for ``mess`` of :hg:`histedit`
+- ``changeset.histedit.pick`` for ``pick`` of :hg:`histedit`
+- ``changeset.import.bypass`` for :hg:`import --bypass`
+- ``changeset.import.normal`` for :hg:`import` without ``--bypass``
+- ``changeset.mq.qnew`` for :hg:`qnew`
+- ``changeset.mq.qfold`` for :hg:`qfold`
+- ``changeset.mq.qrefresh`` for :hg:`qrefresh`
+- ``changeset.rebase.collapse`` for :hg:`rebase --collapse`
+- ``changeset.rebase.normal`` for :hg:`rebase` without ``--collapse``
+- ``changeset.shelve.shelve`` for :hg:`shelve`
+- ``changeset.tag.add`` for :hg:`tag` without ``--remove``
+- ``changeset.tag.remove`` for :hg:`tag --remove`
+- ``changeset.transplant`` for :hg:`transplant`
+
+These dot-separated lists of names are treated as hierarchical ones.
+For example, ``changeset.tag.remove`` customizes the commit message
+only for :hg:`tag --remove`, but ``changeset.tag`` customizes the
+commit message for :hg:`tag` regardless of ``--remove`` option.
+
 ``decode/encode``
 -----------------
 
diff --git a/tests/test-commit.t b/tests/test-commit.t
--- a/tests/test-commit.t
+++ b/tests/test-commit.t
@@ -359,6 +359,20 @@ 
 
   $ cat >> .hg/hgrc <<EOF
   > [committemplate]
+  > changeset.commit.normal = HG: this is "commit.normal" template
+  >     HG: {extramsg}
+  >     {if(currentbookmark,
+  >    "HG: bookmark '{currentbookmark}' is activated\n",
+  >    "HG: no bookmark is activated\n")}{subrepos %
+  >    "HG: subrepo '{subrepo}' is changed\n"}
+  > 
+  > changeset.commit = HG: this is "commit" template
+  >     HG: {extramsg}
+  >     {if(currentbookmark,
+  >    "HG: bookmark '{currentbookmark}' is activated\n",
+  >    "HG: no bookmark is activated\n")}{subrepos %
+  >    "HG: subrepo '{subrepo}' is changed\n"}
+  > 
   > changeset = HG: this is customized commit template
   >     HG: {extramsg}
   >     {if(currentbookmark,
@@ -373,7 +387,7 @@ 
   $ echo 'sub2 = sub2' >> .hgsub
 
   $ HGEDITOR=cat hg commit -S -q
-  HG: this is customized commit template
+  HG: this is "commit.normal" template
   HG: Leave message empty to abort commit.
   HG: bookmark 'currentbookmark' is activated
   HG: subrepo 'sub' is changed
@@ -381,9 +395,28 @@ 
   abort: empty commit message
   [255]
 
+  $ cat >> .hg/hgrc <<EOF
+  > [committemplate]
+  > changeset.commit.normal =
+  > # now, "changeset.commit" should be chosen for "hg commit"
+  > EOF
+
   $ hg bookmark --inactive currentbookmark
   $ hg forget .hgsub
   $ HGEDITOR=cat hg commit -q
+  HG: this is "commit" template
+  HG: Leave message empty to abort commit.
+  HG: no bookmark is activated
+  abort: empty commit message
+  [255]
+
+  $ cat >> .hg/hgrc <<EOF
+  > [committemplate]
+  > changeset.commit =
+  > # now, "changeset" should be chosen for "hg commit"
+  > EOF
+
+  $ HGEDITOR=cat hg commit -q
   HG: this is customized commit template
   HG: Leave message empty to abort commit.
   HG: no bookmark is activated