Patchwork [1,of,2] dispatch: move command line --config argument parsing to _runcatch()

login
register
mail settings
Submitter Sean Farley
Date July 13, 2013, 10:16 p.m.
Message ID <15a903bca551318cd0c3.1373753815@laptop.local>
Download mbox | patch
Permalink /patch/1879/
State Superseded, archived
Headers show

Comments

Sean Farley - July 13, 2013, 10:16 p.m.
# HG changeset patch
# User Sean Farley <sean.michael.farley@gmail.com>
# Date 1373751187 18000
#      Sat Jul 13 16:33:07 2013 -0500
# Node ID 15a903bca551318cd0c3f42484374a8b8acd08e5
# Parent  3af3a165db18ed093394fe661e797bea296dc602
dispatch: move command line --config argument parsing to _runcatch()

Previously, command line parsing of --config arguments was done in
_dispatch. This means that it takes place after activating the debugger. In an
upcoming patch, we will add a ui.debugger setting so we need to have this
parsing done before _runcatch.
Sean Farley - Aug. 7, 2013, 8:47 p.m.
kbullock+mercurial@ringworld.org writes:

> On 13 Jul 2013, at 5:16 PM, Sean Farley wrote:
>
>> # HG changeset patch
>> # User Sean Farley <sean.michael.farley@gmail.com>
>> # Date 1373751187 18000
>> #      Sat Jul 13 16:33:07 2013 -0500
>> # Node ID 15a903bca551318cd0c3f42484374a8b8acd08e5
>> # Parent  3af3a165db18ed093394fe661e797bea296dc602
>> dispatch: move command line --config argument parsing to _runcatch()
>> 
>> Previously, command line parsing of --config arguments was done in
>> _dispatch. This means that it takes place after activating the debugger. In an
>> upcoming patch, we will add a ui.debugger setting so we need to have this
>> parsing done before _runcatch.
>
> One (probably) small issue: now we can't run the debugger (conveniently) on _parseconfig of options set on the command line.

I've adjusted this in the second version to trigger the debugger
correctly for an error in _parseconfig. Alternatively, we could call
_parseconfig twice?

Patch

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -86,10 +86,21 @@ 
     except ValueError:
         pass # happens if called in a thread
 
     try:
         try:
+
+            # read --config before doing anything else
+            # (e.g. to change trust settings for reading .hg/hgrc)
+            cfgs = _parseconfig(req.ui, _earlygetopt(['--config'], req.args))
+
+            if req.repo:
+                # copy configs that were passed on the cmdline (--config) to
+                # the repo ui
+                for cfg in cfgs:
+                    req.repo.ui.setconfig(*cfg)
+
             # enter the debugger before command execution
             if '--debugger' in req.args:
                 ui.warn(_("entering debugger - "
                         "type c to continue starting hg or h for help\n"))
                 pdb.set_trace()
@@ -617,14 +628,10 @@ 
 _loaded = set()
 def _dispatch(req):
     args = req.args
     ui = req.ui
 
-    # read --config before doing anything else
-    # (e.g. to change trust settings for reading .hg/hgrc)
-    cfgs = _parseconfig(ui, _earlygetopt(['--config'], args))
-
     # check for cwd
     cwd = _earlygetopt(['--cwd'], args)
     if cwd:
         os.chdir(cwd[-1])
 
@@ -697,14 +704,10 @@ 
     uis = set([ui, lui])
 
     if req.repo:
         uis.add(req.repo.ui)
 
-        # copy configs that were passed on the cmdline (--config) to the repo ui
-        for cfg in cfgs:
-            req.repo.ui.setconfig(*cfg)
-
     if options['verbose'] or options['debug'] or options['quiet']:
         for opt in ('verbose', 'debug', 'quiet'):
             val = str(bool(options[opt]))
             for ui_ in uis:
                 ui_.setconfig('ui', opt, val)