[PATCH 17 of 19] mq: use the editor gotten by "getcommiteditor()" instead of "ui.edit()" (qnew)

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Sat May 10 16:08:52 UTC 2014


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1399736976 -32400
#      Sun May 11 00:49:36 2014 +0900
# Node ID 0cba86ca33859c9a8de398ad170c315702fd27c6
# Parent  73f1b585d9440c53a962af3cd8ef4d4c085f0788
mq: use the editor gotten by "getcommiteditor()" instead of "ui.edit()" (qnew)

This patch also replaces "editor = False" by "editor =
cmdutil.getcommiteditor()", because:

  - the latter allows to hook commit message determination easily,
    even in the case without "--edit"

  - the latter can avoid regression (or additional care) around saving
    "last-message.txt", even if MQ's "newcommit()" changes its
    implementation logic from "localrepository.commit" to
    "localrepository.commitctx" with "memctx" in the future

    to save commit message into "last-messge.txt" with "memctx",
    "editor" should be valid function.

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -1081,17 +1081,18 @@
                         p.write("# Date %s %s\n\n" % date)
 
                 defaultmsg = "[mq]: %s" % patchfn
-                editor = False
+                editor = cmdutil.getcommiteditor()
                 if edit:
-                    def desceditor(repo, ctx, subs):
-                        desc = self.ui.edit(ctx.description() + "\n",
-                                            ctx.user())
+                    def finishdesc(desc):
                         if desc.rstrip():
                             return desc
                         else:
                             return defaultmsg
+                    # i18n: this message is shown in editor with "HG: " prefix
+                    extramsg = _('Leave message empty to use default message.')
+                    editor = cmdutil.getcommiteditor(finishdesc=finishdesc,
+                                                     extramsg=extramsg)
                     commitmsg = msg
-                    editor = desceditor
                 else:
                     commitmsg = msg or defaultmsg
 
diff --git a/tests/test-mq-qnew.t b/tests/test-mq-qnew.t
--- a/tests/test-mq-qnew.t
+++ b/tests/test-mq-qnew.t
@@ -284,9 +284,17 @@
   > EOF
 
   $ rm -f .hg/last-message.txt
+  $ hg status
   $ HGEDITOR="sh $TESTTMP/editor.sh" hg qnew -e patch
   ==== before editing
   
+  
+  HG: Enter commit message.  Lines beginning with 'HG:' are removed.
+  HG: Leave message empty to use default message.
+  HG: --
+  HG: user: test
+  HG: branch 'default'
+  HG: no files changed
   ====
   transaction abort!
   rollback completed
@@ -295,6 +303,7 @@
   [255]
   $ cat .hg/last-message.txt
   
+  
   test saving last-message.txt
 
   $ cat >> .hg/hgrc <<EOF
@@ -314,9 +323,17 @@
   > EOF
 
   $ rm -f .hg/last-message.txt
+  $ hg status
   $ HGEDITOR="sh $TESTTMP/editor.sh" hg qnew -e "patch "
   ==== before editing
   
+  
+  HG: Enter commit message.  Lines beginning with 'HG:' are removed.
+  HG: Leave message empty to use default message.
+  HG: --
+  HG: user: test
+  HG: branch 'default'
+  HG: no files changed
   ====
   $ cat ".hg/patches/patch "
   # HG changeset patch



More information about the Mercurial-devel mailing list