comparison mercurial/cmdutil.py @ 21924:5375ba75df40

cmdutil: make commit message shown in text editor customizable by template This patch makes commit message shown in text editor customizable by template. For example, this can advertise: - sample commit messages for routine works, - points to call attention before commit, - message of the day, and so on To show commit message correctly even in problematic encoding, this patch chooses the latter below: - replace "buildcommittext" with "buildcommittemplate" completely - invoke "buildcommittemplate" only if '[committemplate] changeset' is configured explicitly For example, if multibyte character ending with backslash (0x5c) is followed by ASCII character 'n' in the customized template, sequence of backslash and 'n' is treated as line-feed unexpectedly (and multibyte character is broken, too). This corruption occurs in 'decode("string-escape")' while parsing template string.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Tue, 15 Jul 2014 23:34:13 +0900
parents e582e20cd3e6
children 0483ff40e326
comparison
equal deleted inserted replaced
21923:e582e20cd3e6 21924:5375ba75df40
2171 return commitforceeditor(repo, ctx, subs) 2171 return commitforceeditor(repo, ctx, subs)
2172 2172
2173 def commitforceeditor(repo, ctx, subs, finishdesc=None, extramsg=None): 2173 def commitforceeditor(repo, ctx, subs, finishdesc=None, extramsg=None):
2174 if not extramsg: 2174 if not extramsg:
2175 extramsg = _("Leave message empty to abort commit.") 2175 extramsg = _("Leave message empty to abort commit.")
2176 committext = buildcommittext(repo, ctx, subs, extramsg) 2176 tmpl = repo.ui.config('committemplate', 'changeset', '').strip()
2177 if tmpl:
2178 committext = buildcommittemplate(repo, ctx, subs, extramsg, tmpl)
2179 else:
2180 committext = buildcommittext(repo, ctx, subs, extramsg)
2177 2181
2178 # run editor in the repository root 2182 # run editor in the repository root
2179 olddir = os.getcwd() 2183 olddir = os.getcwd()
2180 os.chdir(repo.root) 2184 os.chdir(repo.root)
2181 text = repo.ui.edit(committext, ctx.user(), ctx.extra()) 2185 text = repo.ui.edit(committext, ctx.user(), ctx.extra())
2186 text = finishdesc(text) 2190 text = finishdesc(text)
2187 if not text.strip(): 2191 if not text.strip():
2188 raise util.Abort(_("empty commit message")) 2192 raise util.Abort(_("empty commit message"))
2189 2193
2190 return text 2194 return text
2195
2196 def buildcommittemplate(repo, ctx, subs, extramsg, tmpl):
2197 ui = repo.ui
2198 tmpl, mapfile = gettemplate(ui, tmpl, None)
2199
2200 try:
2201 t = changeset_templater(ui, repo, None, {}, tmpl, mapfile, False)
2202 except SyntaxError, inst:
2203 raise util.Abort(inst.args[0])
2204
2205 if not extramsg:
2206 extramsg = '' # ensure that extramsg is string
2207
2208 ui.pushbuffer()
2209 t.show(ctx, extramsg=extramsg)
2210 return ui.popbuffer()
2191 2211
2192 def buildcommittext(repo, ctx, subs, extramsg): 2212 def buildcommittext(repo, ctx, subs, extramsg):
2193 edittext = [] 2213 edittext = []
2194 modified, added, removed = ctx.modified(), ctx.added(), ctx.removed() 2214 modified, added, removed = ctx.modified(), ctx.added(), ctx.removed()
2195 if ctx.description(): 2215 if ctx.description():