[PATCH 1 of 2] hgwebdir: read --webdir-conf as actual configuration to ui

Alexander Solovyov piranha at piranha.org.ua
Thu Apr 9 10:38:28 CDT 2009


# HG changeset patch
# User Alexander Solovyov <piranha at piranha.org.ua>
# Date 1239291072 -10800
# Node ID ccc09593c00ff5edaf165e582c84193fdece2f71
# Parent  18081ce1e6300bc2e9c0849751e57eaec7c0c4a1
hgwebdir: read --webdir-conf as actual configuration to ui

This cleans up code and allows specification of values more globally. For
example, it's now possible to specify web.contact for all repositories with
unspecified contact in webdir-conf.

diff --git a/mercurial/hgweb/hgwebdir_mod.py b/mercurial/hgweb/hgwebdir_mod.py
--- a/mercurial/hgweb/hgwebdir_mod.py
+++ b/mercurial/hgweb/hgwebdir_mod.py
@@ -21,64 +21,63 @@ class hgwebdir(object):
             return [(util.pconvert(name).strip('/'), path)
                     for name, path in items]
 
+        # not sure this is necessary here
+        # looks like parentui always is almost clean
+        if parentui and parentui.configitems('paths'):
+            parentui.cdata.drop_section('paths')
+
         self.parentui = parentui or ui.ui(report_untrusted=False,
-                                          interactive = False)
-        self.motd = None
-        self.style = 'paper'
-        self.stripecount = None
+                                          interactive=False)
         self.repos_sorted = ('name', False)
-        self._baseurl = None
         if isinstance(config, (list, tuple)):
             self.repos = cleannames(config)
             self.repos_sorted = ('', False)
         elif isinstance(config, dict):
             self.repos = util.sort(cleannames(config.items()))
         else:
-            if isinstance(config, util.configparser):
-                cp = config
-            else:
-                cp = util.configparser()
-                cp.read(config)
+            self.parentui.readconfig(config)
             self.repos = []
-            if cp.has_section('web'):
-                if cp.has_option('web', 'motd'):
-                    self.motd = cp.get('web', 'motd')
-                if cp.has_option('web', 'style'):
-                    self.style = cp.get('web', 'style')
-                if cp.has_option('web', 'stripes'):
-                    self.stripecount = int(cp.get('web', 'stripes'))
-                if cp.has_option('web', 'baseurl'):
-                    self._baseurl = cp.get('web', 'baseurl')
-            if cp.has_section('paths'):
-                paths = cleannames(cp.items('paths'))
-                for prefix, root in paths:
-                    roothead, roottail = os.path.split(root)
-                    # "foo = /bar/*" makes every subrepo of /bar/ to be
-                    # mounted as foo/subrepo
-                    # and "foo = /bar/**" does even recurse inside the
-                    # subdirectories, remember to use it without working dir.
-                    try:
-                        recurse = {'*': False, '**': True}[roottail]
-                    except KeyError:
-                        self.repos.append((prefix, root))
-                        continue
-                    roothead = os.path.normpath(roothead)
-                    for path in util.walkrepos(roothead, followsym=True,
-                                               recurse=recurse):
-                        path = os.path.normpath(path)
-                        name = util.pconvert(path[len(roothead):]).strip('/')
-                        if prefix:
-                            name = prefix + '/' + name
-                        self.repos.append((name, path))
-            if cp.has_section('collections'):
-                for prefix, root in cp.items('collections'):
-                    for path in util.walkrepos(root, followsym=True):
-                        repo = os.path.normpath(path)
-                        name = repo
-                        if name.startswith(prefix):
-                            name = name[len(prefix):]
-                        self.repos.append((name.lstrip(os.sep), repo))
-            self.repos.sort()
+
+        self.motd = self.parentui.config('web', 'motd')
+        self.style = self.parentui.config('web', 'style', 'paper')
+        self.stripecount = self.parentui.config('web', 'stripes')
+        if self.stripecount:
+            self.stripecount = int(self.stripecount)
+        self._baseurl = self.parentui.config('web', 'baseurl')
+
+        if self.repos:
+            return
+
+        if self.parentui.configitems('paths'):
+            paths = cleannames(self.parentui.configitems('paths'))
+            for prefix, root in paths:
+                roothead, roottail = os.path.split(root)
+                # "foo = /bar/*" makes every subrepo of /bar/ to be
+                # mounted as foo/subrepo
+                # and "foo = /bar/**" does even recurse inside the
+                # subdirectories, remember to use it without working dir.
+                try:
+                    recurse = {'*': False, '**': True}[roottail]
+                except KeyError:
+                    self.repos.append((prefix, root))
+                    continue
+                roothead = os.path.normpath(roothead)
+                for path in util.walkrepos(roothead, followsym=True,
+                                           recurse=recurse):
+                    path = os.path.normpath(path)
+                    name = util.pconvert(path[len(roothead):]).strip('/')
+                    if prefix:
+                        name = prefix + '/' + name
+                    self.repos.append((name, path))
+        if self.parentui.configitems('collections'):
+            for prefix, root in self.parentui.configitems('collections'):
+                for path in util.walkrepos(root, followsym=True):
+                    repo = os.path.normpath(path)
+                    name = repo
+                    if name.startswith(prefix):
+                        name = name[len(prefix):]
+                    self.repos.append((name.lstrip(os.sep), repo))
+        self.repos.sort()
 
     def run(self):
         if not os.environ.get('GATEWAY_INTERFACE', '').startswith("CGI/1."):


More information about the Mercurial-devel mailing list