[PATCH 10 of 10] move the parsing of --config options to commands.py

Alexis S. L. Carvalho alexis at cecm.usp.br
Thu Sep 21 22:05:22 UTC 2006


# HG changeset patch
# User Alexis S. L. Carvalho <alexis at cecm.usp.br>
# Date 1158879801 10800
# Node ID b8074e035c125b567bab81376237c1d421622621
# Parent  37975c3177f02cfa7f549d6a1dcd936e7141da91
move the parsing of --config options to commands.py

diff -r 37975c3177f0 -r b8074e035c12 mercurial/commands.py
--- a/mercurial/commands.py	Thu Sep 21 20:03:20 2006 -0300
+++ b/mercurial/commands.py	Thu Sep 21 20:03:21 2006 -0300
@@ -3212,7 +3212,21 @@ def load_extensions(ui):
             if t in table:
                 ui.warn(_("module %s overrides %s\n") % (name, t))
         table.update(cmdtable)
-    
+
+def parseconfig(config):
+    """parse the --config options from the command line"""
+    parsed = []
+    for cfg in config:
+        try:
+            name, value = cfg.split('=', 1)
+            section, name = name.split('.', 1)
+            if not section or not name:
+                raise IndexError
+            parsed.append((section, name, value))
+        except (IndexError, ValueError):
+            raise util.Abort(_('malformed --config option: %s') % cfg)
+    return parsed
+
 def dispatch(args):
     for name in 'SIGBREAK', 'SIGHUP', 'SIGTERM':
         num = getattr(signal, name, None)
@@ -3244,7 +3258,7 @@ def dispatch(args):
 
         u.updateopts(options["verbose"], options["debug"], options["quiet"],
                      not options["noninteractive"], options["traceback"],
-                     options["config"])
+                     parseconfig(options["config"]))
 
         # enter the debugger before command execution
         if options['debugger']:
diff -r 37975c3177f0 -r b8074e035c12 mercurial/ui.py
--- a/mercurial/ui.py	Thu Sep 21 20:03:20 2006 -0300
+++ b/mercurial/ui.py	Thu Sep 21 20:03:21 2006 -0300
@@ -65,15 +65,8 @@ class ui(object):
         self.debugflag = (self.debugflag or debug)
         self.interactive = (self.interactive and interactive)
         self.traceback = self.traceback or traceback
-        for cfg in config:
-            try:
-                name, value = cfg.split('=', 1)
-                section, name = name.split('.', 1)
-                if not section or not name:
-                    raise IndexError
-                self.setconfig(section, name, value)
-            except (IndexError, ValueError):
-                raise util.Abort(_('malformed --config option: %s') % cfg)
+        for section, name, value in config:
+            self.setconfig(section, name, value)
 
     def readconfig(self, fn, root=None):
         if isinstance(fn, basestring):
diff -r 37975c3177f0 -r b8074e035c12 tests/test-ui-config
--- a/tests/test-ui-config	Thu Sep 21 20:03:20 2006 -0300
+++ b/tests/test-ui-config	Thu Sep 21 20:03:21 2006 -0300
@@ -1,9 +1,9 @@
 #!/usr/bin/env python
 
-from mercurial import ui, util
+from mercurial import ui, util, commands
 
 testui = ui.ui()
-testui.updateopts(config=[
+parsed = commands.parseconfig([
     'values.string=string value',
     'values.bool1=true',
     'values.bool2=false',
@@ -17,6 +17,7 @@ testui.updateopts(config=[
     'interpolation.value4=%(bad)1',
     'interpolation.value5=%bad2',
 ])
+testui.updateopts(config=parsed)
 
 print repr(testui.configitems('values'))
 print repr(testui.configitems('lists'))



More information about the Mercurial mailing list