Mercurial > hg-stable
changeset 5890:a0e20a5eba3c
hgweb: fast path for sending raw files
author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
---|---|
date | Fri, 18 Jan 2008 19:53:38 +0100 |
parents | 209577095f20 |
children | e7ec2217f2d8 |
files | mercurial/hgweb/hgweb_mod.py mercurial/hgweb/webcommands.py templates/raw/map |
diffstat | 3 files changed, 30 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/hgweb/hgweb_mod.py Fri Jan 18 19:53:38 2008 +0100 +++ b/mercurial/hgweb/hgweb_mod.py Fri Jan 18 19:53:38 2008 +0100 @@ -206,12 +206,17 @@ method = getattr(protocol, cmd) method(self, req) else: + tmpl = self.templater(req) if cmd == '': req.form['cmd'] = [tmpl.cache['default']] cmd = req.form['cmd'][0] - method = getattr(webcommands, cmd) - method(self, req, tmpl) + + if cmd == 'file' and 'raw' in req.form['style']: + webcommands.rawfile(self, req, tmpl) + else: + getattr(webcommands, cmd)(self, req, tmpl) + del tmpl except revlog.LookupError, err: @@ -254,12 +259,6 @@ req.header(msg.items()) yield header_file.read() - def rawfileheader(**map): - req.header([('Content-type', map['mimetype']), - ('Content-disposition', 'filename=%s' % map['file']), - ('Content-length', str(len(map['raw'])))]) - yield '' - def footer(**map): yield tmpl("footer", **map) @@ -300,7 +299,6 @@ "header": header, "footer": footer, "motd": motd, - "rawfileheader": rawfileheader, "sessionvars": sessionvars }) return tmpl
--- a/mercurial/hgweb/webcommands.py Fri Jan 18 19:53:38 2008 +0100 +++ b/mercurial/hgweb/webcommands.py Fri Jan 18 19:53:38 2008 +0100 @@ -5,8 +5,8 @@ # This software may be used and distributed according to the terms # of the GNU General Public License, incorporated herein by reference. -import os -from mercurial import revlog +import os, mimetypes +from mercurial import revlog, util from common import staticfile def log(web, req, tmpl): @@ -15,6 +15,27 @@ else: changelog(web, req, tmpl) +def rawfile(web, req, tmpl): + path = web.cleanpath(req.form.get('file', [''])[0]) + if not path: + req.write(web.manifest(tmpl, web.changectx(req), path)) + return + + try: + fctx = web.filectx(req) + except revlog.LookupError: + req.write(web.manifest(tmpl, web.changectx(req), path)) + return + + path = fctx.path() + text = fctx.data() + mt = mimetypes.guess_type(path)[0] + if util.binary(text): + mt = mt or 'application/octet-stream' + + req.httphdr(mt, path, len(text)) + req.write(text) + def file(web, req, tmpl): path = web.cleanpath(req.form.get('file', [''])[0]) if path:
--- a/templates/raw/map Fri Jan 18 19:53:38 2008 +0100 +++ b/templates/raw/map Fri Jan 18 19:53:38 2008 +0100 @@ -8,7 +8,6 @@ changesetparent = '# Parent #node#' changesetchild = '# Child #node#' filenodelink = '' -filerevision = '#rawfileheader##raw#' fileline = '#line#' diffblock = '#lines#' filediff = filediff.tmpl