Patchwork [1,of,4] serve: accept multiple values for --daemon-postexec

login
register
mail settings
Submitter Jun Wu
Date March 9, 2016, 2:23 a.m.
Message ID <05d74711cf855d7a5c1a.1457490203@x1c>
Download mbox | patch
Permalink /patch/13697/
State Accepted
Delegated to: Yuya Nishihara
Headers show

Comments

Jun Wu - March 9, 2016, 2:23 a.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1457489260 0
#      Wed Mar 09 02:07:40 2016 +0000
# Node ID 05d74711cf855d7a5c1ab35d5eca6425f963dbfd
# Parent  ffd3ac07b1d79dda7f57bd826208fdaf92a76717
serve: accept multiple values for --daemon-postexec

The next patch will add another postexec command: chdir, which can be used
together with unlink. This patch changes the option type of --daemon-postexec
from string to list to accept multiple commands. The error message of invalid
--daemon-postexec value is also changed to include the actual invalid value.
Yuya Nishihara - March 11, 2016, 7:19 a.m.
On Wed, 9 Mar 2016 02:23:23 +0000, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1457489260 0
> #      Wed Mar 09 02:07:40 2016 +0000
> # Node ID 05d74711cf855d7a5c1ab35d5eca6425f963dbfd
> # Parent  ffd3ac07b1d79dda7f57bd826208fdaf92a76717
> serve: accept multiple values for --daemon-postexec

Pushed the first 3 to the clowncopter, thanks!

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -827,16 +827,17 @@ 
         writepid(util.getpid())
 
     if opts['daemon_postexec']:
-        inst = opts['daemon_postexec']
         try:
             os.setsid()
         except AttributeError:
             pass
-        if inst.startswith('unlink:'):
-            lockpath = inst[7:]
-            os.unlink(lockpath)
-        elif inst != 'none':
-            raise error.Abort(_('invalid value for --daemon-postexec'))
+        for inst in opts['daemon_postexec']:
+            if inst.startswith('unlink:'):
+                lockpath = inst[7:]
+                os.unlink(lockpath)
+            elif inst != 'none':
+                raise error.Abort(_('invalid value for --daemon-postexec: %s')
+                                  % inst)
         util.hidewindow()
         sys.stdout.flush()
         sys.stderr.flush()
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -6276,7 +6276,7 @@ 
     [('A', 'accesslog', '', _('name of access log file to write to'),
      _('FILE')),
     ('d', 'daemon', None, _('run server in background')),
-    ('', 'daemon-postexec', '', _('used internally by daemon mode')),
+    ('', 'daemon-postexec', [], _('used internally by daemon mode')),
     ('E', 'errorlog', '', _('name of error log file to write to'), _('FILE')),
     # use string type, then we can check if something was passed
     ('p', 'port', '', _('port to listen on (default: 8000)'), _('PORT')),
diff --git a/tests/dumbhttp.py b/tests/dumbhttp.py
--- a/tests/dumbhttp.py
+++ b/tests/dumbhttp.py
@@ -38,7 +38,7 @@ 
     parser.add_option('-f', '--foreground', dest='foreground',
         action='store_true',
         help='do not start the HTTP server in the background')
-    parser.add_option('--daemon-postexec')
+    parser.add_option('--daemon-postexec', action='append')
 
     (options, args) = parser.parse_args()