Patchwork [1,of,4] logtoprocess: leverage procutil.shellenviron() to stringify variables (BC)

login
register
mail settings
Submitter Yuya Nishihara
Date Nov. 13, 2018, 1:42 p.m.
Message ID <acd1e5000af16058913f.1542116536@mimosa>
Download mbox | patch
Permalink /patch/36542/
State Accepted
Headers show

Comments

Yuya Nishihara - Nov. 13, 2018, 1:42 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1541906843 -32400
#      Sun Nov 11 12:27:23 2018 +0900
# Node ID acd1e5000af16058913ff547e08a35d4583a6dac
# Parent  5c7dff08eea9b3f05995380e612546c9bc7a17ad
logtoprocess: leverage procutil.shellenviron() to stringify variables (BC)

This should make the extension more Py3 friendly. The environment variables
of the main process are copied to the dict by shellenviron().

.. bc::

   Boolean options passed to the logtoprocess extension are now formatted
   as ``0`` or ``1`` instead of ``None``, ``False``, or ``True``.

Patch

diff --git a/hgext/logtoprocess.py b/hgext/logtoprocess.py
--- a/hgext/logtoprocess.py
+++ b/hgext/logtoprocess.py
@@ -73,16 +73,16 @@  def uisetup(ui):
                 # positional arguments are listed as MSG[N] keys in the
                 # environment
                 msgpairs = (
-                    ('MSG{0:d}'.format(i), str(m))
+                    ('MSG{0:d}'.format(i), m)
                     for i, m in enumerate(messages, 1))
                 # keyword arguments get prefixed with OPT_ and uppercased
                 optpairs = (
-                    ('OPT_{0}'.format(key.upper()), str(value))
+                    ('OPT_{0}'.format(key.upper()), value)
                     for key, value in opts.iteritems())
-                env = dict(itertools.chain(procutil.shellenviron().items(),
-                                           msgpairs, optpairs),
-                           EVENT=event, HGPID=str(os.getpid()))
-                procutil.runbgcommand(script, env, shell=True)
+                env = dict(itertools.chain(msgpairs, optpairs),
+                           EVENT=event, HGPID=os.getpid())
+                fullenv = procutil.shellenviron(env)
+                procutil.runbgcommand(script, fullenv, shell=True)
             return super(logtoprocessui, self).log(event, *msg, **opts)
 
     # Replace the class for this instance and all clones created from it: