Show More
@@ -1,127 +1,126 b'' | |||||
1 | # |
|
1 | # | |
2 | # Copyright 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net> |
|
2 | # Copyright 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net> | |
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, mimetypes |
|
8 | import os, mimetypes | |
9 | from mercurial import revlog, util |
|
9 | from mercurial import revlog, util | |
10 | from mercurial.repo import RepoError |
|
10 | from mercurial.repo import RepoError | |
11 | from common import staticfile, ErrorResponse, HTTP_OK, HTTP_NOT_FOUND |
|
11 | from common import staticfile, ErrorResponse, HTTP_OK, HTTP_NOT_FOUND | |
12 |
|
12 | |||
13 | # __all__ is populated with the allowed commands. Be sure to add to it if |
|
13 | # __all__ is populated with the allowed commands. Be sure to add to it if | |
14 | # you're adding a new command, or the new command won't work. |
|
14 | # you're adding a new command, or the new command won't work. | |
15 |
|
15 | |||
16 | __all__ = [ |
|
16 | __all__ = [ | |
17 | 'log', 'rawfile', 'file', 'changelog', 'shortlog', 'changeset', 'rev', |
|
17 | 'log', 'rawfile', 'file', 'changelog', 'shortlog', 'changeset', 'rev', | |
18 | 'manifest', 'tags', 'summary', 'filediff', 'diff', 'annotate', 'filelog', |
|
18 | 'manifest', 'tags', 'summary', 'filediff', 'diff', 'annotate', 'filelog', | |
19 | 'archive', 'static', |
|
19 | 'archive', 'static', | |
20 | ] |
|
20 | ] | |
21 |
|
21 | |||
22 | def log(web, req, tmpl): |
|
22 | def log(web, req, tmpl): | |
23 | if 'file' in req.form and req.form['file'][0]: |
|
23 | if 'file' in req.form and req.form['file'][0]: | |
24 | return filelog(web, req, tmpl) |
|
24 | return filelog(web, req, tmpl) | |
25 | else: |
|
25 | else: | |
26 | return changelog(web, req, tmpl) |
|
26 | return changelog(web, req, tmpl) | |
27 |
|
27 | |||
28 | def rawfile(web, req, tmpl): |
|
28 | def rawfile(web, req, tmpl): | |
29 | path = web.cleanpath(req.form.get('file', [''])[0]) |
|
29 | path = web.cleanpath(req.form.get('file', [''])[0]) | |
30 | if not path: |
|
30 | if not path: | |
31 | content = web.manifest(tmpl, web.changectx(req), path) |
|
31 | content = web.manifest(tmpl, web.changectx(req), path) | |
32 | req.respond(HTTP_OK, web.ctype) |
|
32 | req.respond(HTTP_OK, web.ctype) | |
33 | return content |
|
33 | return content | |
34 |
|
34 | |||
35 | try: |
|
35 | try: | |
36 | fctx = web.filectx(req) |
|
36 | fctx = web.filectx(req) | |
37 | except revlog.LookupError, inst: |
|
37 | except revlog.LookupError, inst: | |
38 | try: |
|
38 | try: | |
39 | content = web.manifest(tmpl, web.changectx(req), path) |
|
39 | content = web.manifest(tmpl, web.changectx(req), path) | |
40 | req.respond(HTTP_OK, web.ctype) |
|
40 | req.respond(HTTP_OK, web.ctype) | |
41 | return content |
|
41 | return content | |
42 | except ErrorResponse: |
|
42 | except ErrorResponse: | |
43 | raise inst |
|
43 | raise inst | |
44 |
|
44 | |||
45 | path = fctx.path() |
|
45 | path = fctx.path() | |
46 | text = fctx.data() |
|
46 | text = fctx.data() | |
47 | mt = mimetypes.guess_type(path)[0] |
|
47 | mt = mimetypes.guess_type(path)[0] | |
48 | if mt is None or util.binary(text): |
|
48 | if mt is None or util.binary(text): | |
49 | mt = mt or 'application/octet-stream' |
|
49 | mt = mt or 'application/octet-stream' | |
50 |
|
50 | |||
51 | req.respond(HTTP_OK, mt, path, len(text)) |
|
51 | req.respond(HTTP_OK, mt, path, len(text)) | |
52 | return [text] |
|
52 | return [text] | |
53 |
|
53 | |||
54 | def file(web, req, tmpl): |
|
54 | def file(web, req, tmpl): | |
55 | path = web.cleanpath(req.form.get('file', [''])[0]) |
|
55 | path = web.cleanpath(req.form.get('file', [''])[0]) | |
56 | if path: |
|
56 | if not path: | |
|
57 | return web.manifest(tmpl, web.changectx(req), path) | |||
57 |
|
|
58 | try: | |
58 |
|
|
59 | return web.filerevision(tmpl, web.filectx(req)) | |
59 |
|
|
60 | except revlog.LookupError, inst: | |
60 | pass |
|
|||
61 |
|
||||
62 | try: |
|
61 | try: | |
63 | return web.manifest(tmpl, web.changectx(req), path) |
|
62 | return web.manifest(tmpl, web.changectx(req), path) | |
64 | except ErrorResponse: |
|
63 | except ErrorResponse: | |
65 | raise inst |
|
64 | raise inst | |
66 |
|
65 | |||
67 | def changelog(web, req, tmpl, shortlog = False): |
|
66 | def changelog(web, req, tmpl, shortlog = False): | |
68 | if 'node' in req.form: |
|
67 | if 'node' in req.form: | |
69 | ctx = web.changectx(req) |
|
68 | ctx = web.changectx(req) | |
70 | else: |
|
69 | else: | |
71 | if 'rev' in req.form: |
|
70 | if 'rev' in req.form: | |
72 | hi = req.form['rev'][0] |
|
71 | hi = req.form['rev'][0] | |
73 | else: |
|
72 | else: | |
74 | hi = web.repo.changelog.count() - 1 |
|
73 | hi = web.repo.changelog.count() - 1 | |
75 | try: |
|
74 | try: | |
76 | ctx = web.repo.changectx(hi) |
|
75 | ctx = web.repo.changectx(hi) | |
77 | except RepoError: |
|
76 | except RepoError: | |
78 | return web.search(tmpl, hi) # XXX redirect to 404 page? |
|
77 | return web.search(tmpl, hi) # XXX redirect to 404 page? | |
79 |
|
78 | |||
80 | return web.changelog(tmpl, ctx, shortlog = shortlog) |
|
79 | return web.changelog(tmpl, ctx, shortlog = shortlog) | |
81 |
|
80 | |||
82 | def shortlog(web, req, tmpl): |
|
81 | def shortlog(web, req, tmpl): | |
83 | return changelog(web, req, tmpl, shortlog = True) |
|
82 | return changelog(web, req, tmpl, shortlog = True) | |
84 |
|
83 | |||
85 | def changeset(web, req, tmpl): |
|
84 | def changeset(web, req, tmpl): | |
86 | return web.changeset(tmpl, web.changectx(req)) |
|
85 | return web.changeset(tmpl, web.changectx(req)) | |
87 |
|
86 | |||
88 | rev = changeset |
|
87 | rev = changeset | |
89 |
|
88 | |||
90 | def manifest(web, req, tmpl): |
|
89 | def manifest(web, req, tmpl): | |
91 | return web.manifest(tmpl, web.changectx(req), |
|
90 | return web.manifest(tmpl, web.changectx(req), | |
92 | web.cleanpath(req.form['path'][0])) |
|
91 | web.cleanpath(req.form['path'][0])) | |
93 |
|
92 | |||
94 | def tags(web, req, tmpl): |
|
93 | def tags(web, req, tmpl): | |
95 | return web.tags(tmpl) |
|
94 | return web.tags(tmpl) | |
96 |
|
95 | |||
97 | def summary(web, req, tmpl): |
|
96 | def summary(web, req, tmpl): | |
98 | return web.summary(tmpl) |
|
97 | return web.summary(tmpl) | |
99 |
|
98 | |||
100 | def filediff(web, req, tmpl): |
|
99 | def filediff(web, req, tmpl): | |
101 | return web.filediff(tmpl, web.filectx(req)) |
|
100 | return web.filediff(tmpl, web.filectx(req)) | |
102 |
|
101 | |||
103 | diff = filediff |
|
102 | diff = filediff | |
104 |
|
103 | |||
105 | def annotate(web, req, tmpl): |
|
104 | def annotate(web, req, tmpl): | |
106 | return web.fileannotate(tmpl, web.filectx(req)) |
|
105 | return web.fileannotate(tmpl, web.filectx(req)) | |
107 |
|
106 | |||
108 | def filelog(web, req, tmpl): |
|
107 | def filelog(web, req, tmpl): | |
109 | return web.filelog(tmpl, web.filectx(req)) |
|
108 | return web.filelog(tmpl, web.filectx(req)) | |
110 |
|
109 | |||
111 | def archive(web, req, tmpl): |
|
110 | def archive(web, req, tmpl): | |
112 | type_ = req.form.get('type', [None])[0] |
|
111 | type_ = req.form.get('type', [None])[0] | |
113 | allowed = web.configlist("web", "allow_archive") |
|
112 | allowed = web.configlist("web", "allow_archive") | |
114 | if (type_ in web.archives and (type_ in allowed or |
|
113 | if (type_ in web.archives and (type_ in allowed or | |
115 | web.configbool("web", "allow" + type_, False))): |
|
114 | web.configbool("web", "allow" + type_, False))): | |
116 | web.archive(tmpl, req, req.form['node'][0], type_) |
|
115 | web.archive(tmpl, req, req.form['node'][0], type_) | |
117 | return [] |
|
116 | return [] | |
118 | raise ErrorResponse(HTTP_NOT_FOUND, 'unsupported archive type: %s' % type_) |
|
117 | raise ErrorResponse(HTTP_NOT_FOUND, 'unsupported archive type: %s' % type_) | |
119 |
|
118 | |||
120 | def static(web, req, tmpl): |
|
119 | def static(web, req, tmpl): | |
121 | fname = req.form['file'][0] |
|
120 | fname = req.form['file'][0] | |
122 | # a repo owner may set web.static in .hg/hgrc to get any file |
|
121 | # a repo owner may set web.static in .hg/hgrc to get any file | |
123 | # readable by the user running the CGI script |
|
122 | # readable by the user running the CGI script | |
124 | static = web.config("web", "static", |
|
123 | static = web.config("web", "static", | |
125 | os.path.join(web.templatepath, "static"), |
|
124 | os.path.join(web.templatepath, "static"), | |
126 | untrusted=False) |
|
125 | untrusted=False) | |
127 | return [staticfile(static, fname, req)] |
|
126 | return [staticfile(static, fname, req)] |
General Comments 0
You need to be logged in to leave comments.
Login now