Details
Details
- Reviewers
durin42 - Group Reviewers
hg-reviewers - Commits
- rHG93717f082af9: hgweb: use modern response type for index generation
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
| durin42 |
| hg-reviewers |
| Lint Skipped |
| Unit Tests Skipped |
| Path | Packages | |||
|---|---|---|---|---|
| M | mercurial/hgweb/hgwebdir_mod.py (26 lines) |
| import os | import os | ||||
| import time | import time | ||||
| from ..i18n import _ | from ..i18n import _ | ||||
| from .common import ( | from .common import ( | ||||
| ErrorResponse, | ErrorResponse, | ||||
| HTTP_NOT_FOUND, | HTTP_NOT_FOUND, | ||||
| HTTP_OK, | |||||
| HTTP_SERVER_ERROR, | HTTP_SERVER_ERROR, | ||||
| cspvalues, | cspvalues, | ||||
| get_contact, | get_contact, | ||||
| get_mtime, | get_mtime, | ||||
| ismember, | ismember, | ||||
| paritygen, | paritygen, | ||||
| staticfile, | staticfile, | ||||
| ) | ) | ||||
| staticfile(static, fname, res) | staticfile(static, fname, res) | ||||
| return res.sendresponse() | return res.sendresponse() | ||||
| # top-level index | # top-level index | ||||
| repos = dict(self.repos) | repos = dict(self.repos) | ||||
| if (not virtual or virtual == 'index') and virtual not in repos: | if (not virtual or virtual == 'index') and virtual not in repos: | ||||
| wsgireq.respond(HTTP_OK, ctype) | return self.makeindex(req, res, tmpl) | ||||
| return self.makeindex(req, tmpl) | |||||
| # nested indexes and hgwebs | # nested indexes and hgwebs | ||||
| if virtual.endswith('/index') and virtual not in repos: | if virtual.endswith('/index') and virtual not in repos: | ||||
| subdir = virtual[:-len('index')] | subdir = virtual[:-len('index')] | ||||
| if any(r.startswith(subdir) for r in repos): | if any(r.startswith(subdir) for r in repos): | ||||
| wsgireq.respond(HTTP_OK, ctype) | return self.makeindex(req, res, tmpl, subdir) | ||||
| return self.makeindex(req, tmpl, subdir) | |||||
| def _virtualdirs(): | def _virtualdirs(): | ||||
| # Check the full virtual path, each parent, and the root ('') | # Check the full virtual path, each parent, and the root ('') | ||||
| if virtual != '': | if virtual != '': | ||||
| yield virtual | yield virtual | ||||
| for p in util.finddirs(virtual): | for p in util.finddirs(virtual): | ||||
| yield p | yield p | ||||
| msg = encoding.strtolocal(inst.strerror) | msg = encoding.strtolocal(inst.strerror) | ||||
| raise ErrorResponse(HTTP_SERVER_ERROR, msg) | raise ErrorResponse(HTTP_SERVER_ERROR, msg) | ||||
| except error.RepoError as inst: | except error.RepoError as inst: | ||||
| raise ErrorResponse(HTTP_SERVER_ERROR, bytes(inst)) | raise ErrorResponse(HTTP_SERVER_ERROR, bytes(inst)) | ||||
| # browse subdirectories | # browse subdirectories | ||||
| subdir = virtual + '/' | subdir = virtual + '/' | ||||
| if [r for r in repos if r.startswith(subdir)]: | if [r for r in repos if r.startswith(subdir)]: | ||||
| wsgireq.respond(HTTP_OK, ctype) | return self.makeindex(req, res, tmpl, subdir) | ||||
| return self.makeindex(req, tmpl, subdir) | |||||
| # prefixes not found | # prefixes not found | ||||
| wsgireq.respond(HTTP_NOT_FOUND, ctype) | wsgireq.respond(HTTP_NOT_FOUND, ctype) | ||||
| return tmpl("notfound", repo=virtual) | return tmpl("notfound", repo=virtual) | ||||
| except ErrorResponse as err: | except ErrorResponse as err: | ||||
| wsgireq.respond(err, ctype) | wsgireq.respond(err, ctype) | ||||
| return tmpl('error', error=err.message or '') | return tmpl('error', error=err.message or '') | ||||
| finally: | finally: | ||||
| tmpl = None | tmpl = None | ||||
| def makeindex(self, req, tmpl, subdir=""): | def makeindex(self, req, res, tmpl, subdir=""): | ||||
| self.refresh() | self.refresh() | ||||
| sortable = ["name", "description", "contact", "lastchange"] | sortable = ["name", "description", "contact", "lastchange"] | ||||
| sortcolumn, descending = None, False | sortcolumn, descending = None, False | ||||
| if 'sort' in req.qsparams: | if 'sort' in req.qsparams: | ||||
| sortcolumn = req.qsparams['sort'] | sortcolumn = req.qsparams['sort'] | ||||
| descending = sortcolumn.startswith('-') | descending = sortcolumn.startswith('-') | ||||
| if descending: | if descending: | ||||
| sortcolumn = sortcolumn[1:] | sortcolumn = sortcolumn[1:] | ||||
| if sortcolumn not in sortable: | if sortcolumn not in sortable: | ||||
| sortcolumn = "" | sortcolumn = "" | ||||
| sort = [("sort_%s" % column, | sort = [("sort_%s" % column, | ||||
| "%s%s" % ((not descending and column == sortcolumn) | "%s%s" % ((not descending and column == sortcolumn) | ||||
| and "-" or "", column)) | and "-" or "", column)) | ||||
| for column in sortable] | for column in sortable] | ||||
| self.refresh() | self.refresh() | ||||
| entries = indexentries(self.ui, self.repos, req, | entries = indexentries(self.ui, self.repos, req, | ||||
| self.stripecount, sortcolumn=sortcolumn, | self.stripecount, sortcolumn=sortcolumn, | ||||
| descending=descending, subdir=subdir) | descending=descending, subdir=subdir) | ||||
| return tmpl("index", entries=entries, subdir=subdir, | res.setbodygen(tmpl( | ||||
| 'index', | |||||
| entries=entries, | |||||
| subdir=subdir, | |||||
| pathdef=hgweb_mod.makebreadcrumb('/' + subdir, self.prefix), | pathdef=hgweb_mod.makebreadcrumb('/' + subdir, self.prefix), | ||||
| sortcolumn=sortcolumn, descending=descending, | sortcolumn=sortcolumn, | ||||
| **dict(sort)) | descending=descending, | ||||
| **dict(sort))) | |||||
| return res.sendresponse() | |||||
| def templater(self, wsgireq, nonce): | def templater(self, wsgireq, nonce): | ||||
| def motd(**map): | def motd(**map): | ||||
| if self.motd is not None: | if self.motd is not None: | ||||
| yield self.motd | yield self.motd | ||||
| else: | else: | ||||
| yield config('web', 'motd') | yield config('web', 'motd') | ||||