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