##// END OF EJS Templates
hgwebdir: read --webdir-conf as actual configuration to ui (issue1586)...
Alexander Solovyov -
r8345:dcebff8a default
parent child Browse files
Show More
@@ -9,7 +9,7 b''
9 9 import os
10 10 from mercurial.i18n import _
11 11 from mercurial import ui, hg, util, templater, templatefilters
12 from mercurial import config, error, encoding
12 from mercurial import error, encoding
13 13 from common import ErrorResponse, get_mtime, staticfile, paritygen,\
14 14 get_contact, HTTP_OK, HTTP_NOT_FOUND, HTTP_SERVER_ERROR
15 15 from hgweb_mod import hgweb
@@ -30,11 +30,7 b' class hgwebdir(object):'
30 30 self.ui.setconfig('ui', 'report_untrusted', 'off')
31 31 self.ui.setconfig('ui', 'interactive', 'off')
32 32
33 self.motd = None
34 self.style = 'paper'
35 self.stripecount = 1
36 33 self.repos_sorted = ('name', False)
37 self._baseurl = None
38 34
39 35 if isinstance(conf, (list, tuple)):
40 36 self.repos = cleannames(conf)
@@ -42,45 +38,48 b' class hgwebdir(object):'
42 38 elif isinstance(conf, dict):
43 39 self.repos = sorted(cleannames(conf.items()))
44 40 else:
45 if isinstance(conf, config.config):
46 cp = conf
47 else:
48 cp = config.config()
49 cp.read(conf)
41 self.ui.readconfig(conf, remap={'paths': 'hgweb-paths'})
50 42 self.repos = []
51 self.motd = cp.get('web', 'motd')
52 self.style = cp.get('web', 'style', 'paper')
53 self.stripecount = cp.get('web', 'stripes', 1)
54 self._baseurl = cp.get('web', 'baseurl')
55 if 'paths' in cp:
56 paths = cleannames(cp.items('paths'))
57 for prefix, root in paths:
58 roothead, roottail = os.path.split(root)
59 # "foo = /bar/*" makes every subrepo of /bar/ to be
60 # mounted as foo/subrepo
61 # and "foo = /bar/**" does even recurse inside the
62 # subdirectories, remember to use it without working dir.
63 try:
64 recurse = {'*': False, '**': True}[roottail]
65 except KeyError:
66 self.repos.append((prefix, root))
67 continue
68 roothead = os.path.normpath(roothead)
69 for path in util.walkrepos(roothead, followsym=True,
70 recurse=recurse):
71 path = os.path.normpath(path)
72 name = util.pconvert(path[len(roothead):]).strip('/')
73 if prefix:
74 name = prefix + '/' + name
75 self.repos.append((name, path))
76 for prefix, root in cp.items('collections'):
77 for path in util.walkrepos(root, followsym=True):
78 repo = os.path.normpath(path)
79 name = repo
80 if name.startswith(prefix):
81 name = name[len(prefix):]
82 self.repos.append((name.lstrip(os.sep), repo))
83 self.repos.sort()
43
44 self.motd = self.ui.config('web', 'motd')
45 self.style = self.ui.config('web', 'style', 'paper')
46 self.stripecount = self.ui.config('web', 'stripes', 1)
47 if self.stripecount:
48 self.stripecount = int(self.stripecount)
49 self._baseurl = self.ui.config('web', 'baseurl')
50
51 if self.repos:
52 return
53
54 for prefix, root in cleannames(self.ui.configitems('hgweb-paths')):
55 roothead, roottail = os.path.split(root)
56 # "foo = /bar/*" makes every subrepo of /bar/ to be
57 # mounted as foo/subrepo
58 # and "foo = /bar/**" also recurses into the subdirectories,
59 # remember to use it without working dir.
60 try:
61 recurse = {'*': False, '**': True}[roottail]
62 except KeyError:
63 self.repos.append((prefix, root))
64 continue
65 roothead = os.path.normpath(roothead)
66 for path in util.walkrepos(roothead, followsym=True,
67 recurse=recurse):
68 path = os.path.normpath(path)
69 name = util.pconvert(path[len(roothead):]).strip('/')
70 if prefix:
71 name = prefix + '/' + name
72 self.repos.append((name, path))
73
74 for prefix, root in self.ui.configitems('collections'):
75 for path in util.walkrepos(root, followsym=True):
76 repo = os.path.normpath(path)
77 name = repo
78 if name.startswith(prefix):
79 name = name[len(prefix):]
80 self.repos.append((name.lstrip(os.sep), repo))
81
82 self.repos.sort()
84 83
85 84 def run(self):
86 85 if not os.environ.get('GATEWAY_INTERFACE', '').startswith("CGI/1."):
@@ -58,7 +58,7 b' class ui(object):'
58 58 return False
59 59
60 60 def readconfig(self, filename, root=None, trust=False,
61 sections=None):
61 sections=None, remap=None):
62 62 try:
63 63 fp = open(filename)
64 64 except IOError:
@@ -70,7 +70,7 b' class ui(object):'
70 70 trusted = sections or trust or self._is_trusted(fp, filename)
71 71
72 72 try:
73 cfg.read(filename, fp, sections=sections)
73 cfg.read(filename, fp, sections=sections, remap=remap)
74 74 except error.ConfigError, inst:
75 75 if trusted:
76 76 raise
General Comments 0
You need to be logged in to leave comments. Login now