# HG changeset patch # User FUJIWARA Katsunori # Date 2014-08-15 14:05:53 # 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 --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -2215,7 +2215,7 @@ def commitforceeditor(repo, ctx, subs, f # 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 --git a/mercurial/help/config.txt b/mercurial/help/config.txt --- a/mercurial/help/config.txt +++ b/mercurial/help/config.txt @@ -420,6 +420,10 @@ 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. +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 --git a/mercurial/ui.py b/mercurial/ui.py --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -728,7 +728,7 @@ class ui(object): 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 @@ class ui(object): if label in extra: environ.update({'HGREVISION': extra[label]}) break + if editform: + environ.update({'HGEDITFORM': editform}) editor = self.geteditor() diff --git a/tests/test-commit.t b/tests/test-commit.t --- a/tests/test-commit.t +++ b/tests/test-commit.t @@ -4,7 +4,12 @@ commit date test $ 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