##// END OF EJS Templates
hgweb: fast path for sending raw files
Dirkjan Ochtman -
r5890:a0e20a5e default
parent child Browse files
Show More
@@ -206,12 +206,17 b' class hgweb(object):'
206 method = getattr(protocol, cmd)
206 method = getattr(protocol, cmd)
207 method(self, req)
207 method(self, req)
208 else:
208 else:
209
209 tmpl = self.templater(req)
210 tmpl = self.templater(req)
210 if cmd == '':
211 if cmd == '':
211 req.form['cmd'] = [tmpl.cache['default']]
212 req.form['cmd'] = [tmpl.cache['default']]
212 cmd = req.form['cmd'][0]
213 cmd = req.form['cmd'][0]
213 method = getattr(webcommands, cmd)
214
214 method(self, req, tmpl)
215 if cmd == 'file' and 'raw' in req.form['style']:
216 webcommands.rawfile(self, req, tmpl)
217 else:
218 getattr(webcommands, cmd)(self, req, tmpl)
219
215 del tmpl
220 del tmpl
216
221
217 except revlog.LookupError, err:
222 except revlog.LookupError, err:
@@ -254,12 +259,6 b' class hgweb(object):'
254 req.header(msg.items())
259 req.header(msg.items())
255 yield header_file.read()
260 yield header_file.read()
256
261
257 def rawfileheader(**map):
258 req.header([('Content-type', map['mimetype']),
259 ('Content-disposition', 'filename=%s' % map['file']),
260 ('Content-length', str(len(map['raw'])))])
261 yield ''
262
263 def footer(**map):
262 def footer(**map):
264 yield tmpl("footer", **map)
263 yield tmpl("footer", **map)
265
264
@@ -300,7 +299,6 b' class hgweb(object):'
300 "header": header,
299 "header": header,
301 "footer": footer,
300 "footer": footer,
302 "motd": motd,
301 "motd": motd,
303 "rawfileheader": rawfileheader,
304 "sessionvars": sessionvars
302 "sessionvars": sessionvars
305 })
303 })
306 return tmpl
304 return tmpl
@@ -5,8 +5,8 b''
5 # This software may be used and distributed according to the terms
5 # This software may be used and distributed according to the terms
6 # of the GNU General Public License, incorporated herein by reference.
6 # of the GNU General Public License, incorporated herein by reference.
7
7
8 import os
8 import os, mimetypes
9 from mercurial import revlog
9 from mercurial import revlog, util
10 from common import staticfile
10 from common import staticfile
11
11
12 def log(web, req, tmpl):
12 def log(web, req, tmpl):
@@ -15,6 +15,27 b' def log(web, req, tmpl):'
15 else:
15 else:
16 changelog(web, req, tmpl)
16 changelog(web, req, tmpl)
17
17
18 def rawfile(web, req, tmpl):
19 path = web.cleanpath(req.form.get('file', [''])[0])
20 if not path:
21 req.write(web.manifest(tmpl, web.changectx(req), path))
22 return
23
24 try:
25 fctx = web.filectx(req)
26 except revlog.LookupError:
27 req.write(web.manifest(tmpl, web.changectx(req), path))
28 return
29
30 path = fctx.path()
31 text = fctx.data()
32 mt = mimetypes.guess_type(path)[0]
33 if util.binary(text):
34 mt = mt or 'application/octet-stream'
35
36 req.httphdr(mt, path, len(text))
37 req.write(text)
38
18 def file(web, req, tmpl):
39 def file(web, req, tmpl):
19 path = web.cleanpath(req.form.get('file', [''])[0])
40 path = web.cleanpath(req.form.get('file', [''])[0])
20 if path:
41 if path:
@@ -8,7 +8,6 b" diffline = '#line#'"
8 changesetparent = '# Parent #node#'
8 changesetparent = '# Parent #node#'
9 changesetchild = '# Child #node#'
9 changesetchild = '# Child #node#'
10 filenodelink = ''
10 filenodelink = ''
11 filerevision = '#rawfileheader##raw#'
12 fileline = '#line#'
11 fileline = '#line#'
13 diffblock = '#lines#'
12 diffblock = '#lines#'
14 filediff = filediff.tmpl
13 filediff = filediff.tmpl
General Comments 0
You need to be logged in to leave comments. Login now