Mercurial > hg
annotate mercurial/hgweb/hgweb_mod.py @ 6777:44c5157474e7
hgweb: protocol requests are processed immediately
This makes separation of interface/webcommands and protocol easier and will
make http repos slightly faster because there's less overhead.
author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
---|---|
date | Sat, 28 Jun 2008 15:28:43 +0200 |
parents | 39319a457dda |
children | d3147b4e3e8a |
rev | line source |
---|---|
2391
d351a3be3371
Fixing up comment headers for split up code.
Eric Hopper <hopper@omnifarious.org>
parents:
2361
diff
changeset
|
1 # hgweb/hgweb_mod.py - Web interface for a repository. |
131 | 2 # |
238
3b92f8fe47ae
hgweb.py: kill #! line, clean up copyright notice
mpm@selenic.com
parents:
222
diff
changeset
|
3 # Copyright 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net> |
4635
63b9d2deed48
Updated copyright notices and add "and others" to "hg version"
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4539
diff
changeset
|
4 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
131 | 5 # |
6 # This software may be used and distributed according to the terms | |
7 # of the GNU General Public License, incorporated herein by reference. | |
8 | |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
9 import os, mimetypes |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
10 from mercurial.node import hex, nullid |
6217
fe8dbbe9520d
Avoid importing mercurial.node/mercurial.repo stuff from mercurial.hg
Joel Rosdahl <joel@rosdahl.net>
parents:
6211
diff
changeset
|
11 from mercurial.repo import RepoError |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
12 from mercurial import mdiff, ui, hg, util, patch, hook |
6152
c050548307a4
hgweb: use bundletypes from mercurial.changegroup
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6149
diff
changeset
|
13 from mercurial import revlog, templater, templatefilters, changegroup |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
14 from common import get_mtime, style_map, paritygen, countgen, ErrorResponse |
5993
948a41e77902
hgweb: explicit response status
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5976
diff
changeset
|
15 from common import HTTP_OK, HTTP_BAD_REQUEST, HTTP_NOT_FOUND, HTTP_SERVER_ERROR |
5566
d74fc8dec2b4
Less indirection in the WSGI web interface. This simplifies some code, and makes it more compliant with WSGI.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5565
diff
changeset
|
16 from request import wsgirequest |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
17 import webcommands, protocol, webutil |
138 | 18 |
1559
59b3639df0a9
Convert all classes to new-style classes by deriving them from object.
Eric Hopper <hopper@omnifarious.org>
parents:
1554
diff
changeset
|
19 class hgweb(object): |
6141
90e5c82a3859
Backed out changeset b913d3aacddc (see issue971/msg5317)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5995
diff
changeset
|
20 def __init__(self, repo, name=None): |
4874
d9e385a7a806
Use isinstance instead of type == type
Christian Ebert <blacktrash@gmx.net>
parents:
4872
diff
changeset
|
21 if isinstance(repo, str): |
6141
90e5c82a3859
Backed out changeset b913d3aacddc (see issue971/msg5317)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5995
diff
changeset
|
22 parentui = ui.ui(report_untrusted=False, interactive=False) |
5289
ed6df6b1c29a
Prevent WSGI apps from touching sys.stdin by setting ui.interactive to False.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5064
diff
changeset
|
23 self.repo = hg.repository(parentui, repo) |
987 | 24 else: |
25 self.repo = repo | |
133
fb84d3e71042
added template support for some hgweb output, also, template files for
jake@edge2.net
parents:
132
diff
changeset
|
26 |
5833
323b9c55b328
hook: redirect stdout to stderr for ssh and http servers
Matt Mackall <mpm@selenic.com>
parents:
5779
diff
changeset
|
27 hook.redirect(True) |
258 | 28 self.mtime = -1 |
1172
3f30a5e7e15b
Use path relative to document root as reponame if published via a web server.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1170
diff
changeset
|
29 self.reponame = name |
1078 | 30 self.archives = 'zip', 'gz', 'bz2' |
2666
ebf033bc8eb2
hgweb: Configurable zebra stripes
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
2622
diff
changeset
|
31 self.stripecount = 1 |
6152
c050548307a4
hgweb: use bundletypes from mercurial.changegroup
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6149
diff
changeset
|
32 self._capabilities = None |
3555
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
33 # a repo owner may set web.templates in .hg/hgrc to get any file |
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
34 # readable by the user running the CGI script |
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
35 self.templatepath = self.config("web", "templates", |
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
36 templater.templatepath(), |
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
37 untrusted=False) |
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
38 |
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
39 # The CGI scripts are often run by a user different from the repo owner. |
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
40 # Trust the settings from the .hg/hgrc files by default. |
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
41 def config(self, section, name, default=None, untrusted=True): |
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
42 return self.repo.ui.config(section, name, default, |
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
43 untrusted=untrusted) |
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
44 |
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
45 def configbool(self, section, name, default=False, untrusted=True): |
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
46 return self.repo.ui.configbool(section, name, default, |
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
47 untrusted=untrusted) |
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
48 |
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
49 def configlist(self, section, name, default=None, untrusted=True): |
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
50 return self.repo.ui.configlist(section, name, default, |
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
51 untrusted=untrusted) |
131 | 52 |
258 | 53 def refresh(self): |
1418
68f81ba07b2a
Make hgweb work when the repository is empty (no 00changelog.i)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1416
diff
changeset
|
54 mtime = get_mtime(self.repo.root) |
68f81ba07b2a
Make hgweb work when the repository is empty (no 00changelog.i)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1416
diff
changeset
|
55 if mtime != self.mtime: |
68f81ba07b2a
Make hgweb work when the repository is empty (no 00changelog.i)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1416
diff
changeset
|
56 self.mtime = mtime |
1213 | 57 self.repo = hg.repository(self.repo.ui, self.repo.root) |
3555
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
58 self.maxchanges = int(self.config("web", "maxchanges", 10)) |
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
59 self.stripecount = int(self.config("web", "stripes", 1)) |
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
60 self.maxshortchanges = int(self.config("web", "maxshortchanges", 60)) |
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
61 self.maxfiles = int(self.config("web", "maxfiles", 10)) |
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
62 self.allowpull = self.configbool("web", "allowpull", True) |
4690
ecea4de3104e
Enable to select encoding in hgrc web section
OHASHI Hideya <ohachige at gmail.com>
parents:
4669
diff
changeset
|
63 self.encoding = self.config("web", "encoding", util._encoding) |
6152
c050548307a4
hgweb: use bundletypes from mercurial.changegroup
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6149
diff
changeset
|
64 self._capabilities = None |
c050548307a4
hgweb: use bundletypes from mercurial.changegroup
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6149
diff
changeset
|
65 |
c050548307a4
hgweb: use bundletypes from mercurial.changegroup
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6149
diff
changeset
|
66 def capabilities(self): |
c050548307a4
hgweb: use bundletypes from mercurial.changegroup
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6149
diff
changeset
|
67 if self._capabilities is not None: |
c050548307a4
hgweb: use bundletypes from mercurial.changegroup
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6149
diff
changeset
|
68 return self._capabilities |
c050548307a4
hgweb: use bundletypes from mercurial.changegroup
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6149
diff
changeset
|
69 caps = ['lookup', 'changegroupsubset'] |
c050548307a4
hgweb: use bundletypes from mercurial.changegroup
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6149
diff
changeset
|
70 if self.configbool('server', 'uncompressed'): |
c050548307a4
hgweb: use bundletypes from mercurial.changegroup
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6149
diff
changeset
|
71 caps.append('stream=%d' % self.repo.changelog.version) |
c050548307a4
hgweb: use bundletypes from mercurial.changegroup
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6149
diff
changeset
|
72 if changegroup.bundlepriority: |
c050548307a4
hgweb: use bundletypes from mercurial.changegroup
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6149
diff
changeset
|
73 caps.append('unbundle=%s' % ','.join(changegroup.bundlepriority)) |
c050548307a4
hgweb: use bundletypes from mercurial.changegroup
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6149
diff
changeset
|
74 self._capabilities = caps |
c050548307a4
hgweb: use bundletypes from mercurial.changegroup
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6149
diff
changeset
|
75 return caps |
258 | 76 |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
77 def run(self): |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
78 if not os.environ.get('GATEWAY_INTERFACE', '').startswith("CGI/1."): |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
79 raise RuntimeError("This function is only intended to be called while running as a CGI script.") |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
80 import mercurial.hgweb.wsgicgi as wsgicgi |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
81 wsgicgi.launch(self) |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
82 |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
83 def __call__(self, env, respond): |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
84 req = wsgirequest(env, respond) |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
85 self.run_wsgi(req) |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
86 return req |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
87 |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
88 def run_wsgi(self, req): |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
89 |
5596
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
90 self.refresh() |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
91 |
6777
44c5157474e7
hgweb: protocol requests are processed immediately
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6776
diff
changeset
|
92 # process this if it's a protocol request |
44c5157474e7
hgweb: protocol requests are processed immediately
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6776
diff
changeset
|
93 # protocol bits don't need to create any URLs |
44c5157474e7
hgweb: protocol requests are processed immediately
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6776
diff
changeset
|
94 # and the clients always use the old URL structure |
44c5157474e7
hgweb: protocol requests are processed immediately
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6776
diff
changeset
|
95 |
44c5157474e7
hgweb: protocol requests are processed immediately
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6776
diff
changeset
|
96 cmd = req.form.get('cmd', [''])[0] |
44c5157474e7
hgweb: protocol requests are processed immediately
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6776
diff
changeset
|
97 if cmd and cmd in protocol.__all__: |
44c5157474e7
hgweb: protocol requests are processed immediately
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6776
diff
changeset
|
98 method = getattr(protocol, cmd) |
44c5157474e7
hgweb: protocol requests are processed immediately
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6776
diff
changeset
|
99 method(self, req) |
44c5157474e7
hgweb: protocol requests are processed immediately
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6776
diff
changeset
|
100 return |
44c5157474e7
hgweb: protocol requests are processed immediately
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6776
diff
changeset
|
101 |
5596
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
102 # work with CGI variables to create coherent structure |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
103 # use SCRIPT_NAME, PATH_INFO and QUERY_STRING as well as our REPO_NAME |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
104 |
5596
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
105 req.url = req.env['SCRIPT_NAME'] |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
106 if not req.url.endswith('/'): |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
107 req.url += '/' |
5915
d0576d065993
Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents:
5890
diff
changeset
|
108 if 'REPO_NAME' in req.env: |
5596
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
109 req.url += req.env['REPO_NAME'] + '/' |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
110 |
6459
8189e03adb44
hgweb: make hgwebdir work in the absence of PATH_INFO
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6379
diff
changeset
|
111 if 'PATH_INFO' in req.env: |
8189e03adb44
hgweb: make hgwebdir work in the absence of PATH_INFO
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6379
diff
changeset
|
112 parts = req.env['PATH_INFO'].strip('/').split('/') |
5596
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
113 repo_parts = req.env.get('REPO_NAME', '').split('/') |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
114 if parts[:len(repo_parts)] == repo_parts: |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
115 parts = parts[len(repo_parts):] |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
116 query = '/'.join(parts) |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
117 else: |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
118 query = req.env['QUERY_STRING'].split('&', 1)[0] |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
119 query = query.split(';', 1)[0] |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
120 |
5596
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
121 # translate user-visible url structure to internal structure |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
122 |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
123 args = query.split('/', 2) |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
124 if 'cmd' not in req.form and args and args[0]: |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
125 |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
126 cmd = args.pop(0) |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
127 style = cmd.rfind('-') |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
128 if style != -1: |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
129 req.form['style'] = [cmd[:style]] |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
130 cmd = cmd[style+1:] |
5596
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
131 |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
132 # avoid accepting e.g. style parameter as command |
6777
44c5157474e7
hgweb: protocol requests are processed immediately
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6776
diff
changeset
|
133 if hasattr(webcommands, cmd): |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
134 req.form['cmd'] = [cmd] |
6777
44c5157474e7
hgweb: protocol requests are processed immediately
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6776
diff
changeset
|
135 else: |
44c5157474e7
hgweb: protocol requests are processed immediately
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6776
diff
changeset
|
136 cmd = '' |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
137 |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
138 if args and args[0]: |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
139 node = args.pop(0) |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
140 req.form['node'] = [node] |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
141 if args: |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
142 req.form['file'] = args |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
143 |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
144 if cmd == 'static': |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
145 req.form['file'] = req.form['node'] |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
146 elif cmd == 'archive': |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
147 fn = req.form['node'][0] |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
148 for type_, spec in self.archive_specs.iteritems(): |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
149 ext = spec[2] |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
150 if fn.endswith(ext): |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
151 req.form['node'] = [fn[:-len(ext)]] |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
152 req.form['type'] = [type_] |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
153 |
6149
b023915aa1bc
hgweb: separate protocol calls from interface calls (issue996)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6142
diff
changeset
|
154 # process the web interface request |
5599
3de66c2a9734
hgweb: split out templater definition
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
155 |
3de66c2a9734
hgweb: split out templater definition
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
156 try: |
3de66c2a9734
hgweb: split out templater definition
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
157 |
6149
b023915aa1bc
hgweb: separate protocol calls from interface calls (issue996)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6142
diff
changeset
|
158 tmpl = self.templater(req) |
6391
a1007f7b9b7b
Backed out changeset d2bb66a8a435 (temporary template compatibility)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6379
diff
changeset
|
159 ctype = tmpl('mimetype', encoding=self.encoding) |
a1007f7b9b7b
Backed out changeset d2bb66a8a435 (temporary template compatibility)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6379
diff
changeset
|
160 ctype = templater.stringify(ctype) |
6149
b023915aa1bc
hgweb: separate protocol calls from interface calls (issue996)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6142
diff
changeset
|
161 |
b023915aa1bc
hgweb: separate protocol calls from interface calls (issue996)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6142
diff
changeset
|
162 if cmd == '': |
b023915aa1bc
hgweb: separate protocol calls from interface calls (issue996)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6142
diff
changeset
|
163 req.form['cmd'] = [tmpl.cache['default']] |
b023915aa1bc
hgweb: separate protocol calls from interface calls (issue996)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6142
diff
changeset
|
164 cmd = req.form['cmd'][0] |
5890
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5889
diff
changeset
|
165 |
6149
b023915aa1bc
hgweb: separate protocol calls from interface calls (issue996)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6142
diff
changeset
|
166 if cmd not in webcommands.__all__: |
6368
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6249
diff
changeset
|
167 msg = 'no such method: %s' % cmd |
6149
b023915aa1bc
hgweb: separate protocol calls from interface calls (issue996)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6142
diff
changeset
|
168 raise ErrorResponse(HTTP_BAD_REQUEST, msg) |
b023915aa1bc
hgweb: separate protocol calls from interface calls (issue996)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6142
diff
changeset
|
169 elif cmd == 'file' and 'raw' in req.form.get('style', []): |
b023915aa1bc
hgweb: separate protocol calls from interface calls (issue996)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6142
diff
changeset
|
170 self.ctype = ctype |
b023915aa1bc
hgweb: separate protocol calls from interface calls (issue996)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6142
diff
changeset
|
171 content = webcommands.rawfile(self, req, tmpl) |
b023915aa1bc
hgweb: separate protocol calls from interface calls (issue996)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6142
diff
changeset
|
172 else: |
b023915aa1bc
hgweb: separate protocol calls from interface calls (issue996)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6142
diff
changeset
|
173 content = getattr(webcommands, cmd)(self, req, tmpl) |
b023915aa1bc
hgweb: separate protocol calls from interface calls (issue996)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6142
diff
changeset
|
174 req.respond(HTTP_OK, ctype) |
5890
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5889
diff
changeset
|
175 |
6149
b023915aa1bc
hgweb: separate protocol calls from interface calls (issue996)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6142
diff
changeset
|
176 req.write(content) |
b023915aa1bc
hgweb: separate protocol calls from interface calls (issue996)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6142
diff
changeset
|
177 del tmpl |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
178 |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
179 except revlog.LookupError, err: |
5993
948a41e77902
hgweb: explicit response status
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5976
diff
changeset
|
180 req.respond(HTTP_NOT_FOUND, ctype) |
6374
31a01e3d99cc
hgweb: fix breakage in python < 2.5 introduced in 2c370f08c486
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6368
diff
changeset
|
181 msg = str(err) |
31a01e3d99cc
hgweb: fix breakage in python < 2.5 introduced in 2c370f08c486
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6368
diff
changeset
|
182 if 'manifest' not in msg: |
6368
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6249
diff
changeset
|
183 msg = 'revision not found: %s' % err.name |
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6249
diff
changeset
|
184 req.write(tmpl('error', error=msg)) |
6217
fe8dbbe9520d
Avoid importing mercurial.node/mercurial.repo stuff from mercurial.hg
Joel Rosdahl <joel@rosdahl.net>
parents:
6211
diff
changeset
|
185 except (RepoError, revlog.RevlogError), inst: |
5993
948a41e77902
hgweb: explicit response status
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5976
diff
changeset
|
186 req.respond(HTTP_SERVER_ERROR, ctype) |
948a41e77902
hgweb: explicit response status
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5976
diff
changeset
|
187 req.write(tmpl('error', error=str(inst))) |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
188 except ErrorResponse, inst: |
5993
948a41e77902
hgweb: explicit response status
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5976
diff
changeset
|
189 req.respond(inst.code, ctype) |
948a41e77902
hgweb: explicit response status
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5976
diff
changeset
|
190 req.write(tmpl('error', error=inst.message)) |
5599
3de66c2a9734
hgweb: split out templater definition
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
191 |
3de66c2a9734
hgweb: split out templater definition
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
192 def templater(self, req): |
3de66c2a9734
hgweb: split out templater definition
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
193 |
5596
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
194 # determine scheme, port and server name |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
195 # this is needed to create absolute urls |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
196 |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
197 proto = req.env.get('wsgi.url_scheme') |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
198 if proto == 'https': |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
199 proto = 'https' |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
200 default_port = "443" |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
201 else: |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
202 proto = 'http' |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
203 default_port = "80" |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
204 |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
205 port = req.env["SERVER_PORT"] |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
206 port = port != default_port and (":" + port) or "" |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
207 urlbase = '%s://%s%s' % (proto, req.env['SERVER_NAME'], port) |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
208 staticurl = self.config("web", "staticurl") or req.url + 'static/' |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
209 if not staticurl.endswith('/'): |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
210 staticurl += '/' |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
211 |
5596
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
212 # some functions for the templater |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
213 |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
214 def header(**map): |
6391
a1007f7b9b7b
Backed out changeset d2bb66a8a435 (temporary template compatibility)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6379
diff
changeset
|
215 yield tmpl('header', encoding=self.encoding, **map) |
5596
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
216 |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
217 def footer(**map): |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
218 yield tmpl("footer", **map) |
5596
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
219 |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
220 def motd(**map): |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
221 yield self.config("web", "motd", "") |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
222 |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
223 def sessionvars(**map): |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
224 fields = [] |
5915
d0576d065993
Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents:
5890
diff
changeset
|
225 if 'style' in req.form: |
5596
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
226 style = req.form['style'][0] |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
227 if style != self.config('web', 'style', ''): |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
228 fields.append(('style', style)) |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
229 |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
230 separator = req.url[-1] == '?' and ';' or '?' |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
231 for name, value in fields: |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
232 yield dict(name=name, value=value, separator=separator) |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
233 separator = ';' |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
234 |
5599
3de66c2a9734
hgweb: split out templater definition
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
235 # figure out which style to use |
3de66c2a9734
hgweb: split out templater definition
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
236 |
5596
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
237 style = self.config("web", "style", "") |
5915
d0576d065993
Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents:
5890
diff
changeset
|
238 if 'style' in req.form: |
5596
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
239 style = req.form['style'][0] |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
240 mapfile = style_map(self.templatepath, style) |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
241 |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
242 if not self.reponame: |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
243 self.reponame = (self.config("web", "name") |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
244 or req.env.get('REPO_NAME') |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
245 or req.url.strip('/') or self.repo.root) |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
246 |
5599
3de66c2a9734
hgweb: split out templater definition
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
247 # create the templater |
3de66c2a9734
hgweb: split out templater definition
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
248 |
5976
9f1e6ab76069
templates: move filters to their own module
Matt Mackall <mpm@selenic.com>
parents:
5964
diff
changeset
|
249 tmpl = templater.templater(mapfile, templatefilters.filters, |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
250 defaults={"url": req.url, |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
251 "staticurl": staticurl, |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
252 "urlbase": urlbase, |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
253 "repo": self.reponame, |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
254 "header": header, |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
255 "footer": footer, |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
256 "motd": motd, |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
257 "sessionvars": sessionvars |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
258 }) |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
259 return tmpl |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
260 |
1498
78590fb4a82b
hgweb: Added archive download buttons to manifest page.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1473
diff
changeset
|
261 def archivelist(self, nodeid): |
3555
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
262 allowed = self.configlist("web", "allow_archive") |
3260
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
263 for i, spec in self.archive_specs.iteritems(): |
3555
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
264 if i in allowed or self.configbool("web", "allow" + i): |
3260
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
265 yield {"type" : i, "extension" : spec[2], "node" : nodeid} |
1498
78590fb4a82b
hgweb: Added archive download buttons to manifest page.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1473
diff
changeset
|
266 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
267 def listfilediffs(self, tmpl, files, changeset): |
138 | 268 for f in files[:self.maxfiles]: |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
269 yield tmpl("filedifflink", node=hex(changeset), file=f) |
138 | 270 if len(files) > self.maxfiles: |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
271 yield tmpl("fileellipses") |
138 | 272 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
273 def diff(self, tmpl, node1, node2, files): |
1626
f2b1df3dbcbb
make the order of the arguments for filterfiles consistent
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1619
diff
changeset
|
274 def filterfiles(filters, files): |
1627
11cd38286fdb
fix for hgweb.filterfiles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1626
diff
changeset
|
275 l = [x for x in files if x in filters] |
515 | 276 |
1626
f2b1df3dbcbb
make the order of the arguments for filterfiles consistent
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1619
diff
changeset
|
277 for t in filters: |
1627
11cd38286fdb
fix for hgweb.filterfiles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1626
diff
changeset
|
278 if t and t[-1] != os.sep: |
1626
f2b1df3dbcbb
make the order of the arguments for filterfiles consistent
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1619
diff
changeset
|
279 t += os.sep |
f2b1df3dbcbb
make the order of the arguments for filterfiles consistent
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1619
diff
changeset
|
280 l += [x for x in files if x.startswith(t)] |
138 | 281 return l |
131 | 282 |
4462
12e4d9524951
hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4458
diff
changeset
|
283 parity = paritygen(self.stripecount) |
172
e9b1147db448
hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents:
168
diff
changeset
|
284 def diffblock(diff, f, fn): |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
285 yield tmpl("diffblock", |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
286 lines=prettyprintlines(diff), |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
287 parity=parity.next(), |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
288 file=f, |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
289 filenode=hex(fn or nullid)) |
515 | 290 |
6122
800e2756c9ab
Add line anchors to annotate, changeset, diff, file views for hgweb
Edward Lee <edward.lee@engineering.uiuc.edu>
parents:
5336
diff
changeset
|
291 blockcount = countgen() |
172
e9b1147db448
hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents:
168
diff
changeset
|
292 def prettyprintlines(diff): |
6122
800e2756c9ab
Add line anchors to annotate, changeset, diff, file views for hgweb
Edward Lee <edward.lee@engineering.uiuc.edu>
parents:
5336
diff
changeset
|
293 blockno = blockcount.next() |
800e2756c9ab
Add line anchors to annotate, changeset, diff, file views for hgweb
Edward Lee <edward.lee@engineering.uiuc.edu>
parents:
5336
diff
changeset
|
294 for lineno, l in enumerate(diff.splitlines(1)): |
800e2756c9ab
Add line anchors to annotate, changeset, diff, file views for hgweb
Edward Lee <edward.lee@engineering.uiuc.edu>
parents:
5336
diff
changeset
|
295 if blockno == 0: |
800e2756c9ab
Add line anchors to annotate, changeset, diff, file views for hgweb
Edward Lee <edward.lee@engineering.uiuc.edu>
parents:
5336
diff
changeset
|
296 lineno = lineno + 1 |
800e2756c9ab
Add line anchors to annotate, changeset, diff, file views for hgweb
Edward Lee <edward.lee@engineering.uiuc.edu>
parents:
5336
diff
changeset
|
297 else: |
800e2756c9ab
Add line anchors to annotate, changeset, diff, file views for hgweb
Edward Lee <edward.lee@engineering.uiuc.edu>
parents:
5336
diff
changeset
|
298 lineno = "%d.%d" % (blockno, lineno + 1) |
201
f918a6fa2572
hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents:
198
diff
changeset
|
299 if l.startswith('+'): |
6123
f7f25f58693a
merged Edward Lee's line anchors patch
Thomas Arendsen Hein <thomas@intevation.de>
diff
changeset
|
300 ltype = "difflineplus" |
201
f918a6fa2572
hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents:
198
diff
changeset
|
301 elif l.startswith('-'): |
6123
f7f25f58693a
merged Edward Lee's line anchors patch
Thomas Arendsen Hein <thomas@intevation.de>
diff
changeset
|
302 ltype = "difflineminus" |
201
f918a6fa2572
hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents:
198
diff
changeset
|
303 elif l.startswith('@'): |
6123
f7f25f58693a
merged Edward Lee's line anchors patch
Thomas Arendsen Hein <thomas@intevation.de>
diff
changeset
|
304 ltype = "difflineat" |
138 | 305 else: |
6123
f7f25f58693a
merged Edward Lee's line anchors patch
Thomas Arendsen Hein <thomas@intevation.de>
diff
changeset
|
306 ltype = "diffline" |
f7f25f58693a
merged Edward Lee's line anchors patch
Thomas Arendsen Hein <thomas@intevation.de>
diff
changeset
|
307 yield tmpl(ltype, |
f7f25f58693a
merged Edward Lee's line anchors patch
Thomas Arendsen Hein <thomas@intevation.de>
diff
changeset
|
308 line=l, |
f7f25f58693a
merged Edward Lee's line anchors patch
Thomas Arendsen Hein <thomas@intevation.de>
diff
changeset
|
309 lineid="l%s" % lineno, |
f7f25f58693a
merged Edward Lee's line anchors patch
Thomas Arendsen Hein <thomas@intevation.de>
diff
changeset
|
310 linenumber="% 8s" % lineno) |
131 | 311 |
138 | 312 r = self.repo |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6460
diff
changeset
|
313 c1 = r[node1] |
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6460
diff
changeset
|
314 c2 = r[node2] |
3973
b485a4459d96
hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3936
diff
changeset
|
315 date1 = util.datestr(c1.date()) |
b485a4459d96
hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3936
diff
changeset
|
316 date2 = util.datestr(c2.date()) |
131 | 317 |
2876
cf86bbb8ed68
hgweb: repo.changes() is now called repo.status()
Giorgos Keramidas <keramida@ceid.upatras.gr>
parents:
2874
diff
changeset
|
318 modified, added, removed, deleted, unknown = r.status(node1, node2)[:5] |
645
a55048b2ae3a
this patch permits hgweb to show the deleted files in the changeset diff
kreijack@inwind.REMOVEME.it
parents:
635
diff
changeset
|
319 if files: |
1626
f2b1df3dbcbb
make the order of the arguments for filterfiles consistent
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1619
diff
changeset
|
320 modified, added, removed = map(lambda x: filterfiles(files, x), |
1618
ff339dd21976
Renamed c, a, d, u to modified, added, removed, unknown for users of changes()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1606
diff
changeset
|
321 (modified, added, removed)) |
131 | 322 |
3555
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
323 diffopts = patch.diffopts(self.repo.ui, untrusted=True) |
1618
ff339dd21976
Renamed c, a, d, u to modified, added, removed, unknown for users of changes()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1606
diff
changeset
|
324 for f in modified: |
3973
b485a4459d96
hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3936
diff
changeset
|
325 to = c1.filectx(f).data() |
b485a4459d96
hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3936
diff
changeset
|
326 tn = c2.filectx(f).data() |
5486
48c22c719f8c
hgweb_mod: update unidiff() calls and finish e5eedd74e70f job
Rocco Rutte <pdmef@gmx.net>
parents:
5336
diff
changeset
|
327 yield diffblock(mdiff.unidiff(to, date1, tn, date2, f, f, |
2874
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2859
diff
changeset
|
328 opts=diffopts), f, tn) |
1618
ff339dd21976
Renamed c, a, d, u to modified, added, removed, unknown for users of changes()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1606
diff
changeset
|
329 for f in added: |
265
7ca05593bd30
hgweb: fix non-existent source or destination for diff
mpm@selenic.com
parents:
258
diff
changeset
|
330 to = None |
3973
b485a4459d96
hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3936
diff
changeset
|
331 tn = c2.filectx(f).data() |
5486
48c22c719f8c
hgweb_mod: update unidiff() calls and finish e5eedd74e70f job
Rocco Rutte <pdmef@gmx.net>
parents:
5336
diff
changeset
|
332 yield diffblock(mdiff.unidiff(to, date1, tn, date2, f, f, |
2874
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2859
diff
changeset
|
333 opts=diffopts), f, tn) |
1618
ff339dd21976
Renamed c, a, d, u to modified, added, removed, unknown for users of changes()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1606
diff
changeset
|
334 for f in removed: |
3973
b485a4459d96
hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3936
diff
changeset
|
335 to = c1.filectx(f).data() |
265
7ca05593bd30
hgweb: fix non-existent source or destination for diff
mpm@selenic.com
parents:
258
diff
changeset
|
336 tn = None |
5486
48c22c719f8c
hgweb_mod: update unidiff() calls and finish e5eedd74e70f job
Rocco Rutte <pdmef@gmx.net>
parents:
5336
diff
changeset
|
337 yield diffblock(mdiff.unidiff(to, date1, tn, date2, f, f, |
2874
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2859
diff
changeset
|
338 opts=diffopts), f, tn) |
131 | 339 |
2113
633d733e7b11
make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2103
diff
changeset
|
340 archive_specs = { |
2361
d3adb454c5a9
Fix automatic decompression of tarballs with Firefox.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2359
diff
changeset
|
341 'bz2': ('application/x-tar', 'tbz2', '.tar.bz2', None), |
d3adb454c5a9
Fix automatic decompression of tarballs with Firefox.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2359
diff
changeset
|
342 'gz': ('application/x-tar', 'tgz', '.tar.gz', None), |
2113
633d733e7b11
make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2103
diff
changeset
|
343 'zip': ('application/zip', 'zip', '.zip', None), |
633d733e7b11
make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2103
diff
changeset
|
344 } |
1076
01db658cc78a
tarball support v0.3
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1073
diff
changeset
|
345 |
2466
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
346 def check_perm(self, req, op, default): |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
347 '''check permission for operation based on user auth. |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
348 return true if op allowed, else false. |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
349 default is policy to use if no config given.''' |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
350 |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
351 user = req.env.get('REMOTE_USER') |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
352 |
3555
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
353 deny = self.configlist('web', 'deny_' + op) |
2466
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
354 if deny and (not user or deny == ['*'] or user in deny): |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
355 return False |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
356 |
3555
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
357 allow = self.configlist('web', 'allow_' + op) |
2466
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
358 return (allow and (allow == ['*'] or user in allow)) or default |