# HG changeset patch # User FUJIWARA Katsunori # Date 2014-08-02 12:46:27 # Node ID de5cee8ba0880b336b323c4cc1130dee3ecdcaed # Parent 9d92b9d1e28252cc1ede6ca4cf91e6aff1f15c98 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. diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -2228,6 +2228,10 @@ def buildcommittemplate(repo, ctx, subs, 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 @@ For example, ``changeset.tag.remove`` cu 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 @@ template keyword 'extramsg' work well) $ cat >> .hg/hgrc < [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