##// END OF EJS Templates
cmdutil: enhance "getcommiteditor()" for specific usages in MQ...
FUJIWARA Katsunori -
r21419:27278548 default
parent child Browse files
Show More
@@ -109,10 +109,27 def logmessage(ui, opts):
109 109 (logfile, inst.strerror))
110 110 return message
111 111
112 def getcommiteditor(edit=False, **opts):
113 """get appropriate commit message editor according to '--edit' option"""
114 if edit:
115 return commitforceeditor
112 def getcommiteditor(edit=False, finishdesc=None, extramsg=None, **opts):
113 """get appropriate commit message editor according to '--edit' option
114
115 'finishdesc' is a function to be called with edited commit message
116 (= 'description' of the new changeset) just after editing, but
117 before checking empty-ness. It should return actual text to be
118 stored into history. This allows to change description before
119 storing.
120
121 'extramsg' is a extra message to be shown in the editor instead of
122 'Leave message empty to abort commit' line. 'HG: ' prefix and EOL
123 is automatically added.
124
125 'getcommiteditor' returns 'commitforceeditor' regardless of
126 'edit', if one of 'finishdesc' or 'extramsg' is specified, because
127 they are specific for usage in MQ.
128 """
129 if edit or finishdesc or extramsg:
130 return lambda r, c, s: commitforceeditor(r, c, s,
131 finishdesc=finishdesc,
132 extramsg=extramsg)
116 133 else:
117 134 return commiteditor
118 135
@@ -2130,7 +2147,7 def commiteditor(repo, ctx, subs):
2130 2147 return ctx.description()
2131 2148 return commitforceeditor(repo, ctx, subs)
2132 2149
2133 def commitforceeditor(repo, ctx, subs):
2150 def commitforceeditor(repo, ctx, subs, finishdesc=None, extramsg=None):
2134 2151 edittext = []
2135 2152 modified, added, removed = ctx.modified(), ctx.added(), ctx.removed()
2136 2153 if ctx.description():
@@ -2139,6 +2156,9 def commitforceeditor(repo, ctx, subs):
2139 2156 edittext.append("") # Empty line between message and comments.
2140 2157 edittext.append(_("HG: Enter commit message."
2141 2158 " Lines beginning with 'HG:' are removed."))
2159 if extramsg:
2160 edittext.append("HG: %s" % extramsg)
2161 else:
2142 2162 edittext.append(_("HG: Leave message empty to abort commit."))
2143 2163 edittext.append("HG: --")
2144 2164 edittext.append(_("HG: user: %s") % ctx.user())
@@ -2162,6 +2182,8 def commitforceeditor(repo, ctx, subs):
2162 2182 text = re.sub("(?m)^HG:.*(\n|$)", "", text)
2163 2183 os.chdir(olddir)
2164 2184
2185 if finishdesc:
2186 text = finishdesc(text)
2165 2187 if not text.strip():
2166 2188 raise util.Abort(_("empty commit message"))
2167 2189
General Comments 0
You need to be logged in to leave comments. Login now