Mercurial > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
21233:213fd1a99cd9 | 21234:b9a16ed5acec |
---|---|
1024 def new(self, repo, patchfn, *pats, **opts): | 1024 def new(self, repo, patchfn, *pats, **opts): |
1025 """options: | 1025 """options: |
1026 msg: a string or a no-argument function returning a string | 1026 msg: a string or a no-argument function returning a string |
1027 """ | 1027 """ |
1028 msg = opts.get('msg') | 1028 msg = opts.get('msg') |
1029 editor = opts.get('editor') | |
1029 user = opts.get('user') | 1030 user = opts.get('user') |
1030 date = opts.get('date') | 1031 date = opts.get('date') |
1031 if date: | 1032 if date: |
1032 date = util.parsedate(date) | 1033 date = util.parsedate(date) |
1033 diffopts = self.diffopts({'git': opts.get('git')}) | 1034 diffopts = self.diffopts({'git': opts.get('git')}) |
1076 + hex(repo[None].p1().node()) + "\n") | 1077 + hex(repo[None].p1().node()) + "\n") |
1077 if user: | 1078 if user: |
1078 p.write("# User " + user + "\n") | 1079 p.write("# User " + user + "\n") |
1079 if date: | 1080 if date: |
1080 p.write("# Date %s %s\n\n" % date) | 1081 p.write("# Date %s %s\n\n" % date) |
1081 if util.safehasattr(msg, '__call__'): | 1082 |
1082 msg = msg() | 1083 defaultmsg = "[mq]: %s" % patchfn |
1083 repo.savecommitmessage(msg) | 1084 if editor: |
1084 commitmsg = msg and msg or ("[mq]: %s" % patchfn) | 1085 origeditor = editor |
1086 def desceditor(repo, ctx, subs): | |
1087 desc = origeditor(repo, ctx, subs) | |
1088 if desc.rstrip(): | |
1089 return desc | |
1090 else: | |
1091 return defaultmsg | |
1092 commitmsg = msg | |
1093 editor = desceditor | |
1094 else: | |
1095 commitmsg = msg or defaultmsg | |
1096 | |
1085 n = newcommit(repo, None, commitmsg, user, date, match=match, | 1097 n = newcommit(repo, None, commitmsg, user, date, match=match, |
1086 force=True) | 1098 force=True, editor=editor) |
1087 if n is None: | 1099 if n is None: |
1088 raise util.Abort(_("repo commit failed")) | 1100 raise util.Abort(_("repo commit failed")) |
1089 try: | 1101 try: |
1090 self.fullseries[insert:insert] = [patchfn] | 1102 self.fullseries[insert:insert] = [patchfn] |
1091 self.applied.append(statusentry(n, patchfn)) | 1103 self.applied.append(statusentry(n, patchfn)) |
1092 self.parseseries() | 1104 self.parseseries() |
1093 self.seriesdirty = True | 1105 self.seriesdirty = True |
1094 self.applieddirty = True | 1106 self.applieddirty = True |
1095 if msg: | 1107 nctx = repo[n] |
1096 msg = msg + "\n\n" | 1108 if nctx.description() != defaultmsg.rstrip(): |
1109 msg = nctx.description() + "\n\n" | |
1097 p.write(msg) | 1110 p.write(msg) |
1098 if commitfiles: | 1111 if commitfiles: |
1099 parent = self.qparents(repo, n) | 1112 parent = self.qparents(repo, n) |
1100 if inclsubs: | 1113 if inclsubs: |
1101 self.putsubstate2changes(substatestate, changes) | 1114 self.putsubstate2changes(substatestate, changes) |
2415 information. | 2428 information. |
2416 | 2429 |
2417 Returns 0 on successful creation of a new patch. | 2430 Returns 0 on successful creation of a new patch. |
2418 """ | 2431 """ |
2419 msg = cmdutil.logmessage(ui, opts) | 2432 msg = cmdutil.logmessage(ui, opts) |
2420 def getmsg(): | |
2421 return ui.edit(msg, opts.get('user') or ui.username()) | |
2422 q = repo.mq | 2433 q = repo.mq |
2423 opts['msg'] = msg | 2434 opts['msg'] = msg |
2424 if opts.get('edit'): | 2435 if opts.get('edit'): |
2425 opts['msg'] = getmsg | 2436 def editor(repo, ctx, subs): |
2426 else: | 2437 return ui.edit(ctx.description() + "\n", ctx.user()) |
2427 opts['msg'] = msg | 2438 opts['editor'] = editor |
2428 setupheaderopts(ui, opts) | 2439 setupheaderopts(ui, opts) |
2429 q.new(repo, patch, *args, **opts) | 2440 q.new(repo, patch, *args, **opts) |
2430 q.savedirty() | 2441 q.savedirty() |
2431 return 0 | 2442 return 0 |
2432 | 2443 |