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

Alexander Solovyov piranha at piranha.org.ua
Fri Apr 24 23:58:47 CDT 2009


# HG changeset patch
# User Alexander Solovyov <piranha at piranha.org.ua>
# Date 1239291072 -10800
# Node ID 524d07af14faf924a939c6dbd4cac66b12eb196a
# Parent  6f14253416bdc9e35dc8a9c10590637322d84689
hgwebdir: read --webdir-conf as actual configuration to ui (issue 1586)

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

diff --git a/mercurial/config.py b/mercurial/config.py
--- a/mercurial/config.py
+++ b/mercurial/config.py
@@ -56,6 +56,8 @@ class config:
         if section not in self:
             self._data[section] = sortdict()
         self._data[section][item] = (value, source)
+    def remove_section(self, section):
+        del self._data[section]
 
     def read(self, path, fp):
         sectionre = re.compile(r'\[([^\[]+)\]')
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,6 +21,11 @@ class hgwebdir(object):
             return [(util.pconvert(name).strip('/'), path)
                     for name, path in items]
 
+        # parentui will contain 'paths' if they were present in user
+        # or system-wide config. They should be dropped.
+        if parentui and parentui.configitems('paths'):
+            parentui.cdata.remove_section('paths')
+
         if parentui:
            self.parentui = parentui
         else:
@@ -28,62 +33,56 @@ class hgwebdir(object):
             self.parentui.setconfig('ui', 'report_untrusted', 'off')
             self.parentui.setconfig('ui', 'interactive', 'off')
 
-        self.motd = None
-        self.style = 'paper'
-        self.stripecount = None
         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