chgserver: make _renewui load repo and command line configs
authorJun Wu <quark@fb.com>
Fri, 26 Feb 2016 15:22:46 +0000
changeset 28264 3682e201cce6
parent 28263 59509c6724c7
child 28265 332926212ef8
chgserver: make _renewui load repo and command line configs Before this patch, there is no way to load repo config in chgserver. This patch revised _renewui to let it load repo config and take command line flags passed into consideration. The _renewui logic is not ideal at present because it's very tricky to know what should copy and what should not from the old ui object to the new one. This is partially because the current ui and config object design is not ideal. In the future, we may want to avoid all ui or config copies.
hgext/chgserver.py
--- a/hgext/chgserver.py	Fri Feb 26 15:07:58 2016 +0000
+++ b/hgext/chgserver.py	Fri Feb 26 15:22:46 2016 +0000
@@ -180,17 +180,35 @@
 
     return chgui(srcui)
 
-def _renewui(srcui):
+def _renewui(srcui, args=None):
+    if not args:
+        args = []
+
     newui = srcui.__class__()
     for a in ['fin', 'fout', 'ferr', 'environ']:
         setattr(newui, a, getattr(srcui, a))
     if util.safehasattr(srcui, '_csystem'):
         newui._csystem = srcui._csystem
+
+    # load wd and repo config, copied from dispatch.py
+    cwds = dispatch._earlygetopt(['--cwd'], args)
+    cwd = cwds and os.path.realpath(cwds[-1]) or None
+    rpath = dispatch._earlygetopt(["-R", "--repository", "--repo"], args)
+    path, newui = dispatch._getlocal(newui, rpath, wd=cwd)
+
+    # internal config: extensions.chgserver
+    # copy it. it can only be overrided from command line.
+    newui.setconfig('extensions', 'chgserver',
+                    srcui.config('extensions', 'chgserver'), '--config')
+
+    # command line args
+    dispatch._parseconfig(newui, dispatch._earlygetopt(['--config'], args))
+
     # stolen from tortoisehg.util.copydynamicconfig()
     for section, name, value in srcui.walkconfig():
         source = srcui.configsource(section, name)
-        if ':' in source:
-            # path:line
+        if ':' in source or source == '--config':
+            # path:line or command line
             continue
         if source == 'none':
             # ui.configsource returns 'none' by default