8 |
8 |
9 from mercurial import demandimport; demandimport.enable() |
9 from mercurial import demandimport; demandimport.enable() |
10 import os, mimetools, cStringIO |
10 import os, mimetools, cStringIO |
11 from mercurial.i18n import gettext as _ |
11 from mercurial.i18n import gettext as _ |
12 from mercurial import ui, hg, util, templater |
12 from mercurial import ui, hg, util, templater |
13 from common import get_mtime, staticfile, style_map |
13 from common import get_mtime, staticfile, style_map, paritygen |
14 from hgweb_mod import hgweb |
14 from hgweb_mod import hgweb |
15 |
15 |
16 # This is a stopgap |
16 # This is a stopgap |
17 class hgwebdir(object): |
17 class hgwebdir(object): |
18 def __init__(self, config, parentui=None): |
18 def __init__(self, config, parentui=None): |
20 return [(name.strip(os.sep), path) for name, path in items] |
20 return [(name.strip(os.sep), path) for name, path in items] |
21 |
21 |
22 self.parentui = parentui |
22 self.parentui = parentui |
23 self.motd = None |
23 self.motd = None |
24 self.style = None |
24 self.style = None |
|
25 self.stripecount = None |
25 self.repos_sorted = ('name', False) |
26 self.repos_sorted = ('name', False) |
26 if isinstance(config, (list, tuple)): |
27 if isinstance(config, (list, tuple)): |
27 self.repos = cleannames(config) |
28 self.repos = cleannames(config) |
28 self.repos_sorted = ('', False) |
29 self.repos_sorted = ('', False) |
29 elif isinstance(config, dict): |
30 elif isinstance(config, dict): |
39 if cp.has_section('web'): |
40 if cp.has_section('web'): |
40 if cp.has_option('web', 'motd'): |
41 if cp.has_option('web', 'motd'): |
41 self.motd = cp.get('web', 'motd') |
42 self.motd = cp.get('web', 'motd') |
42 if cp.has_option('web', 'style'): |
43 if cp.has_option('web', 'style'): |
43 self.style = cp.get('web', 'style') |
44 self.style = cp.get('web', 'style') |
|
45 if cp.has_option('web', 'stripes'): |
|
46 self.stripecount = int(cp.get('web', 'stripes')) |
44 if cp.has_section('paths'): |
47 if cp.has_section('paths'): |
45 self.repos.extend(cleannames(cp.items('paths'))) |
48 self.repos.extend(cleannames(cp.items('paths'))) |
46 if cp.has_section('collections'): |
49 if cp.has_section('collections'): |
47 for prefix, root in cp.items('collections'): |
50 for prefix, root in cp.items('collections'): |
48 for path in util.walkrepos(root): |
51 for path in util.walkrepos(root): |
95 style = self.style |
98 style = self.style |
96 if style is None: |
99 if style is None: |
97 style = config('web', 'style', '') |
100 style = config('web', 'style', '') |
98 if req.form.has_key('style'): |
101 if req.form.has_key('style'): |
99 style = req.form['style'][0] |
102 style = req.form['style'][0] |
|
103 if self.stripecount is None: |
|
104 self.stripecount = int(config('web', 'stripes', 1)) |
100 mapfile = style_map(templater.templatepath(), style) |
105 mapfile = style_map(templater.templatepath(), style) |
101 tmpl = templater.templater(mapfile, templater.common_filters, |
106 tmpl = templater.templater(mapfile, templater.common_filters, |
102 defaults={"header": header, |
107 defaults={"header": header, |
103 "footer": footer, |
108 "footer": footer, |
104 "motd": motd, |
109 "motd": motd, |
125 for name, value in fields: |
130 for name, value in fields: |
126 yield dict(name=name, value=value, separator=separator) |
131 yield dict(name=name, value=value, separator=separator) |
127 separator = ';' |
132 separator = ';' |
128 |
133 |
129 rows = [] |
134 rows = [] |
130 parity = 0 |
135 parity = paritygen(self.stripecount) |
131 for name, path in self.repos: |
136 for name, path in self.repos: |
132 u = ui.ui(parentui=parentui) |
137 u = ui.ui(parentui=parentui) |
133 try: |
138 try: |
134 u.readconfig(os.path.join(path, '.hg', 'hgrc')) |
139 u.readconfig(os.path.join(path, '.hg', 'hgrc')) |
135 except IOError: |
140 except IOError: |
163 sessionvars=sessionvars, |
168 sessionvars=sessionvars, |
164 archives=archivelist(u, "tip", url)) |
169 archives=archivelist(u, "tip", url)) |
165 if (not sortcolumn |
170 if (not sortcolumn |
166 or (sortcolumn, descending) == self.repos_sorted): |
171 or (sortcolumn, descending) == self.repos_sorted): |
167 # fast path for unsorted output |
172 # fast path for unsorted output |
168 row['parity'] = parity |
173 row['parity'] = parity.next() |
169 parity = 1 - parity |
|
170 yield row |
174 yield row |
171 else: |
175 else: |
172 rows.append((row["%s_sort" % sortcolumn], row)) |
176 rows.append((row["%s_sort" % sortcolumn], row)) |
173 if rows: |
177 if rows: |
174 rows.sort() |
178 rows.sort() |
175 if descending: |
179 if descending: |
176 rows.reverse() |
180 rows.reverse() |
177 for key, row in rows: |
181 for key, row in rows: |
178 row['parity'] = parity |
182 row['parity'] = parity.next() |
179 parity = 1 - parity |
|
180 yield row |
183 yield row |
181 |
184 |
182 try: |
185 try: |
183 virtual = req.env.get("PATH_INFO", "").strip('/') |
186 virtual = req.env.get("PATH_INFO", "").strip('/') |
184 if virtual.startswith('static/'): |
187 if virtual.startswith('static/'): |