Commits

Yuya Nishihara committed 5e43851

serve: merge logic of reading local ui and webconf

Comments (0)

Files changed (1)

tortoisehg/hgqt/serve.py

     else:
         return value
 
-def _readconfig(repopath, webconfpath):
-    """create config obj for hgweb"""
+def _readconfig(ui, repopath, webconfpath):
+    """Create new ui and webconf object and read appropriate files"""
+    lui = ui.copy()
     if webconfpath:
+        lui.readconfig(webconfpath)
         # TODO: handle file not found
         c = wconfig.readfile(webconfpath)
         c.path = os.path.abspath(webconfpath)
-        return c
+        return lui, c
     elif repopath:  # imitate webconf for single repo
+        lui.readconfig(os.path.join(repopath, '.hg', 'hgrc'), repopath)
         c = wconfig.config()
         try:
             # TODO: not nice to instantiate repo just for repo.shortname
                       _asconfigliststr(os.path.join(repopath, '**')))
         except (EnvironmentError, error.Abort, error.RepoError):
             c.set('paths', '/', repopath)
-        return c
+        return lui, c
+    else:
+        return lui, None
 
 def run(ui, *pats, **opts):
     repopath = opts.get('root') or paths.find_root()
     webconfpath = opts.get('web_conf') or opts.get('webdir_conf')
 
-    webconf = _readconfig(repopath, webconfpath)
+    lui, webconf = _readconfig(ui, repopath, webconfpath)
     dlg = ServeDialog(webconf=webconf)
-
-    lui = ui.copy()
-    if webconfpath:
-        lui.readconfig(webconfpath)
-    elif repopath:
-        lui.readconfig(os.path.join(repopath, '.hg', 'hgrc'), repopath)
     try:
         dlg.setport(int(lui.config('web', 'port', '8000')))
     except ValueError: