changeset 22205:9fa429723f26

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.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Fri, 15 Aug 2014 23:05:53 +0900
parents f8dc6599da5d
children 6122ad50e38f
files mercurial/cmdutil.py mercurial/help/config.txt mercurial/ui.py tests/test-commit.t
diffstat 4 files changed, 14 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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)
 
--- 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}``::
--- 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()
 
--- 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 <<EOF
+  > 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