Mercurial > public > mercurial-scm > hg
diff hgext/mq.py @ 21234:b9a16ed5acec
qnew: use "editor" argument of "commit()" instead of explicit "ui.edit()"
Before this patch, "hg qnew" invokes "ui.edit()" explicitly to get
commit message edited manually.
This requires explicit "localrepository.savecommitmessage()"
invocation to save edited commit message into ".hg/last-message.txt",
because unexpected exception raising may abort command execution
before saving it in "localrepository.commit()".
This patch uses "editor" argument of "localrepository.commit()"
instead of explicit "ui.edit()" invocation for "hg qnew".
"localrepository.commit()" will invoke "desceditor()" function newly
added by this patch, and save edited commit message into
".hg/last-message.txt" automatically.
This patch passes not "editor" but "desceditor" to "commit()", because
"hg qnew" requires editor function to return edited message if not
empty, or default message otherwise.
This patch applies "rstrip()" on "defaultmsg" at comparison between
"nctx.description()" and "defaultmsg", because the former should be
stripped by "changelog.stripdesc()" and the latter may have tail white
spaces inherited from "patchfn".
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Mon, 05 May 2014 21:26:40 +0900 |
parents | b6e0616d08cb |
children | 51069bf6366b |
line wrap: on
line diff
--- a/hgext/mq.py Mon May 05 21:26:40 2014 +0900 +++ b/hgext/mq.py Mon May 05 21:26:40 2014 +0900 @@ -1026,6 +1026,7 @@ msg: a string or a no-argument function returning a string """ msg = opts.get('msg') + editor = opts.get('editor') user = opts.get('user') date = opts.get('date') if date: @@ -1078,12 +1079,23 @@ p.write("# User " + user + "\n") if date: p.write("# Date %s %s\n\n" % date) - if util.safehasattr(msg, '__call__'): - msg = msg() - repo.savecommitmessage(msg) - commitmsg = msg and msg or ("[mq]: %s" % patchfn) + + defaultmsg = "[mq]: %s" % patchfn + if editor: + origeditor = editor + def desceditor(repo, ctx, subs): + desc = origeditor(repo, ctx, subs) + if desc.rstrip(): + return desc + else: + return defaultmsg + commitmsg = msg + editor = desceditor + else: + commitmsg = msg or defaultmsg + n = newcommit(repo, None, commitmsg, user, date, match=match, - force=True) + force=True, editor=editor) if n is None: raise util.Abort(_("repo commit failed")) try: @@ -1092,8 +1104,9 @@ self.parseseries() self.seriesdirty = True self.applieddirty = True - if msg: - msg = msg + "\n\n" + nctx = repo[n] + if nctx.description() != defaultmsg.rstrip(): + msg = nctx.description() + "\n\n" p.write(msg) if commitfiles: parent = self.qparents(repo, n) @@ -2417,14 +2430,12 @@ Returns 0 on successful creation of a new patch. """ msg = cmdutil.logmessage(ui, opts) - def getmsg(): - return ui.edit(msg, opts.get('user') or ui.username()) q = repo.mq opts['msg'] = msg if opts.get('edit'): - opts['msg'] = getmsg - else: - opts['msg'] = msg + def editor(repo, ctx, subs): + return ui.edit(ctx.description() + "\n", ctx.user()) + opts['editor'] = editor setupheaderopts(ui, opts) q.new(repo, patch, *args, **opts) q.savedirty()