Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hgweb/webcommands.py @ 5600:9d900f7282e6
hgweb: explicitly pass around the templater
author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
---|---|
date | Mon, 03 Dec 2007 13:30:08 +0100 |
parents | d534ba1c4eb4 |
children | a0e20a5eba3c |
comparison
equal
deleted
inserted
replaced
5599:3de66c2a9734 | 5600:9d900f7282e6 |
---|---|
7 | 7 |
8 import os | 8 import os |
9 from mercurial import revlog | 9 from mercurial import revlog |
10 from common import staticfile | 10 from common import staticfile |
11 | 11 |
12 def log(web, req): | 12 def log(web, req, tmpl): |
13 if req.form.has_key('file') and req.form['file'][0]: | 13 if req.form.has_key('file') and req.form['file'][0]: |
14 filelog(web, req) | 14 filelog(web, req, tmpl) |
15 else: | 15 else: |
16 changelog(web, req) | 16 changelog(web, req, tmpl) |
17 | 17 |
18 def file(web, req): | 18 def file(web, req, tmpl): |
19 path = web.cleanpath(req.form.get('file', [''])[0]) | 19 path = web.cleanpath(req.form.get('file', [''])[0]) |
20 if path: | 20 if path: |
21 try: | 21 try: |
22 req.write(web.filerevision(web.filectx(req))) | 22 req.write(web.filerevision(tmpl, web.filectx(req))) |
23 return | 23 return |
24 except revlog.LookupError: | 24 except revlog.LookupError: |
25 pass | 25 pass |
26 | 26 |
27 req.write(web.manifest(web.changectx(req), path)) | 27 req.write(web.manifest(tmpl, web.changectx(req), path)) |
28 | 28 |
29 def changelog(web, req, shortlog = False): | 29 def changelog(web, req, tmpl, shortlog = False): |
30 if req.form.has_key('node'): | 30 if req.form.has_key('node'): |
31 ctx = web.changectx(req) | 31 ctx = web.changectx(req) |
32 else: | 32 else: |
33 if req.form.has_key('rev'): | 33 if req.form.has_key('rev'): |
34 hi = req.form['rev'][0] | 34 hi = req.form['rev'][0] |
35 else: | 35 else: |
36 hi = web.repo.changelog.count() - 1 | 36 hi = web.repo.changelog.count() - 1 |
37 try: | 37 try: |
38 ctx = web.repo.changectx(hi) | 38 ctx = web.repo.changectx(hi) |
39 except hg.RepoError: | 39 except hg.RepoError: |
40 req.write(web.search(hi)) # XXX redirect to 404 page? | 40 req.write(web.search(tmpl, hi)) # XXX redirect to 404 page? |
41 return | 41 return |
42 | 42 |
43 req.write(web.changelog(ctx, shortlog = shortlog)) | 43 req.write(web.changelog(tmpl, ctx, shortlog = shortlog)) |
44 | 44 |
45 def shortlog(web, req): | 45 def shortlog(web, req, tmpl): |
46 changelog(web, req, shortlog = True) | 46 changelog(web, req, tmpl, shortlog = True) |
47 | 47 |
48 def changeset(web, req): | 48 def changeset(web, req, tmpl): |
49 req.write(web.changeset(web.changectx(req))) | 49 req.write(web.changeset(tmpl, web.changectx(req))) |
50 | 50 |
51 rev = changeset | 51 rev = changeset |
52 | 52 |
53 def manifest(web, req): | 53 def manifest(web, req, tmpl): |
54 req.write(web.manifest(web.changectx(req), | 54 req.write(web.manifest(tmpl, web.changectx(req), |
55 web.cleanpath(req.form['path'][0]))) | 55 web.cleanpath(req.form['path'][0]))) |
56 | 56 |
57 def tags(web, req): | 57 def tags(web, req, tmpl): |
58 req.write(web.tags()) | 58 req.write(web.tags(tmpl)) |
59 | 59 |
60 def summary(web, req): | 60 def summary(web, req, tmpl): |
61 req.write(web.summary()) | 61 req.write(web.summary(tmpl)) |
62 | 62 |
63 def filediff(web, req): | 63 def filediff(web, req, tmpl): |
64 req.write(web.filediff(web.filectx(req))) | 64 req.write(web.filediff(tmpl, web.filectx(req))) |
65 | 65 |
66 diff = filediff | 66 diff = filediff |
67 | 67 |
68 def annotate(web, req): | 68 def annotate(web, req, tmpl): |
69 req.write(web.fileannotate(web.filectx(req))) | 69 req.write(web.fileannotate(tmpl, web.filectx(req))) |
70 | 70 |
71 def filelog(web, req): | 71 def filelog(web, req, tmpl): |
72 req.write(web.filelog(web.filectx(req))) | 72 req.write(web.filelog(tmpl, web.filectx(req))) |
73 | 73 |
74 def archive(web, req): | 74 def archive(web, req, tmpl): |
75 type_ = req.form['type'][0] | 75 type_ = req.form['type'][0] |
76 allowed = web.configlist("web", "allow_archive") | 76 allowed = web.configlist("web", "allow_archive") |
77 if (type_ in web.archives and (type_ in allowed or | 77 if (type_ in web.archives and (type_ in allowed or |
78 web.configbool("web", "allow" + type_, False))): | 78 web.configbool("web", "allow" + type_, False))): |
79 web.archive(req, req.form['node'][0], type_) | 79 web.archive(tmpl, req, req.form['node'][0], type_) |
80 return | 80 return |
81 | 81 |
82 req.respond(400, web.t('error', | 82 req.respond(400, tmpl('error', |
83 error='Unsupported archive type: %s' % type_)) | 83 error='Unsupported archive type: %s' % type_)) |
84 | 84 |
85 def static(web, req): | 85 def static(web, req, tmpl): |
86 fname = req.form['file'][0] | 86 fname = req.form['file'][0] |
87 # a repo owner may set web.static in .hg/hgrc to get any file | 87 # a repo owner may set web.static in .hg/hgrc to get any file |
88 # readable by the user running the CGI script | 88 # readable by the user running the CGI script |
89 static = web.config("web", "static", | 89 static = web.config("web", "static", |
90 os.path.join(web.templatepath, "static"), | 90 os.path.join(web.templatepath, "static"), |