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