# HG changeset patch # User FUJIWARA Katsunori # Date 1408111553 -32400 # Node ID 9fa429723f26bc2f7d96291d08e15e702fe5dade # Parent f8dc6599da5d2220aeee736f6e59f95046421157 ui: invoke editor for committing with HGEDITFORM environment variable At the external editor invocation for committing, the value specified as "editform" for "cmdutil.getcommiteditor" is in "HGEDITFORM". This enables external editor to do own customization according to commit types. diff -r f8dc6599da5d -r 9fa429723f26 mercurial/cmdutil.py --- a/mercurial/cmdutil.py Fri Aug 15 04:37:46 2014 +0200 +++ b/mercurial/cmdutil.py Fri Aug 15 23:05:53 2014 +0900 @@ -2215,7 +2215,7 @@ # run editor in the repository root olddir = os.getcwd() os.chdir(repo.root) - text = repo.ui.edit(committext, ctx.user(), ctx.extra()) + text = repo.ui.edit(committext, ctx.user(), ctx.extra(), editform=editform) text = re.sub("(?m)^HG:.*(\n|$)", "", text) os.chdir(olddir) diff -r f8dc6599da5d -r 9fa429723f26 mercurial/help/config.txt --- a/mercurial/help/config.txt Fri Aug 15 04:37:46 2014 +0200 +++ b/mercurial/help/config.txt Fri Aug 15 23:05:53 2014 +0900 @@ -420,6 +420,10 @@ only for :hg:`tag --remove`, but ``changeset.tag`` customizes the commit message for :hg:`tag` regardless of ``--remove`` option. +At the external editor invocation for committing, corresponding +dot-separated list of names without ``changeset.`` prefix +(e.g. ``commit.normal``) is in ``HGEDITFORM`` environment variable. + 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}``:: diff -r f8dc6599da5d -r 9fa429723f26 mercurial/ui.py --- a/mercurial/ui.py Fri Aug 15 04:37:46 2014 +0200 +++ b/mercurial/ui.py Fri Aug 15 23:05:53 2014 +0900 @@ -728,7 +728,7 @@ if self.debugflag: opts['label'] = opts.get('label', '') + ' ui.debug' self.write(*msg, **opts) - def edit(self, text, user, extra={}): + def edit(self, text, user, extra={}, editform=None): (fd, name) = tempfile.mkstemp(prefix="hg-editor-", suffix=".txt", text=True) try: @@ -743,6 +743,8 @@ if label in extra: environ.update({'HGREVISION': extra[label]}) break + if editform: + environ.update({'HGEDITFORM': editform}) editor = self.geteditor() diff -r f8dc6599da5d -r 9fa429723f26 tests/test-commit.t --- a/tests/test-commit.t Fri Aug 15 04:37:46 2014 +0200 +++ b/tests/test-commit.t Fri Aug 15 23:05:53 2014 +0900 @@ -4,7 +4,12 @@ $ cd test $ echo foo > foo $ hg add foo - $ HGEDITOR=true hg commit -m "" + $ cat > $TESTTMP/checkeditform.sh < env | grep HGEDITFORM + > true + > EOF + $ HGEDITOR="sh $TESTTMP/checkeditform.sh" hg commit -m "" + HGEDITFORM=commit.normal abort: empty commit message [255] $ hg commit -d '0 0' -m commit-1