##// END OF EJS Templates
Merge with crew-stable
Merge with crew-stable

File last commit:

r5890:a0e20a5e default
r5913:7c2921a6 merge default
Show More
webcommands.py
113 lines | 3.3 KiB | text/x-python | PythonLexer
Dirkjan Ochtman
split out hgweb commands into a separate file, move some code around
r5591 #
# Copyright 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net>
# Copyright 2005-2007 Matt Mackall <mpm@selenic.com>
#
# This software may be used and distributed according to the terms
# of the GNU General Public License, incorporated herein by reference.
Dirkjan Ochtman
hgweb: fast path for sending raw files
r5890 import os, mimetypes
from mercurial import revlog, util
Dirkjan Ochtman
split out hgweb commands into a separate file, move some code around
r5591 from common import staticfile
Dirkjan Ochtman
hgweb: explicitly pass around the templater
r5600 def log(web, req, tmpl):
Dirkjan Ochtman
split out hgweb commands into a separate file, move some code around
r5591 if req.form.has_key('file') and req.form['file'][0]:
Dirkjan Ochtman
hgweb: explicitly pass around the templater
r5600 filelog(web, req, tmpl)
Dirkjan Ochtman
split out hgweb commands into a separate file, move some code around
r5591 else:
Dirkjan Ochtman
hgweb: explicitly pass around the templater
r5600 changelog(web, req, tmpl)
Dirkjan Ochtman
split out hgweb commands into a separate file, move some code around
r5591
Dirkjan Ochtman
hgweb: fast path for sending raw files
r5890 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)
Dirkjan Ochtman
hgweb: explicitly pass around the templater
r5600 def file(web, req, tmpl):
Dirkjan Ochtman
split out hgweb commands into a separate file, move some code around
r5591 path = web.cleanpath(req.form.get('file', [''])[0])
if path:
try:
Dirkjan Ochtman
hgweb: explicitly pass around the templater
r5600 req.write(web.filerevision(tmpl, web.filectx(req)))
Dirkjan Ochtman
split out hgweb commands into a separate file, move some code around
r5591 return
except revlog.LookupError:
pass
Dirkjan Ochtman
hgweb: explicitly pass around the templater
r5600 req.write(web.manifest(tmpl, web.changectx(req), path))
Dirkjan Ochtman
split out hgweb commands into a separate file, move some code around
r5591
Dirkjan Ochtman
hgweb: explicitly pass around the templater
r5600 def changelog(web, req, tmpl, shortlog = False):
Dirkjan Ochtman
split out hgweb commands into a separate file, move some code around
r5591 if req.form.has_key('node'):
ctx = web.changectx(req)
else:
if req.form.has_key('rev'):
hi = req.form['rev'][0]
else:
hi = web.repo.changelog.count() - 1
try:
ctx = web.repo.changectx(hi)
except hg.RepoError:
Dirkjan Ochtman
hgweb: explicitly pass around the templater
r5600 req.write(web.search(tmpl, hi)) # XXX redirect to 404 page?
Dirkjan Ochtman
split out hgweb commands into a separate file, move some code around
r5591 return
Dirkjan Ochtman
hgweb: explicitly pass around the templater
r5600 req.write(web.changelog(tmpl, ctx, shortlog = shortlog))
Dirkjan Ochtman
split out hgweb commands into a separate file, move some code around
r5591
Dirkjan Ochtman
hgweb: explicitly pass around the templater
r5600 def shortlog(web, req, tmpl):
changelog(web, req, tmpl, shortlog = True)
Dirkjan Ochtman
split out hgweb commands into a separate file, move some code around
r5591
Dirkjan Ochtman
hgweb: explicitly pass around the templater
r5600 def changeset(web, req, tmpl):
req.write(web.changeset(tmpl, web.changectx(req)))
Dirkjan Ochtman
split out hgweb commands into a separate file, move some code around
r5591
rev = changeset
Dirkjan Ochtman
hgweb: explicitly pass around the templater
r5600 def manifest(web, req, tmpl):
req.write(web.manifest(tmpl, web.changectx(req),
Dirkjan Ochtman
split out hgweb commands into a separate file, move some code around
r5591 web.cleanpath(req.form['path'][0])))
Dirkjan Ochtman
hgweb: explicitly pass around the templater
r5600 def tags(web, req, tmpl):
req.write(web.tags(tmpl))
Dirkjan Ochtman
split out hgweb commands into a separate file, move some code around
r5591
Dirkjan Ochtman
hgweb: explicitly pass around the templater
r5600 def summary(web, req, tmpl):
req.write(web.summary(tmpl))
Dirkjan Ochtman
split out hgweb commands into a separate file, move some code around
r5591
Dirkjan Ochtman
hgweb: explicitly pass around the templater
r5600 def filediff(web, req, tmpl):
req.write(web.filediff(tmpl, web.filectx(req)))
Dirkjan Ochtman
split out hgweb commands into a separate file, move some code around
r5591
diff = filediff
Dirkjan Ochtman
hgweb: explicitly pass around the templater
r5600 def annotate(web, req, tmpl):
req.write(web.fileannotate(tmpl, web.filectx(req)))
Dirkjan Ochtman
split out hgweb commands into a separate file, move some code around
r5591
Dirkjan Ochtman
hgweb: explicitly pass around the templater
r5600 def filelog(web, req, tmpl):
req.write(web.filelog(tmpl, web.filectx(req)))
Dirkjan Ochtman
split out hgweb commands into a separate file, move some code around
r5591
Dirkjan Ochtman
hgweb: explicitly pass around the templater
r5600 def archive(web, req, tmpl):
Dirkjan Ochtman
split out hgweb commands into a separate file, move some code around
r5591 type_ = req.form['type'][0]
allowed = web.configlist("web", "allow_archive")
if (type_ in web.archives and (type_ in allowed or
web.configbool("web", "allow" + type_, False))):
Dirkjan Ochtman
hgweb: explicitly pass around the templater
r5600 web.archive(tmpl, req, req.form['node'][0], type_)
Dirkjan Ochtman
split out hgweb commands into a separate file, move some code around
r5591 return
Dirkjan Ochtman
hgweb: explicitly pass around the templater
r5600 req.respond(400, tmpl('error',
Dirkjan Ochtman
split out hgweb commands into a separate file, move some code around
r5591 error='Unsupported archive type: %s' % type_))
Dirkjan Ochtman
hgweb: explicitly pass around the templater
r5600 def static(web, req, tmpl):
Dirkjan Ochtman
split out hgweb commands into a separate file, move some code around
r5591 fname = req.form['file'][0]
# a repo owner may set web.static in .hg/hgrc to get any file
# readable by the user running the CGI script
static = web.config("web", "static",
os.path.join(web.templatepath, "static"),
untrusted=False)
req.write(staticfile(static, fname, req))