From patchwork Sat May 10 16:08:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [01, of, 19] cmdutil: introduce "getcommiteditor()" to simplify code paths to choose editor From: Katsunori FUJIWARA X-Patchwork-Id: 4703 Message-Id: To: mercurial-devel@selenic.com Date: Sun, 11 May 2014 01:08:36 +0900 # HG changeset patch # User FUJIWARA Katsunori # Date 1399736975 -32400 # Sun May 11 00:49:35 2014 +0900 # Node ID b482c1575fdf145f03285a6a846b7f07a753b8a2 # Parent bcddddcf0b540b1d98f0dc1f1a1bef9337e2e567 cmdutil: introduce "getcommiteditor()" to simplify code paths to choose editor "getcommiteditor()" can simplify code paths to choose commit editor according to '--edit' option as below: before: editor = cmdutil.commiteditor # or editor = None/False if opts.get('edit'): editor = cmdutil.commitforceeditor after: editor = cmdutil.getcommiteditor(**opts) "getcommiteditor()" accepts option arguments not in "opts" style but in "**opts" style, because some code paths want to invoke it with just explicit "edit=True" argument (building dictionary is redundant). diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -109,6 +109,13 @@ (logfile, inst.strerror)) return message +def getcommiteditor(edit=False, **opts): + """get appropriate commit message editor according to '--edit' option""" + if edit: + return commitforceeditor + else: + return commiteditor + def loglimit(opts): """get the log limit according to option -l/--limit""" limit = opts.get('limit')