Mercurial > public > mercurial-scm > hg-stable
diff 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 |
line wrap: on
line diff
--- a/mercurial/cmdutil.py Fri Jul 18 23:15:28 2014 -0500 +++ b/mercurial/cmdutil.py Tue Jul 15 23:34:13 2014 +0900 @@ -2173,7 +2173,11 @@ def commitforceeditor(repo, ctx, subs, finishdesc=None, extramsg=None): if not extramsg: extramsg = _("Leave message empty to abort commit.") - committext = buildcommittext(repo, ctx, subs, extramsg) + tmpl = repo.ui.config('committemplate', 'changeset', '').strip() + if tmpl: + committext = buildcommittemplate(repo, ctx, subs, extramsg, tmpl) + else: + committext = buildcommittext(repo, ctx, subs, extramsg) # run editor in the repository root olddir = os.getcwd() @@ -2189,6 +2193,22 @@ return text +def buildcommittemplate(repo, ctx, subs, extramsg, tmpl): + ui = repo.ui + tmpl, mapfile = gettemplate(ui, tmpl, None) + + try: + t = changeset_templater(ui, repo, None, {}, tmpl, mapfile, False) + except SyntaxError, inst: + raise util.Abort(inst.args[0]) + + if not extramsg: + extramsg = '' # ensure that extramsg is string + + ui.pushbuffer() + t.show(ctx, extramsg=extramsg) + return ui.popbuffer() + def buildcommittext(repo, ctx, subs, extramsg): edittext = [] modified, added, removed = ctx.modified(), ctx.added(), ctx.removed()