Mercurial > hg-stable
annotate mercurial/hgweb/webcommands.py @ 6392:2540521dc7c1
hgweb: separate out utility functions
author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
---|---|
date | Fri, 28 Mar 2008 19:37:28 +0100 |
parents | 2c370f08c486 |
children | 894875eae49b |
rev | line source |
---|---|
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
1 # |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
2 # Copyright 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net> |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
4 # |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
6 # of the GNU General Public License, incorporated herein by reference. |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
7 |
5890
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
8 import os, mimetypes |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6368
diff
changeset
|
9 import webutil |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6368
diff
changeset
|
10 from mercurial import revlog |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6368
diff
changeset
|
11 from mercurial.util import binary |
6217
fe8dbbe9520d
Avoid importing mercurial.node/mercurial.repo stuff from mercurial.hg
Joel Rosdahl <joel@rosdahl.net>
parents:
5993
diff
changeset
|
12 from mercurial.repo import RepoError |
5993
948a41e77902
hgweb: explicit response status
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5964
diff
changeset
|
13 from common import staticfile, ErrorResponse, HTTP_OK, HTTP_NOT_FOUND |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
14 |
5963
5be210afe1b8
hgweb: explicitly check if requested command exists
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5960
diff
changeset
|
15 # __all__ is populated with the allowed commands. Be sure to add to it if |
5be210afe1b8
hgweb: explicitly check if requested command exists
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5960
diff
changeset
|
16 # you're adding a new command, or the new command won't work. |
5be210afe1b8
hgweb: explicitly check if requested command exists
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5960
diff
changeset
|
17 |
5be210afe1b8
hgweb: explicitly check if requested command exists
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5960
diff
changeset
|
18 __all__ = [ |
5be210afe1b8
hgweb: explicitly check if requested command exists
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5960
diff
changeset
|
19 'log', 'rawfile', 'file', 'changelog', 'shortlog', 'changeset', 'rev', |
5be210afe1b8
hgweb: explicitly check if requested command exists
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5960
diff
changeset
|
20 'manifest', 'tags', 'summary', 'filediff', 'diff', 'annotate', 'filelog', |
5be210afe1b8
hgweb: explicitly check if requested command exists
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5960
diff
changeset
|
21 'archive', 'static', |
5be210afe1b8
hgweb: explicitly check if requested command exists
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5960
diff
changeset
|
22 ] |
5be210afe1b8
hgweb: explicitly check if requested command exists
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5960
diff
changeset
|
23 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
24 def log(web, req, tmpl): |
5915
d0576d065993
Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents:
5890
diff
changeset
|
25 if 'file' in req.form and req.form['file'][0]: |
5964
1cd1582ef25f
hgweb: centralize req.write() calls
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5963
diff
changeset
|
26 return filelog(web, req, tmpl) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
27 else: |
5964
1cd1582ef25f
hgweb: centralize req.write() calls
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5963
diff
changeset
|
28 return changelog(web, req, tmpl) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
29 |
5890
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
30 def rawfile(web, req, tmpl): |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6368
diff
changeset
|
31 path = webutil.cleanpath(web.repo, req.form.get('file', [''])[0]) |
5890
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
32 if not path: |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6368
diff
changeset
|
33 content = web.manifest(tmpl, webutil.changectx(web.repo, req), path) |
5993
948a41e77902
hgweb: explicit response status
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5964
diff
changeset
|
34 req.respond(HTTP_OK, web.ctype) |
948a41e77902
hgweb: explicit response status
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5964
diff
changeset
|
35 return content |
5890
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
36 |
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
37 try: |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6368
diff
changeset
|
38 fctx = webutil.filectx(web.repo, req) |
6368
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6217
diff
changeset
|
39 except revlog.LookupError, inst: |
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6217
diff
changeset
|
40 try: |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6368
diff
changeset
|
41 content = web.manifest(tmpl, webutil.changectx(web.repo, req), path) |
6368
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6217
diff
changeset
|
42 req.respond(HTTP_OK, web.ctype) |
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6217
diff
changeset
|
43 return content |
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6217
diff
changeset
|
44 except ErrorResponse: |
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6217
diff
changeset
|
45 raise inst |
5890
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
46 |
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
47 path = fctx.path() |
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
48 text = fctx.data() |
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
49 mt = mimetypes.guess_type(path)[0] |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6368
diff
changeset
|
50 if mt is None or binary(text): |
5890
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
51 mt = mt or 'application/octet-stream' |
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
52 |
5993
948a41e77902
hgweb: explicit response status
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5964
diff
changeset
|
53 req.respond(HTTP_OK, mt, path, len(text)) |
5964
1cd1582ef25f
hgweb: centralize req.write() calls
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5963
diff
changeset
|
54 return [text] |
5890
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
55 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
56 def file(web, req, tmpl): |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6368
diff
changeset
|
57 path = webutil.cleanpath(web.repo, req.form.get('file', [''])[0]) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
58 if path: |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
59 try: |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6368
diff
changeset
|
60 return web.filerevision(tmpl, webutil.filectx(web.repo, req)) |
6368
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6217
diff
changeset
|
61 except revlog.LookupError, inst: |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
62 pass |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
63 |
6368
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6217
diff
changeset
|
64 try: |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6368
diff
changeset
|
65 return web.manifest(tmpl, webutil.changectx(web.repo, req), path) |
6368
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6217
diff
changeset
|
66 except ErrorResponse: |
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6217
diff
changeset
|
67 raise inst |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
68 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
69 def changelog(web, req, tmpl, shortlog = False): |
5915
d0576d065993
Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents:
5890
diff
changeset
|
70 if 'node' in req.form: |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6368
diff
changeset
|
71 ctx = webutil.changectx(web.repo, req) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
72 else: |
5915
d0576d065993
Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents:
5890
diff
changeset
|
73 if 'rev' in req.form: |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
74 hi = req.form['rev'][0] |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
75 else: |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
76 hi = web.repo.changelog.count() - 1 |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
77 try: |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
78 ctx = web.repo.changectx(hi) |
6217
fe8dbbe9520d
Avoid importing mercurial.node/mercurial.repo stuff from mercurial.hg
Joel Rosdahl <joel@rosdahl.net>
parents:
5993
diff
changeset
|
79 except RepoError: |
5964
1cd1582ef25f
hgweb: centralize req.write() calls
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5963
diff
changeset
|
80 return web.search(tmpl, hi) # XXX redirect to 404 page? |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
81 |
5964
1cd1582ef25f
hgweb: centralize req.write() calls
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5963
diff
changeset
|
82 return web.changelog(tmpl, ctx, shortlog = shortlog) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
83 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
84 def shortlog(web, req, tmpl): |
5964
1cd1582ef25f
hgweb: centralize req.write() calls
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5963
diff
changeset
|
85 return changelog(web, req, tmpl, shortlog = True) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
86 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
87 def changeset(web, req, tmpl): |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6368
diff
changeset
|
88 return web.changeset(tmpl, webutil.changectx(web.repo, req)) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
89 |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
90 rev = changeset |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
91 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
92 def manifest(web, req, tmpl): |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6368
diff
changeset
|
93 return web.manifest(tmpl, webutil.changectx(web.repo, req), |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6368
diff
changeset
|
94 webutil.cleanpath(web.repo, req.form['path'][0])) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
95 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
96 def tags(web, req, tmpl): |
5964
1cd1582ef25f
hgweb: centralize req.write() calls
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5963
diff
changeset
|
97 return web.tags(tmpl) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
98 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
99 def summary(web, req, tmpl): |
5964
1cd1582ef25f
hgweb: centralize req.write() calls
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5963
diff
changeset
|
100 return web.summary(tmpl) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
101 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
102 def filediff(web, req, tmpl): |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6368
diff
changeset
|
103 return web.filediff(tmpl, webutil.filectx(web.repo, req)) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
104 |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
105 diff = filediff |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
106 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
107 def annotate(web, req, tmpl): |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6368
diff
changeset
|
108 return web.fileannotate(tmpl, webutil.filectx(web.repo, req)) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
109 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
110 def filelog(web, req, tmpl): |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6368
diff
changeset
|
111 return web.filelog(tmpl, webutil.filectx(web.repo, req)) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
112 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
113 def archive(web, req, tmpl): |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
114 type_ = req.form['type'][0] |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
115 allowed = web.configlist("web", "allow_archive") |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
116 if (type_ in web.archives and (type_ in allowed or |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
117 web.configbool("web", "allow" + type_, False))): |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
118 web.archive(tmpl, req, req.form['node'][0], type_) |
5964
1cd1582ef25f
hgweb: centralize req.write() calls
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5963
diff
changeset
|
119 return [] |
6368
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6217
diff
changeset
|
120 raise ErrorResponse(HTTP_NOT_FOUND, 'unsupported archive type: %s' % type_) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
121 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
122 def static(web, req, tmpl): |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
123 fname = req.form['file'][0] |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
124 # a repo owner may set web.static in .hg/hgrc to get any file |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
125 # readable by the user running the CGI script |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
126 static = web.config("web", "static", |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
127 os.path.join(web.templatepath, "static"), |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
128 untrusted=False) |
5964
1cd1582ef25f
hgweb: centralize req.write() calls
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5963
diff
changeset
|
129 return [staticfile(static, fname, req)] |