Patchwork [15,of,19] cmdutil: enhance "getcommiteditor()" for specific usages in MQ

login
register
mail settings
Submitter Katsunori FUJIWARA
Date May 10, 2014, 4:08 p.m.
Message ID <4b998ec208e265de4c98.1399738130@feefifofum>
Download mbox | patch
Permalink /patch/4717/
State Accepted
Headers show

Comments

Katsunori FUJIWARA - May 10, 2014, 4:08 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1399736976 -32400
#      Sun May 11 00:49:36 2014 +0900
# Node ID 4b998ec208e265de4c981645536c94b2536afa9a
# Parent  3a4c7b9f7ae1c785cd6a9ee35af99065e6eb088d
cmdutil: enhance "getcommiteditor()" for specific usages in MQ

This patch introduces "finishdesc" and "extramsg" arguments into
"getcommiteditor()" for specific usages in MQ.

"finishdesc" will be used to treat the commit message as "[mq];
patch-file-name" (default MQ commit message), if it is left as empty,
instead of aborting commit process.

"extramsg" will be used to show the line below:

    HG: Leave message empty to use default message

instead of:

    HG: Leave message empty to abort commit

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -109,10 +109,27 @@ 
                              (logfile, inst.strerror))
     return message
 
-def getcommiteditor(edit=False, **opts):
-    """get appropriate commit message editor according to '--edit' option"""
-    if edit:
-        return commitforceeditor
+def getcommiteditor(edit=False, finishdesc=None, extramsg=None, **opts):
+    """get appropriate commit message editor according to '--edit' option
+
+    'finishdesc' is a function to be called with edited commit message
+    (= 'description' of the new changeset) just after editing, but
+    before checking empty-ness. It should return actual text to be
+    stored into history. This allows to change description before
+    storing.
+
+    'extramsg' is a extra message to be shown in the editor instead of
+    'Leave message empty to abort commit' line. 'HG: ' prefix and EOL
+    is automatically added.
+
+    'getcommiteditor' returns 'commitforceeditor' regardless of
+    'edit', if one of 'finishdesc' or 'extramsg' is specified, because
+    they are specific for usage in MQ.
+    """
+    if edit or finishdesc or extramsg:
+        return lambda r, c, s: commitforceeditor(r, c, s,
+                                                 finishdesc=finishdesc,
+                                                 extramsg=extramsg)
     else:
         return commiteditor
 
@@ -2130,7 +2147,7 @@ 
         return ctx.description()
     return commitforceeditor(repo, ctx, subs)
 
-def commitforceeditor(repo, ctx, subs):
+def commitforceeditor(repo, ctx, subs, finishdesc=None, extramsg=None):
     edittext = []
     modified, added, removed = ctx.modified(), ctx.added(), ctx.removed()
     if ctx.description():
@@ -2139,7 +2156,10 @@ 
     edittext.append("") # Empty line between message and comments.
     edittext.append(_("HG: Enter commit message."
                       "  Lines beginning with 'HG:' are removed."))
-    edittext.append(_("HG: Leave message empty to abort commit."))
+    if extramsg:
+        edittext.append("HG: %s" % extramsg)
+    else:
+        edittext.append(_("HG: Leave message empty to abort commit."))
     edittext.append("HG: --")
     edittext.append(_("HG: user: %s") % ctx.user())
     if ctx.p2():
@@ -2162,6 +2182,8 @@ 
     text = re.sub("(?m)^HG:.*(\n|$)", "", text)
     os.chdir(olddir)
 
+    if finishdesc:
+        text = finishdesc(text)
     if not text.strip():
         raise util.Abort(_("empty commit message"))