##// 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 b' def logmessage(ui, opts):'
109 (logfile, inst.strerror))
109 (logfile, inst.strerror))
110 return message
110 return message
111
111
112 def getcommiteditor(edit=False, **opts):
112 def getcommiteditor(edit=False, finishdesc=None, extramsg=None, **opts):
113 """get appropriate commit message editor according to '--edit' option"""
113 """get appropriate commit message editor according to '--edit' option
114 if edit:
114
115 return commitforceeditor
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 else:
133 else:
117 return commiteditor
134 return commiteditor
118
135
@@ -2130,7 +2147,7 b' def commiteditor(repo, ctx, subs):'
2130 return ctx.description()
2147 return ctx.description()
2131 return commitforceeditor(repo, ctx, subs)
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 edittext = []
2151 edittext = []
2135 modified, added, removed = ctx.modified(), ctx.added(), ctx.removed()
2152 modified, added, removed = ctx.modified(), ctx.added(), ctx.removed()
2136 if ctx.description():
2153 if ctx.description():
@@ -2139,7 +2156,10 b' def commitforceeditor(repo, ctx, subs):'
2139 edittext.append("") # Empty line between message and comments.
2156 edittext.append("") # Empty line between message and comments.
2140 edittext.append(_("HG: Enter commit message."
2157 edittext.append(_("HG: Enter commit message."
2141 " Lines beginning with 'HG:' are removed."))
2158 " Lines beginning with 'HG:' are removed."))
2142 edittext.append(_("HG: Leave message empty to abort commit."))
2159 if extramsg:
2160 edittext.append("HG: %s" % extramsg)
2161 else:
2162 edittext.append(_("HG: Leave message empty to abort commit."))
2143 edittext.append("HG: --")
2163 edittext.append("HG: --")
2144 edittext.append(_("HG: user: %s") % ctx.user())
2164 edittext.append(_("HG: user: %s") % ctx.user())
2145 if ctx.p2():
2165 if ctx.p2():
@@ -2162,6 +2182,8 b' def commitforceeditor(repo, ctx, subs):'
2162 text = re.sub("(?m)^HG:.*(\n|$)", "", text)
2182 text = re.sub("(?m)^HG:.*(\n|$)", "", text)
2163 os.chdir(olddir)
2183 os.chdir(olddir)
2164
2184
2185 if finishdesc:
2186 text = finishdesc(text)
2165 if not text.strip():
2187 if not text.strip():
2166 raise util.Abort(_("empty commit message"))
2188 raise util.Abort(_("empty commit message"))
2167
2189
General Comments 0
You need to be logged in to leave comments. Login now