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