##// END OF EJS Templates
Fix bad behaviour when specifying an invalid date (issue700)...
Fix bad behaviour when specifying an invalid date (issue700) commit (aborts _after_ typing in a commit message) backout (aborted after the initial revert) tag (edited .hgtags and couldn't commit) import (patch applied, then commit fails) qnew (aborts on bad dates, but writes any valid date into the # Date header) qrefresh (like qnew) sign (like tag) fetch (merge, merge, merge, merge, abort)

File last commit:

r5993:948a41e7 default
r6139:989467e8 default
Show More
webcommands.py
120 lines | 3.6 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
Patrick Mezard
webcommands: add missing hg import
r5960 from mercurial import revlog, util, hg
Dirkjan Ochtman
hgweb: explicit response status
r5993 from common import staticfile, ErrorResponse, HTTP_OK, HTTP_NOT_FOUND
Dirkjan Ochtman
split out hgweb commands into a separate file, move some code around
r5591
Dirkjan Ochtman
hgweb: explicitly check if requested command exists
r5963 # __all__ is populated with the allowed commands. Be sure to add to it if
# you're adding a new command, or the new command won't work.
__all__ = [
'log', 'rawfile', 'file', 'changelog', 'shortlog', 'changeset', 'rev',
'manifest', 'tags', 'summary', 'filediff', 'diff', 'annotate', 'filelog',
'archive', 'static',
]
Dirkjan Ochtman
hgweb: explicitly pass around the templater
r5600 def log(web, req, tmpl):
Christian Ebert
Prefer i in d over d.has_key(i)
r5915 if 'file' in req.form and req.form['file'][0]:
Dirkjan Ochtman
hgweb: centralize req.write() calls
r5964 return filelog(web, req, tmpl)
Dirkjan Ochtman
split out hgweb commands into a separate file, move some code around
r5591 else:
Dirkjan Ochtman
hgweb: centralize req.write() calls
r5964 return 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:
Dirkjan Ochtman
hgweb: explicit response status
r5993 content = web.manifest(tmpl, web.changectx(req), path)
req.respond(HTTP_OK, web.ctype)
return content
Dirkjan Ochtman
hgweb: fast path for sending raw files
r5890
try:
fctx = web.filectx(req)
except revlog.LookupError:
Dirkjan Ochtman
hgweb: explicit response status
r5993 content = web.manifest(tmpl, web.changectx(req), path)
req.respond(HTTP_OK, web.ctype)
return content
Dirkjan Ochtman
hgweb: fast path for sending raw files
r5890
path = fctx.path()
text = fctx.data()
mt = mimetypes.guess_type(path)[0]
Dirkjan Ochtman
hgweb: be sure to send a valid content-type for raw files
r5926 if mt is None or util.binary(text):
Dirkjan Ochtman
hgweb: fast path for sending raw files
r5890 mt = mt or 'application/octet-stream'
Dirkjan Ochtman
hgweb: explicit response status
r5993 req.respond(HTTP_OK, mt, path, len(text))
Dirkjan Ochtman
hgweb: centralize req.write() calls
r5964 return [text]
Dirkjan Ochtman
hgweb: fast path for sending raw files
r5890
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: centralize req.write() calls
r5964 return web.filerevision(tmpl, web.filectx(req))
Dirkjan Ochtman
split out hgweb commands into a separate file, move some code around
r5591 except revlog.LookupError:
pass
Dirkjan Ochtman
hgweb: centralize req.write() calls
r5964 return 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):
Christian Ebert
Prefer i in d over d.has_key(i)
r5915 if 'node' in req.form:
Dirkjan Ochtman
split out hgweb commands into a separate file, move some code around
r5591 ctx = web.changectx(req)
else:
Christian Ebert
Prefer i in d over d.has_key(i)
r5915 if 'rev' in req.form:
Dirkjan Ochtman
split out hgweb commands into a separate file, move some code around
r5591 hi = req.form['rev'][0]
else:
hi = web.repo.changelog.count() - 1
try:
ctx = web.repo.changectx(hi)
except hg.RepoError:
Dirkjan Ochtman
hgweb: centralize req.write() calls
r5964 return web.search(tmpl, hi) # XXX redirect to 404 page?
Dirkjan Ochtman
split out hgweb commands into a separate file, move some code around
r5591
Dirkjan Ochtman
hgweb: centralize req.write() calls
r5964 return 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):
Dirkjan Ochtman
hgweb: centralize req.write() calls
r5964 return 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):
Dirkjan Ochtman
hgweb: centralize req.write() calls
r5964 return 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):
Dirkjan Ochtman
hgweb: centralize req.write() calls
r5964 return web.manifest(tmpl, web.changectx(req),
web.cleanpath(req.form['path'][0]))
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 tags(web, req, tmpl):
Dirkjan Ochtman
hgweb: centralize req.write() calls
r5964 return 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):
Dirkjan Ochtman
hgweb: centralize req.write() calls
r5964 return 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):
Dirkjan Ochtman
hgweb: centralize req.write() calls
r5964 return 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):
Dirkjan Ochtman
hgweb: centralize req.write() calls
r5964 return 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):
Dirkjan Ochtman
hgweb: centralize req.write() calls
r5964 return 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
hgweb: centralize req.write() calls
r5964 return []
Dirkjan Ochtman
hgweb: explicit response status
r5993 raise ErrorResponse(HTTP_NOT_FOUND, 'Unsupported archive type: %s' % type_)
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 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)
Dirkjan Ochtman
hgweb: centralize req.write() calls
r5964 return [staticfile(static, fname, req)]