0d132beefc84 2009-04-27 22 13 0300 piranha 8234 hgwebdir diff hgwebdir

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
0d132beefc84 2009-04-27 22:13 +0300 piranha 8234[hgwebdir.diff]
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
@@ -68,6 +68,8 @@ class config(object):
self._data[section] = sortdict()
self._data[section][item] = value
self._source[(section, item)] = source
+ def remove_section(self, section):
+ del self._data[section]
def read(self, path, fp=None, sections=None):
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
@@ -9,7 +9,7 @@
import os
from mercurial.i18n import _
from mercurial import ui, hg, util, templater, templatefilters
-from mercurial import config, error, encoding
+from mercurial import error, encoding
from common import ErrorResponse, get_mtime, staticfile, paritygen,\
get_contact, HTTP_OK, HTTP_NOT_FOUND, HTTP_SERVER_ERROR
from hgweb_mod import hgweb
@@ -25,16 +25,16 @@ class hgwebdir(object):
if baseui:
self.ui = baseui.copy()
+ # ui will contain 'paths' if they were present in user or
+ # system-wide config. They should be dropped.
+ if self.ui.has_section('paths'):
+ self.ui.remove_section('paths')
else:
self.ui = ui.ui()
self.ui.setconfig('ui', 'report_untrusted', 'off')
self.ui.setconfig('ui', 'interactive', 'off')
- self.motd = None
- self.style = 'paper'
- self.stripecount = 1
self.repos_sorted = ('name', False)
- self._baseurl = None
if isinstance(conf, (list, tuple)):
self.repos = cleannames(conf)
@@ -42,45 +42,49 @@ class hgwebdir(object):
elif isinstance(conf, dict):
self.repos = sorted(cleannames(conf.items()))
else:
- if isinstance(conf, config.config):
- cp = conf
- else:
- cp = config.config()
- cp.read(conf)
+ self.ui.readconfig(conf)
self.repos = []
- self.motd = cp.get('web', 'motd')
- self.style = cp.get('web', 'style', 'paper')
- self.stripecount = cp.get('web', 'stripes', 1)
- self._baseurl = cp.get('web', 'baseurl')
- if 'paths' in cp:
- 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))
- 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.ui.config('web', 'motd')
+ self.style = self.ui.config('web', 'style', 'paper')
+ self.stripecount = self.ui.config('web', 'stripes', 1)
+ if self.stripecount:
+ self.stripecount = int(self.stripecount)
+ self._baseurl = self.ui.config('web', 'baseurl')
+
+ if self.repos:
+ return
+
+ for prefix, root in cleannames(self.ui.configitems('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:
+ if hg.islocal(root):
+ 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))
+
+ for prefix, root in self.ui.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."):
diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -151,6 +151,10 @@ class ui(object):
'''tell whether section exists in config.'''
return section in self._data(untrusted)
+ def remove_section(self, section, untrusted=False):
+ '''remove section from config.'''
+ self._data(untrusted).remove_section(section)
+
def configitems(self, section, untrusted=False):
items = self._data(untrusted).items(section)
if self.debugflag and not untrusted and self._reportuntrusted: