# HG changeset patch # User FUJIWARA Katsunori # Date 1399736976 -32400 # Node ID 272785489ed313e898c1ec573e40eb5c3ec75f57 # Parent d4b8fc75345501861510ecb7efdb8dfbfb984ad3 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 diff -r d4b8fc753455 -r 272785489ed3 mercurial/cmdutil.py --- a/mercurial/cmdutil.py Sun May 11 00:49:36 2014 +0900 +++ b/mercurial/cmdutil.py Sun May 11 00:49:36 2014 +0900 @@ -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"))