[PATCH 01 of 19] cmdutil: introduce "getcommiteditor()" to simplify code paths to choose editor

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Sat May 10 11:08:36 CDT 2014


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# 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')


More information about the Mercurial-devel mailing list