Patchwork [2,of,7] dispatch: factor out the exception raised on unsafe `serve --stdio`

login
register
mail settings
Submitter Paul Morelle
Date June 20, 2018, 4:36 p.m.
Message ID <b7051e4bf783c844f705.1529512583@belenos.localdomain>
Download mbox | patch
Permalink /patch/32344/
State Accepted
Headers show

Comments

Paul Morelle - June 20, 2018, 4:36 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1529489808 -7200
#      Wed Jun 20 12:16:48 2018 +0200
# Node ID b7051e4bf783c844f705473a2396458acecc59dc
# Parent  a7944f21dbfc9e912606b82dc1001e4640598600
# EXP-Topic remote-debug
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r b7051e4bf783
dispatch: factor out the exception raised on unsafe `serve --stdio`

We want to relax this check to allow for wider argument passing in certain
conditions (e.g. --debug). We make preliminary refactoring in different
changesets for clarity.

Patch

diff -r a7944f21dbfc -r b7051e4bf783 mercurial/dispatch.py
--- a/mercurial/dispatch.py	Tue Jun 19 18:21:37 2018 +0200
+++ b/mercurial/dispatch.py	Wed Jun 20 12:16:48 2018 +0200
@@ -282,14 +282,15 @@ 
             # shenanigans wherein a user does something like pass
             # --debugger or --config=ui.debugger=1 as a repo
             # name. This used to actually run the debugger.
+            def unsafe():
+                msg = _('potentially unsafe serve --stdio invocation: %s')
+                raise error.Abort(msg % (stringutil.pprint(req.args),))
             if (len(req.args) != 4 or
                 req.args[0] != '-R' or
                 req.args[1].startswith('--') or
                 req.args[2] != 'serve' or
                 req.args[3] != '--stdio'):
-                raise error.Abort(
-                    _('potentially unsafe serve --stdio invocation: %s') %
-                    (stringutil.pprint(req.args),))
+                unsafe()
 
         try:
             debugger = 'pdb'