[PATCH 1 of 2] hgweb: move code to read paths configuration into a separate method
Markus Zapke-Gründemann
markuszapke at gmx.net
Wed Nov 28 10:58:45 CST 2012
# HG changeset patch
# User Markus Zapke-Gründemann <markus at keimlink.de>
# Date 1354120937 -3600
# Branch stable
# Node ID 24b51d1e0d0d8c17b71d3557f570d2c4fa0b9b9d
# Parent 54cedee86e5126188b0dcfbd7015bcdca7f6c2e2
hgweb: move code to read paths configuration into a separate method
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
@@ -83,38 +83,40 @@ class hgwebdir(object):
def __init__(self, conf, baseui=None):
self.conf = conf
- self.baseui = baseui
+ if baseui:
+ self.ui = baseui.copy()
+ else:
+ self.ui = ui.ui()
+ self.ui.setconfig('ui', 'report_untrusted', 'off')
+ self.ui.setconfig('ui', 'nontty', 'true')
self.lastrefresh = 0
self.motd = None
self.refresh()
+ def getpaths(self, clean=False):
+ if not isinstance(self.conf, (dict, list, tuple)):
+ map = {'paths': 'hgweb-paths'}
+ if not os.path.exists(self.conf):
+ raise util.Abort(_('config file %s not found!') % self.conf)
+ self.ui.readconfig(self.conf, remap=map, trust=True)
+ paths = []
+ for name, ignored in self.ui.configitems('hgweb-paths'):
+ for path in self.ui.configlist('hgweb-paths', name):
+ paths.append((name, path))
+ elif isinstance(self.conf, (list, tuple)):
+ paths = self.conf
+ elif isinstance(self.conf, dict):
+ paths = self.conf.items()
+ if clean:
+ paths = dict(cleannames(paths))
+ return paths
+
def refresh(self):
if self.lastrefresh + self.refreshinterval > time.time():
return
- if self.baseui:
- u = self.baseui.copy()
- else:
- u = ui.ui()
- u.setconfig('ui', 'report_untrusted', 'off')
- u.setconfig('ui', 'nontty', 'true')
-
- if not isinstance(self.conf, (dict, list, tuple)):
- map = {'paths': 'hgweb-paths'}
- if not os.path.exists(self.conf):
- raise util.Abort(_('config file %s not found!') % self.conf)
- u.readconfig(self.conf, remap=map, trust=True)
- paths = []
- for name, ignored in u.configitems('hgweb-paths'):
- for path in u.configlist('hgweb-paths', name):
- paths.append((name, path))
- elif isinstance(self.conf, (list, tuple)):
- paths = self.conf
- elif isinstance(self.conf, dict):
- paths = self.conf.items()
-
- repos = findrepos(paths)
- for prefix, root in u.configitems('collections'):
+ repos = findrepos(self.getpaths())
+ for prefix, root in self.ui.configitems('collections'):
prefix = util.pconvert(prefix)
for path in scmutil.walkrepos(root, followsym=True):
repo = os.path.normpath(path)
@@ -124,7 +126,6 @@ class hgwebdir(object):
repos.append((name.lstrip('/'), repo))
self.repos = repos
- self.ui = u
encoding.encoding = self.ui.config('web', 'encoding',
encoding.encoding)
self.style = self.ui.config('web', 'style', 'paper')
More information about the Mercurial-devel
mailing list