# HG changeset patch # User FUJIWARA Katsunori # Date 2014-08-02 12:46:27 # Node ID 9d92b9d1e28252cc1ede6ca4cf91e6aff1f15c98 # Parent 97acb4504704d13b70257d6133e11971f30a9751 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. diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -2193,9 +2193,15 @@ def commitforceeditor(repo, ctx, subs, f 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 @@ required): - :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 @@ specific template keywords work well $ cat >> .hg/hgrc < [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 @@ specific template keywords work well $ 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 @@ specific template keywords work well abort: empty commit message [255] + $ cat >> .hg/hgrc < [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 < [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