##// END OF EJS Templates
hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman -
r5601:8279cb84 default
parent child Browse files
Show More
@@ -20,7 +20,8 b' class hgwebdir(object):'
20 return [(util.pconvert(name).strip('/'), path)
20 return [(util.pconvert(name).strip('/'), path)
21 for name, path in items]
21 for name, path in items]
22
22
23 self.parentui = parentui
23 self.parentui = parentui or ui.ui(report_untrusted=False,
24 interactive = False)
24 self.motd = None
25 self.motd = None
25 self.style = None
26 self.style = None
26 self.stripecount = None
27 self.stripecount = None
@@ -85,11 +86,8 b' class hgwebdir(object):'
85 else:
86 else:
86 yield config('web', 'motd', '')
87 yield config('web', 'motd', '')
87
88
88 parentui = self.parentui or ui.ui(report_untrusted=False,
89 interactive=False)
90
91 def config(section, name, default=None, untrusted=True):
89 def config(section, name, default=None, untrusted=True):
92 return parentui.config(section, name, default, untrusted)
90 return self.parentui.config(section, name, default, untrusted)
93
91
94 url = req.env.get('SCRIPT_NAME', '')
92 url = req.env.get('SCRIPT_NAME', '')
95 if not url.endswith('/'):
93 if not url.endswith('/'):
@@ -114,6 +112,54 b' class hgwebdir(object):'
114 "url": url,
112 "url": url,
115 "staticurl": staticurl})
113 "staticurl": staticurl})
116
114
115 try:
116 try:
117 virtual = req.env.get("PATH_INFO", "").strip('/')
118 if virtual.startswith('static/'):
119 static = os.path.join(templater.templatepath(), 'static')
120 fname = virtual[7:]
121 req.write(staticfile(static, fname, req))
122 elif virtual:
123 repos = dict(self.repos)
124 while virtual:
125 real = repos.get(virtual)
126 if real:
127 req.env['REPO_NAME'] = virtual
128 try:
129 repo = hg.repository(self.parentui, real)
130 hgweb(repo).run_wsgi(req)
131 return
132 except IOError, inst:
133 raise ErrorResponse(500, inst.strerror)
134 except hg.RepoError, inst:
135 raise ErrorResponse(500, str(inst))
136
137 # browse subdirectories
138 subdir = virtual + '/'
139 if [r for r in repos if r.startswith(subdir)]:
140 self.makeindex(req, tmpl, subdir)
141 return
142
143 up = virtual.rfind('/')
144 if up < 0:
145 break
146 virtual = virtual[:up]
147
148 req.respond(404, tmpl("notfound", repo=virtual))
149 else:
150 if req.form.has_key('static'):
151 static = os.path.join(templater.templatepath(), "static")
152 fname = req.form['static'][0]
153 req.write(staticfile(static, fname, req))
154 else:
155 self.makeindex(req, tmpl)
156 except ErrorResponse, err:
157 req.respond(err.code, tmpl('error', error=err.message or ''))
158 finally:
159 tmpl = None
160
161 def makeindex(self, req, tmpl, subdir=""):
162
117 def archivelist(ui, nodeid, url):
163 def archivelist(ui, nodeid, url):
118 allowed = ui.configlist("web", "allow_archive", untrusted=True)
164 allowed = ui.configlist("web", "allow_archive", untrusted=True)
119 for i in [('zip', '.zip'), ('gz', '.tar.gz'), ('bz2', '.tar.bz2')]:
165 for i in [('zip', '.zip'), ('gz', '.tar.gz'), ('bz2', '.tar.bz2')]:
@@ -142,7 +188,7 b' class hgwebdir(object):'
142 continue
188 continue
143 name = name[len(subdir):]
189 name = name[len(subdir):]
144
190
145 u = ui.ui(parentui=parentui)
191 u = ui.ui(parentui=self.parentui)
146 try:
192 try:
147 u.readconfig(os.path.join(path, '.hg', 'hgrc'))
193 u.readconfig(os.path.join(path, '.hg', 'hgrc'))
148 except Exception, e:
194 except Exception, e:
@@ -196,67 +242,20 b' class hgwebdir(object):'
196 row['parity'] = parity.next()
242 row['parity'] = parity.next()
197 yield row
243 yield row
198
244
199 def makeindex(req, subdir=""):
245 sortable = ["name", "description", "contact", "lastchange"]
200 sortable = ["name", "description", "contact", "lastchange"]
246 sortcolumn, descending = self.repos_sorted
201 sortcolumn, descending = self.repos_sorted
247 if req.form.has_key('sort'):
202 if req.form.has_key('sort'):
248 sortcolumn = req.form['sort'][0]
203 sortcolumn = req.form['sort'][0]
249 descending = sortcolumn.startswith('-')
204 descending = sortcolumn.startswith('-')
250 if descending:
205 if descending:
251 sortcolumn = sortcolumn[1:]
206 sortcolumn = sortcolumn[1:]
252 if sortcolumn not in sortable:
207 if sortcolumn not in sortable:
253 sortcolumn = ""
208 sortcolumn = ""
209
210 sort = [("sort_%s" % column,
211 "%s%s" % ((not descending and column == sortcolumn)
212 and "-" or "", column))
213 for column in sortable]
214 req.write(tmpl("index", entries=entries, subdir=subdir,
215 sortcolumn=sortcolumn, descending=descending,
216 **dict(sort)))
217
254
218 try:
255 sort = [("sort_%s" % column,
219 try:
256 "%s%s" % ((not descending and column == sortcolumn)
220 virtual = req.env.get("PATH_INFO", "").strip('/')
257 and "-" or "", column))
221 if virtual.startswith('static/'):
258 for column in sortable]
222 static = os.path.join(templater.templatepath(), 'static')
259 req.write(tmpl("index", entries=entries, subdir=subdir,
223 fname = virtual[7:]
260 sortcolumn=sortcolumn, descending=descending,
224 req.write(staticfile(static, fname, req))
261 **dict(sort)))
225 elif virtual:
226 repos = dict(self.repos)
227 while virtual:
228 real = repos.get(virtual)
229 if real:
230 req.env['REPO_NAME'] = virtual
231 try:
232 repo = hg.repository(parentui, real)
233 hgweb(repo).run_wsgi(req)
234 return
235 except IOError, inst:
236 raise ErrorResponse(500, inst.strerror)
237 except hg.RepoError, inst:
238 raise ErrorResponse(500, str(inst))
239
240 # browse subdirectories
241 subdir = virtual + '/'
242 if [r for r in repos if r.startswith(subdir)]:
243 makeindex(req, subdir)
244 return
245
246 up = virtual.rfind('/')
247 if up < 0:
248 break
249 virtual = virtual[:up]
250
251 req.respond(404, tmpl("notfound", repo=virtual))
252 else:
253 if req.form.has_key('static'):
254 static = os.path.join(templater.templatepath(), "static")
255 fname = req.form['static'][0]
256 req.write(staticfile(static, fname, req))
257 else:
258 makeindex(req)
259 except ErrorResponse, err:
260 req.respond(err.code, tmpl('error', error=err.message or ''))
261 finally:
262 tmpl = None
@@ -27,7 +27,7 b' b=$root/b'
27 EOF
27 EOF
28
28
29 hg serve -p $HGPORT -d --pid-file=hg.pid --webdir-conf paths.conf \
29 hg serve -p $HGPORT -d --pid-file=hg.pid --webdir-conf paths.conf \
30 -A access-paths.log -E error-paths.log
30 -A access-paths.log -E error-paths-1.log
31 cat hg.pid >> $DAEMON_PIDS
31 cat hg.pid >> $DAEMON_PIDS
32
32
33 echo % should give a 404 - file does not exist
33 echo % should give a 404 - file does not exist
@@ -48,7 +48,7 b' b=$root/b'
48 EOF
48 EOF
49
49
50 hg serve -p $HGPORT1 -d --pid-file=hg.pid --webdir-conf paths.conf \
50 hg serve -p $HGPORT1 -d --pid-file=hg.pid --webdir-conf paths.conf \
51 -A access-paths.log -E error-paths.log
51 -A access-paths.log -E error-paths-2.log
52 cat hg.pid >> $DAEMON_PIDS
52 cat hg.pid >> $DAEMON_PIDS
53
53
54 echo % should succeed, slashy names
54 echo % should succeed, slashy names
@@ -75,3 +75,10 b' echo % should succeed'
75 "$TESTDIR/get-with-headers.py" localhost:$HGPORT2 '/a/file/tip/a?style=raw'
75 "$TESTDIR/get-with-headers.py" localhost:$HGPORT2 '/a/file/tip/a?style=raw'
76 "$TESTDIR/get-with-headers.py" localhost:$HGPORT2 '/b/file/tip/b?style=raw'
76 "$TESTDIR/get-with-headers.py" localhost:$HGPORT2 '/b/file/tip/b?style=raw'
77 "$TESTDIR/get-with-headers.py" localhost:$HGPORT2 '/c/file/tip/c?style=raw'
77 "$TESTDIR/get-with-headers.py" localhost:$HGPORT2 '/c/file/tip/c?style=raw'
78
79 echo % paths errors 1
80 cat error-paths-1.log
81 echo % paths errors 2
82 cat error-paths-2.log
83 echo % collections errors
84 cat error-collections.log
@@ -119,3 +119,6 b' b'
119 200 Script output follows
119 200 Script output follows
120
120
121 c
121 c
122 % paths errors 1
123 % paths errors 2
124 % collections errors
General Comments 0
You need to be logged in to leave comments. Login now