Mercurial > public > mercurial-scm > hg
comparison mercurial/hgweb/hgwebdir_mod.py @ 32004:bd3cb917761a
hgwebdir: allow a repository to be hosted at "/"
This can be useful in general, but will also be useful for hosting subrepos,
with the main repo at /.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Fri, 31 Mar 2017 23:00:41 -0400 |
parents | da7d19324b1e |
children | eede022fc142 |
comparison
equal
deleted
inserted
replaced
32003:84569d2b3fb7 | 32004:bd3cb917761a |
---|---|
255 | 255 |
256 # top-level index | 256 # top-level index |
257 | 257 |
258 repos = dict(self.repos) | 258 repos = dict(self.repos) |
259 | 259 |
260 if not virtual or (virtual == 'index' and virtual not in repos): | 260 if (not virtual or virtual == 'index') and virtual not in repos: |
261 req.respond(HTTP_OK, ctype) | 261 req.respond(HTTP_OK, ctype) |
262 return self.makeindex(req, tmpl) | 262 return self.makeindex(req, tmpl) |
263 | 263 |
264 # nested indexes and hgwebs | 264 # nested indexes and hgwebs |
265 | 265 |
267 subdir = virtual[:-len('index')] | 267 subdir = virtual[:-len('index')] |
268 if any(r.startswith(subdir) for r in repos): | 268 if any(r.startswith(subdir) for r in repos): |
269 req.respond(HTTP_OK, ctype) | 269 req.respond(HTTP_OK, ctype) |
270 return self.makeindex(req, tmpl, subdir) | 270 return self.makeindex(req, tmpl, subdir) |
271 | 271 |
272 virtualrepo = virtual | 272 def _virtualdirs(): |
273 while virtualrepo: | 273 # Check the full virtual path, each parent, and the root ('') |
274 if virtual != '': | |
275 yield virtual | |
276 | |
277 for p in util.finddirs(virtual): | |
278 yield p | |
279 | |
280 yield '' | |
281 | |
282 for virtualrepo in _virtualdirs(): | |
274 real = repos.get(virtualrepo) | 283 real = repos.get(virtualrepo) |
275 if real: | 284 if real: |
276 req.env['REPO_NAME'] = virtualrepo | 285 req.env['REPO_NAME'] = virtualrepo |
277 try: | 286 try: |
278 # ensure caller gets private copy of ui | 287 # ensure caller gets private copy of ui |
281 except IOError as inst: | 290 except IOError as inst: |
282 msg = inst.strerror | 291 msg = inst.strerror |
283 raise ErrorResponse(HTTP_SERVER_ERROR, msg) | 292 raise ErrorResponse(HTTP_SERVER_ERROR, msg) |
284 except error.RepoError as inst: | 293 except error.RepoError as inst: |
285 raise ErrorResponse(HTTP_SERVER_ERROR, str(inst)) | 294 raise ErrorResponse(HTTP_SERVER_ERROR, str(inst)) |
286 | |
287 up = virtualrepo.rfind('/') | |
288 if up < 0: | |
289 break | |
290 virtualrepo = virtualrepo[:up] | |
291 | 295 |
292 # browse subdirectories | 296 # browse subdirectories |
293 subdir = virtual + '/' | 297 subdir = virtual + '/' |
294 if [r for r in repos if r.startswith(subdir)]: | 298 if [r for r in repos if r.startswith(subdir)]: |
295 req.respond(HTTP_OK, ctype) | 299 req.respond(HTTP_OK, ctype) |