mercurial/hgweb/webcommands.py
changeset 5890 a0e20a5eba3c
parent 5600 9d900f7282e6
child 5915 d0576d065993
equal deleted inserted replaced
5889:209577095f20 5890:a0e20a5eba3c
     3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
     3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
     4 #
     4 #
     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):
    13     if req.form.has_key('file') and req.form['file'][0]:
    13     if req.form.has_key('file') and req.form['file'][0]:
    14         filelog(web, req, tmpl)
    14         filelog(web, req, tmpl)
    15     else:
    15     else:
    16         changelog(web, req, tmpl)
    16         changelog(web, req, tmpl)
       
    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)
    17 
    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:
    21         try:
    42         try: