Mercurial > hg-stable
annotate mercurial/hgweb/hgweb_mod.py @ 6392:2540521dc7c1
hgweb: separate out utility functions
author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
---|---|
date | Fri, 28 Mar 2008 19:37:28 +0100 |
parents | a1007f7b9b7b |
children | 894875eae49b |
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 | |
6391
a1007f7b9b7b
Backed out changeset d2bb66a8a435 (temporary template compatibility)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6379
diff
changeset
|
9 import os, mimetypes, re |
6211
f89fd07fc51d
Expand import * to allow Pyflakes to find problems
Joel Rosdahl <joel@rosdahl.net>
parents:
6203
diff
changeset
|
10 from mercurial.node import hex, nullid, short |
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 |
5833
323b9c55b328
hook: redirect stdout to stderr for ssh and http servers
Matt Mackall <mpm@selenic.com>
parents:
5779
diff
changeset
|
12 from mercurial import mdiff, ui, hg, util, archival, 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 |
6123
f7f25f58693a
merged Edward Lee's line anchors patch
Thomas Arendsen Hein <thomas@intevation.de>
diff
changeset
|
14 from common import get_mtime, style_map, paritygen, countgen, get_contact |
f7f25f58693a
merged Edward Lee's line anchors patch
Thomas Arendsen Hein <thomas@intevation.de>
diff
changeset
|
15 from common import ErrorResponse |
5993
948a41e77902
hgweb: explicit response status
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5976
diff
changeset
|
16 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
|
17 from request import wsgirequest |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
18 import webcommands, protocol, webutil |
138 | 19 |
5597
e7f99a3ed008
hgweb: extract constant to global level
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5596
diff
changeset
|
20 shortcuts = { |
e7f99a3ed008
hgweb: extract constant to global level
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5596
diff
changeset
|
21 'cl': [('cmd', ['changelog']), ('rev', None)], |
e7f99a3ed008
hgweb: extract constant to global level
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5596
diff
changeset
|
22 'sl': [('cmd', ['shortlog']), ('rev', None)], |
e7f99a3ed008
hgweb: extract constant to global level
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5596
diff
changeset
|
23 'cs': [('cmd', ['changeset']), ('node', None)], |
e7f99a3ed008
hgweb: extract constant to global level
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5596
diff
changeset
|
24 'f': [('cmd', ['file']), ('filenode', None)], |
e7f99a3ed008
hgweb: extract constant to global level
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5596
diff
changeset
|
25 'fl': [('cmd', ['filelog']), ('filenode', None)], |
e7f99a3ed008
hgweb: extract constant to global level
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5596
diff
changeset
|
26 'fd': [('cmd', ['filediff']), ('node', None)], |
e7f99a3ed008
hgweb: extract constant to global level
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5596
diff
changeset
|
27 'fa': [('cmd', ['annotate']), ('filenode', None)], |
e7f99a3ed008
hgweb: extract constant to global level
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5596
diff
changeset
|
28 'mf': [('cmd', ['manifest']), ('manifest', None)], |
e7f99a3ed008
hgweb: extract constant to global level
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5596
diff
changeset
|
29 'ca': [('cmd', ['archive']), ('node', None)], |
e7f99a3ed008
hgweb: extract constant to global level
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5596
diff
changeset
|
30 'tags': [('cmd', ['tags'])], |
e7f99a3ed008
hgweb: extract constant to global level
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5596
diff
changeset
|
31 'tip': [('cmd', ['changeset']), ('node', ['tip'])], |
e7f99a3ed008
hgweb: extract constant to global level
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5596
diff
changeset
|
32 'static': [('cmd', ['static']), ('file', None)] |
e7f99a3ed008
hgweb: extract constant to global level
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5596
diff
changeset
|
33 } |
138 | 34 |
2356
2db831b33e8f
Final stage of the hgweb split up.
Eric Hopper <hopper@omnifarious.org>
parents:
2355
diff
changeset
|
35 def _up(p): |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
36 if p[0] != "/": |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
37 p = "/" + p |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
38 if p[-1] == "/": |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
39 p = p[:-1] |
138 | 40 up = os.path.dirname(p) |
41 if up == "/": | |
42 return "/" | |
43 return up + "/" | |
131 | 44 |
3422
0eba7e76cd02
Convert changenav bar from revisions to hashes (closes issue189)
Brendan Cully <brendan@kublai.com>
parents:
3409
diff
changeset
|
45 def revnavgen(pos, pagelen, limit, nodefunc): |
3407
03e7e8958a27
hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents:
3406
diff
changeset
|
46 def seq(factor, limit=None): |
03e7e8958a27
hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents:
3406
diff
changeset
|
47 if limit: |
03e7e8958a27
hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents:
3406
diff
changeset
|
48 yield limit |
03e7e8958a27
hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents:
3406
diff
changeset
|
49 if limit >= 20 and limit <= 40: |
03e7e8958a27
hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents:
3406
diff
changeset
|
50 yield 50 |
03e7e8958a27
hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents:
3406
diff
changeset
|
51 else: |
03e7e8958a27
hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents:
3406
diff
changeset
|
52 yield 1 * factor |
03e7e8958a27
hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents:
3406
diff
changeset
|
53 yield 3 * factor |
03e7e8958a27
hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents:
3406
diff
changeset
|
54 for f in seq(factor * 10): |
03e7e8958a27
hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents:
3406
diff
changeset
|
55 yield f |
03e7e8958a27
hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents:
3406
diff
changeset
|
56 |
03e7e8958a27
hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents:
3406
diff
changeset
|
57 def nav(**map): |
03e7e8958a27
hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents:
3406
diff
changeset
|
58 l = [] |
03e7e8958a27
hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents:
3406
diff
changeset
|
59 last = 0 |
03e7e8958a27
hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents:
3406
diff
changeset
|
60 for f in seq(1, pagelen): |
03e7e8958a27
hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents:
3406
diff
changeset
|
61 if f < pagelen or f <= last: |
03e7e8958a27
hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents:
3406
diff
changeset
|
62 continue |
03e7e8958a27
hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents:
3406
diff
changeset
|
63 if f > limit: |
03e7e8958a27
hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents:
3406
diff
changeset
|
64 break |
03e7e8958a27
hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents:
3406
diff
changeset
|
65 last = f |
03e7e8958a27
hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents:
3406
diff
changeset
|
66 if pos + f < limit: |
3422
0eba7e76cd02
Convert changenav bar from revisions to hashes (closes issue189)
Brendan Cully <brendan@kublai.com>
parents:
3409
diff
changeset
|
67 l.append(("+%d" % f, hex(nodefunc(pos + f).node()))) |
3407
03e7e8958a27
hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents:
3406
diff
changeset
|
68 if pos - f >= 0: |
3422
0eba7e76cd02
Convert changenav bar from revisions to hashes (closes issue189)
Brendan Cully <brendan@kublai.com>
parents:
3409
diff
changeset
|
69 l.insert(0, ("-%d" % f, hex(nodefunc(pos - f).node()))) |
3407
03e7e8958a27
hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents:
3406
diff
changeset
|
70 |
3424
9b1c126b74cd
Fix test-oldcgi after navbar update
Brendan Cully <brendan@kublai.com>
parents:
3423
diff
changeset
|
71 try: |
9b1c126b74cd
Fix test-oldcgi after navbar update
Brendan Cully <brendan@kublai.com>
parents:
3423
diff
changeset
|
72 yield {"label": "(0)", "node": hex(nodefunc('0').node())} |
3407
03e7e8958a27
hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents:
3406
diff
changeset
|
73 |
3424
9b1c126b74cd
Fix test-oldcgi after navbar update
Brendan Cully <brendan@kublai.com>
parents:
3423
diff
changeset
|
74 for label, node in l: |
9b1c126b74cd
Fix test-oldcgi after navbar update
Brendan Cully <brendan@kublai.com>
parents:
3423
diff
changeset
|
75 yield {"label": label, "node": node} |
3407
03e7e8958a27
hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents:
3406
diff
changeset
|
76 |
3427
6bd676ee8b99
Explicitly use "tip" in revision navigation.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3424
diff
changeset
|
77 yield {"label": "tip", "node": "tip"} |
6217
fe8dbbe9520d
Avoid importing mercurial.node/mercurial.repo stuff from mercurial.hg
Joel Rosdahl <joel@rosdahl.net>
parents:
6211
diff
changeset
|
78 except RepoError: |
3424
9b1c126b74cd
Fix test-oldcgi after navbar update
Brendan Cully <brendan@kublai.com>
parents:
3423
diff
changeset
|
79 pass |
3407
03e7e8958a27
hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents:
3406
diff
changeset
|
80 |
03e7e8958a27
hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents:
3406
diff
changeset
|
81 return nav |
03e7e8958a27
hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents:
3406
diff
changeset
|
82 |
1559
59b3639df0a9
Convert all classes to new-style classes by deriving them from object.
Eric Hopper <hopper@omnifarious.org>
parents:
1554
diff
changeset
|
83 class hgweb(object): |
6141
90e5c82a3859
Backed out changeset b913d3aacddc (see issue971/msg5317)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5995
diff
changeset
|
84 def __init__(self, repo, name=None): |
4874
d9e385a7a806
Use isinstance instead of type == type
Christian Ebert <blacktrash@gmx.net>
parents:
4872
diff
changeset
|
85 if isinstance(repo, str): |
6141
90e5c82a3859
Backed out changeset b913d3aacddc (see issue971/msg5317)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5995
diff
changeset
|
86 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
|
87 self.repo = hg.repository(parentui, repo) |
987 | 88 else: |
89 self.repo = repo | |
133
fb84d3e71042
added template support for some hgweb output, also, template files for
jake@edge2.net
parents:
132
diff
changeset
|
90 |
5833
323b9c55b328
hook: redirect stdout to stderr for ssh and http servers
Matt Mackall <mpm@selenic.com>
parents:
5779
diff
changeset
|
91 hook.redirect(True) |
258 | 92 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
|
93 self.reponame = name |
1078 | 94 self.archives = 'zip', 'gz', 'bz2' |
2666
ebf033bc8eb2
hgweb: Configurable zebra stripes
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
2622
diff
changeset
|
95 self.stripecount = 1 |
6152
c050548307a4
hgweb: use bundletypes from mercurial.changegroup
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6149
diff
changeset
|
96 self._capabilities = None |
3555
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
97 # 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
|
98 # 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
|
99 self.templatepath = self.config("web", "templates", |
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
100 templater.templatepath(), |
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
101 untrusted=False) |
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
102 |
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
103 # 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
|
104 # 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
|
105 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
|
106 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
|
107 untrusted=untrusted) |
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
108 |
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
109 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
|
110 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
|
111 untrusted=untrusted) |
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
112 |
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
113 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
|
114 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
|
115 untrusted=untrusted) |
131 | 116 |
258 | 117 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
|
118 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
|
119 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
|
120 self.mtime = mtime |
1213 | 121 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
|
122 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
|
123 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
|
124 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
|
125 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
|
126 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
|
127 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
|
128 self._capabilities = None |
c050548307a4
hgweb: use bundletypes from mercurial.changegroup
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6149
diff
changeset
|
129 |
c050548307a4
hgweb: use bundletypes from mercurial.changegroup
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6149
diff
changeset
|
130 def capabilities(self): |
c050548307a4
hgweb: use bundletypes from mercurial.changegroup
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6149
diff
changeset
|
131 if self._capabilities is not None: |
c050548307a4
hgweb: use bundletypes from mercurial.changegroup
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6149
diff
changeset
|
132 return self._capabilities |
c050548307a4
hgweb: use bundletypes from mercurial.changegroup
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6149
diff
changeset
|
133 caps = ['lookup', 'changegroupsubset'] |
c050548307a4
hgweb: use bundletypes from mercurial.changegroup
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6149
diff
changeset
|
134 if self.configbool('server', 'uncompressed'): |
c050548307a4
hgweb: use bundletypes from mercurial.changegroup
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6149
diff
changeset
|
135 caps.append('stream=%d' % self.repo.changelog.version) |
c050548307a4
hgweb: use bundletypes from mercurial.changegroup
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6149
diff
changeset
|
136 if changegroup.bundlepriority: |
c050548307a4
hgweb: use bundletypes from mercurial.changegroup
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6149
diff
changeset
|
137 caps.append('unbundle=%s' % ','.join(changegroup.bundlepriority)) |
c050548307a4
hgweb: use bundletypes from mercurial.changegroup
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6149
diff
changeset
|
138 self._capabilities = caps |
c050548307a4
hgweb: use bundletypes from mercurial.changegroup
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6149
diff
changeset
|
139 return caps |
258 | 140 |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
141 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
|
142 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
|
143 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
|
144 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
|
145 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
|
146 |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
147 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
|
148 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
|
149 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
|
150 return req |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
151 |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
152 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
|
153 |
5596
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
154 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
|
155 |
5596
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
156 # expand form shortcuts |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
157 |
5596
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
158 for k in shortcuts.iterkeys(): |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
159 if k in req.form: |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
160 for name, value in shortcuts[k]: |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
161 if value is None: |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
162 value = req.form[k] |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
163 req.form[name] = value |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
164 del req.form[k] |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
165 |
5596
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
166 # 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
|
167 # 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
|
168 |
5596
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
169 req.url = req.env['SCRIPT_NAME'] |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
170 if not req.url.endswith('/'): |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
171 req.url += '/' |
5915
d0576d065993
Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents:
5890
diff
changeset
|
172 if 'REPO_NAME' in req.env: |
5596
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
173 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
|
174 |
5596
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
175 if req.env.get('PATH_INFO'): |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
176 parts = req.env.get('PATH_INFO').strip('/').split('/') |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
177 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
|
178 if parts[:len(repo_parts)] == repo_parts: |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
179 parts = parts[len(repo_parts):] |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
180 query = '/'.join(parts) |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
181 else: |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
182 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
|
183 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
|
184 |
5596
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
185 # 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
|
186 |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
187 args = query.split('/', 2) |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
188 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
|
189 |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
190 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
|
191 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
|
192 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
|
193 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
|
194 cmd = cmd[style+1:] |
5596
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
195 |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
196 # avoid accepting e.g. style parameter as command |
5598
d534ba1c4eb4
separate the wire protocol commands from the user interface commands
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5597
diff
changeset
|
197 if hasattr(webcommands, cmd) or hasattr(protocol, cmd): |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
198 req.form['cmd'] = [cmd] |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
199 |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
200 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
|
201 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
|
202 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
|
203 if args: |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
204 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
|
205 |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
206 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
|
207 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
|
208 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
|
209 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
|
210 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
|
211 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
|
212 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
|
213 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
|
214 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
|
215 |
6149
b023915aa1bc
hgweb: separate protocol calls from interface calls (issue996)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6142
diff
changeset
|
216 # process this if it's a protocol request |
b023915aa1bc
hgweb: separate protocol calls from interface calls (issue996)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6142
diff
changeset
|
217 |
b023915aa1bc
hgweb: separate protocol calls from interface calls (issue996)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6142
diff
changeset
|
218 cmd = req.form.get('cmd', [''])[0] |
b023915aa1bc
hgweb: separate protocol calls from interface calls (issue996)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6142
diff
changeset
|
219 if cmd in protocol.__all__: |
b023915aa1bc
hgweb: separate protocol calls from interface calls (issue996)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6142
diff
changeset
|
220 method = getattr(protocol, cmd) |
b023915aa1bc
hgweb: separate protocol calls from interface calls (issue996)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6142
diff
changeset
|
221 method(self, req) |
b023915aa1bc
hgweb: separate protocol calls from interface calls (issue996)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6142
diff
changeset
|
222 return |
b023915aa1bc
hgweb: separate protocol calls from interface calls (issue996)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6142
diff
changeset
|
223 |
b023915aa1bc
hgweb: separate protocol calls from interface calls (issue996)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6142
diff
changeset
|
224 # process the web interface request |
5599
3de66c2a9734
hgweb: split out templater definition
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
225 |
3de66c2a9734
hgweb: split out templater definition
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
226 try: |
3de66c2a9734
hgweb: split out templater definition
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
227 |
6149
b023915aa1bc
hgweb: separate protocol calls from interface calls (issue996)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6142
diff
changeset
|
228 tmpl = self.templater(req) |
6391
a1007f7b9b7b
Backed out changeset d2bb66a8a435 (temporary template compatibility)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6379
diff
changeset
|
229 ctype = tmpl('mimetype', encoding=self.encoding) |
a1007f7b9b7b
Backed out changeset d2bb66a8a435 (temporary template compatibility)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6379
diff
changeset
|
230 ctype = templater.stringify(ctype) |
6149
b023915aa1bc
hgweb: separate protocol calls from interface calls (issue996)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6142
diff
changeset
|
231 |
b023915aa1bc
hgweb: separate protocol calls from interface calls (issue996)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6142
diff
changeset
|
232 if cmd == '': |
b023915aa1bc
hgweb: separate protocol calls from interface calls (issue996)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6142
diff
changeset
|
233 req.form['cmd'] = [tmpl.cache['default']] |
b023915aa1bc
hgweb: separate protocol calls from interface calls (issue996)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6142
diff
changeset
|
234 cmd = req.form['cmd'][0] |
5890
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5889
diff
changeset
|
235 |
6149
b023915aa1bc
hgweb: separate protocol calls from interface calls (issue996)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6142
diff
changeset
|
236 if cmd not in webcommands.__all__: |
6368
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6249
diff
changeset
|
237 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
|
238 raise ErrorResponse(HTTP_BAD_REQUEST, msg) |
b023915aa1bc
hgweb: separate protocol calls from interface calls (issue996)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6142
diff
changeset
|
239 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
|
240 self.ctype = ctype |
b023915aa1bc
hgweb: separate protocol calls from interface calls (issue996)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6142
diff
changeset
|
241 content = webcommands.rawfile(self, req, tmpl) |
b023915aa1bc
hgweb: separate protocol calls from interface calls (issue996)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6142
diff
changeset
|
242 else: |
b023915aa1bc
hgweb: separate protocol calls from interface calls (issue996)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6142
diff
changeset
|
243 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
|
244 req.respond(HTTP_OK, ctype) |
5890
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5889
diff
changeset
|
245 |
6149
b023915aa1bc
hgweb: separate protocol calls from interface calls (issue996)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6142
diff
changeset
|
246 req.write(content) |
b023915aa1bc
hgweb: separate protocol calls from interface calls (issue996)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6142
diff
changeset
|
247 del tmpl |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
248 |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
249 except revlog.LookupError, err: |
5993
948a41e77902
hgweb: explicit response status
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5976
diff
changeset
|
250 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
|
251 msg = str(err) |
31a01e3d99cc
hgweb: fix breakage in python < 2.5 introduced in 2c370f08c486
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6368
diff
changeset
|
252 if 'manifest' not in msg: |
6368
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6249
diff
changeset
|
253 msg = 'revision not found: %s' % err.name |
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6249
diff
changeset
|
254 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
|
255 except (RepoError, revlog.RevlogError), inst: |
5993
948a41e77902
hgweb: explicit response status
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5976
diff
changeset
|
256 req.respond(HTTP_SERVER_ERROR, ctype) |
948a41e77902
hgweb: explicit response status
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5976
diff
changeset
|
257 req.write(tmpl('error', error=str(inst))) |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
258 except ErrorResponse, inst: |
5993
948a41e77902
hgweb: explicit response status
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5976
diff
changeset
|
259 req.respond(inst.code, ctype) |
948a41e77902
hgweb: explicit response status
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5976
diff
changeset
|
260 req.write(tmpl('error', error=inst.message)) |
5599
3de66c2a9734
hgweb: split out templater definition
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
261 |
3de66c2a9734
hgweb: split out templater definition
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
262 def templater(self, req): |
3de66c2a9734
hgweb: split out templater definition
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
263 |
5596
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
264 # determine scheme, port and server name |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
265 # 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
|
266 |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
267 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
|
268 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
|
269 proto = 'https' |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
270 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
|
271 else: |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
272 proto = 'http' |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
273 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
|
274 |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
275 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
|
276 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
|
277 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
|
278 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
|
279 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
|
280 staticurl += '/' |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
281 |
5596
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
282 # some functions for the templater |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
283 |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
284 def header(**map): |
6391
a1007f7b9b7b
Backed out changeset d2bb66a8a435 (temporary template compatibility)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6379
diff
changeset
|
285 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
|
286 |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
287 def footer(**map): |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
288 yield tmpl("footer", **map) |
5596
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
289 |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
290 def motd(**map): |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
291 yield self.config("web", "motd", "") |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
292 |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
293 def sessionvars(**map): |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
294 fields = [] |
5915
d0576d065993
Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents:
5890
diff
changeset
|
295 if 'style' in req.form: |
5596
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
296 style = req.form['style'][0] |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
297 if style != self.config('web', 'style', ''): |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
298 fields.append(('style', style)) |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
299 |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
300 separator = req.url[-1] == '?' and ';' or '?' |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
301 for name, value in fields: |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
302 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
|
303 separator = ';' |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
304 |
5599
3de66c2a9734
hgweb: split out templater definition
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
305 # figure out which style to use |
3de66c2a9734
hgweb: split out templater definition
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
306 |
5596
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
307 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
|
308 if 'style' in req.form: |
5596
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
309 style = req.form['style'][0] |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
310 mapfile = style_map(self.templatepath, style) |
20b07b68a865
hgweb: get rid of some nested functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5595
diff
changeset
|
311 |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5579
diff
changeset
|
312 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
|
313 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
|
314 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
|
315 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
|
316 |
5599
3de66c2a9734
hgweb: split out templater definition
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
317 # create the templater |
3de66c2a9734
hgweb: split out templater definition
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
318 |
5976
9f1e6ab76069
templates: move filters to their own module
Matt Mackall <mpm@selenic.com>
parents:
5964
diff
changeset
|
319 tmpl = templater.templater(mapfile, templatefilters.filters, |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
320 defaults={"url": req.url, |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
321 "staticurl": staticurl, |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
322 "urlbase": urlbase, |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
323 "repo": self.reponame, |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
324 "header": header, |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
325 "footer": footer, |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
326 "motd": motd, |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
327 "sessionvars": sessionvars |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
328 }) |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
329 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
|
330 |
1498
78590fb4a82b
hgweb: Added archive download buttons to manifest page.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1473
diff
changeset
|
331 def archivelist(self, nodeid): |
3555
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
332 allowed = self.configlist("web", "allow_archive") |
3260
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
333 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
|
334 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
|
335 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
|
336 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
337 def listfilediffs(self, tmpl, files, changeset): |
138 | 338 for f in files[:self.maxfiles]: |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
339 yield tmpl("filedifflink", node=hex(changeset), file=f) |
138 | 340 if len(files) > self.maxfiles: |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
341 yield tmpl("fileellipses") |
138 | 342 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
343 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
|
344 def filterfiles(filters, files): |
1627
11cd38286fdb
fix for hgweb.filterfiles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1626
diff
changeset
|
345 l = [x for x in files if x in filters] |
515 | 346 |
1626
f2b1df3dbcbb
make the order of the arguments for filterfiles consistent
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1619
diff
changeset
|
347 for t in filters: |
1627
11cd38286fdb
fix for hgweb.filterfiles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1626
diff
changeset
|
348 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
|
349 t += os.sep |
f2b1df3dbcbb
make the order of the arguments for filterfiles consistent
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1619
diff
changeset
|
350 l += [x for x in files if x.startswith(t)] |
138 | 351 return l |
131 | 352 |
4462
12e4d9524951
hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4458
diff
changeset
|
353 parity = paritygen(self.stripecount) |
172
e9b1147db448
hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents:
168
diff
changeset
|
354 def diffblock(diff, f, fn): |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
355 yield tmpl("diffblock", |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
356 lines=prettyprintlines(diff), |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
357 parity=parity.next(), |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
358 file=f, |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
359 filenode=hex(fn or nullid)) |
515 | 360 |
6122
800e2756c9ab
Add line anchors to annotate, changeset, diff, file views for hgweb
Edward Lee <edward.lee@engineering.uiuc.edu>
parents:
5336
diff
changeset
|
361 blockcount = countgen() |
172
e9b1147db448
hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents:
168
diff
changeset
|
362 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
|
363 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
|
364 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
|
365 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
|
366 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
|
367 else: |
800e2756c9ab
Add line anchors to annotate, changeset, diff, file views for hgweb
Edward Lee <edward.lee@engineering.uiuc.edu>
parents:
5336
diff
changeset
|
368 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
|
369 if l.startswith('+'): |
6123
f7f25f58693a
merged Edward Lee's line anchors patch
Thomas Arendsen Hein <thomas@intevation.de>
diff
changeset
|
370 ltype = "difflineplus" |
201
f918a6fa2572
hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents:
198
diff
changeset
|
371 elif l.startswith('-'): |
6123
f7f25f58693a
merged Edward Lee's line anchors patch
Thomas Arendsen Hein <thomas@intevation.de>
diff
changeset
|
372 ltype = "difflineminus" |
201
f918a6fa2572
hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents:
198
diff
changeset
|
373 elif l.startswith('@'): |
6123
f7f25f58693a
merged Edward Lee's line anchors patch
Thomas Arendsen Hein <thomas@intevation.de>
diff
changeset
|
374 ltype = "difflineat" |
138 | 375 else: |
6123
f7f25f58693a
merged Edward Lee's line anchors patch
Thomas Arendsen Hein <thomas@intevation.de>
diff
changeset
|
376 ltype = "diffline" |
f7f25f58693a
merged Edward Lee's line anchors patch
Thomas Arendsen Hein <thomas@intevation.de>
diff
changeset
|
377 yield tmpl(ltype, |
f7f25f58693a
merged Edward Lee's line anchors patch
Thomas Arendsen Hein <thomas@intevation.de>
diff
changeset
|
378 line=l, |
f7f25f58693a
merged Edward Lee's line anchors patch
Thomas Arendsen Hein <thomas@intevation.de>
diff
changeset
|
379 lineid="l%s" % lineno, |
f7f25f58693a
merged Edward Lee's line anchors patch
Thomas Arendsen Hein <thomas@intevation.de>
diff
changeset
|
380 linenumber="% 8s" % lineno) |
131 | 381 |
138 | 382 r = self.repo |
3973
b485a4459d96
hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3936
diff
changeset
|
383 c1 = r.changectx(node1) |
b485a4459d96
hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3936
diff
changeset
|
384 c2 = r.changectx(node2) |
b485a4459d96
hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3936
diff
changeset
|
385 date1 = util.datestr(c1.date()) |
b485a4459d96
hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3936
diff
changeset
|
386 date2 = util.datestr(c2.date()) |
131 | 387 |
2876
cf86bbb8ed68
hgweb: repo.changes() is now called repo.status()
Giorgos Keramidas <keramida@ceid.upatras.gr>
parents:
2874
diff
changeset
|
388 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
|
389 if files: |
1626
f2b1df3dbcbb
make the order of the arguments for filterfiles consistent
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1619
diff
changeset
|
390 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
|
391 (modified, added, removed)) |
131 | 392 |
3555
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
393 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
|
394 for f in modified: |
3973
b485a4459d96
hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3936
diff
changeset
|
395 to = c1.filectx(f).data() |
b485a4459d96
hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3936
diff
changeset
|
396 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
|
397 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
|
398 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
|
399 for f in added: |
265
7ca05593bd30
hgweb: fix non-existent source or destination for diff
mpm@selenic.com
parents:
258
diff
changeset
|
400 to = None |
3973
b485a4459d96
hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3936
diff
changeset
|
401 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
|
402 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
|
403 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
|
404 for f in removed: |
3973
b485a4459d96
hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3936
diff
changeset
|
405 to = c1.filectx(f).data() |
265
7ca05593bd30
hgweb: fix non-existent source or destination for diff
mpm@selenic.com
parents:
258
diff
changeset
|
406 tn = None |
5486
48c22c719f8c
hgweb_mod: update unidiff() calls and finish e5eedd74e70f job
Rocco Rutte <pdmef@gmx.net>
parents:
5336
diff
changeset
|
407 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
|
408 opts=diffopts), f, tn) |
131 | 409 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
410 def changelog(self, tmpl, ctx, shortlog=False): |
5269
46c5e1ee8aaa
Added support for the Atom syndication format
Robert Bachmann <rbach@rbach.priv.at>
parents:
5123
diff
changeset
|
411 def changelist(limit=0,**map): |
138 | 412 cl = self.repo.changelog |
413 l = [] # build a list in forward order for efficiency | |
3473
0e68608bd11d
use xrange instead of range
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3445
diff
changeset
|
414 for i in xrange(start, end): |
3208
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
415 ctx = self.repo.changectx(i) |
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
416 n = ctx.node() |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
417 showtags = webutil.showtag(self.repo, tmpl, 'changelogtag', n) |
131 | 418 |
4462
12e4d9524951
hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4458
diff
changeset
|
419 l.insert(0, {"parity": parity.next(), |
3208
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
420 "author": ctx.user(), |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
421 "parent": webutil.siblings(ctx.parents(), i - 1), |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
422 "child": webutil.siblings(ctx.children(), i + 1), |
6168
2ab54f48dbe8
hgweb: fix parameter mixup (issue1001)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6152
diff
changeset
|
423 "changelogtag": showtags, |
3208
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
424 "desc": ctx.description(), |
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
425 "date": ctx.date(), |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
426 "files": self.listfilediffs(tmpl, ctx.files(), n), |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
427 "rev": i, |
4538
4272ae760bb1
gitweb: Display branch and tag labels
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
4469
diff
changeset
|
428 "node": hex(n), |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
429 "tags": webutil.nodetagsdict(self.repo, n), |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
430 "inbranch": webutil.nodeinbranch(self.repo, ctx), |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
431 "branches": webutil.nodebranchdict(self.repo, ctx) |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
432 }) |
138 | 433 |
5269
46c5e1ee8aaa
Added support for the Atom syndication format
Robert Bachmann <rbach@rbach.priv.at>
parents:
5123
diff
changeset
|
434 if limit > 0: |
46c5e1ee8aaa
Added support for the Atom syndication format
Robert Bachmann <rbach@rbach.priv.at>
parents:
5123
diff
changeset
|
435 l = l[:limit] |
46c5e1ee8aaa
Added support for the Atom syndication format
Robert Bachmann <rbach@rbach.priv.at>
parents:
5123
diff
changeset
|
436 |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
437 for e in l: |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
438 yield e |
131 | 439 |
2684
783220e5d2d1
[hgweb] Implemented shortlog (gitweb templates only)
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
2683
diff
changeset
|
440 maxchanges = shortlog and self.maxshortchanges or self.maxchanges |
168 | 441 cl = self.repo.changelog |
442 count = cl.count() | |
3407
03e7e8958a27
hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents:
3406
diff
changeset
|
443 pos = ctx.rev() |
2684
783220e5d2d1
[hgweb] Implemented shortlog (gitweb templates only)
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
2683
diff
changeset
|
444 start = max(0, pos - maxchanges + 1) |
783220e5d2d1
[hgweb] Implemented shortlog (gitweb templates only)
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
2683
diff
changeset
|
445 end = min(count, start + maxchanges) |
351 | 446 pos = end - 1 |
4462
12e4d9524951
hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4458
diff
changeset
|
447 parity = paritygen(self.stripecount, offset=start-end) |
138 | 448 |
3422
0eba7e76cd02
Convert changenav bar from revisions to hashes (closes issue189)
Brendan Cully <brendan@kublai.com>
parents:
3409
diff
changeset
|
449 changenav = revnavgen(pos, maxchanges, count, self.repo.changectx) |
3407
03e7e8958a27
hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents:
3406
diff
changeset
|
450 |
5889
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
451 return tmpl(shortlog and 'shortlog' or 'changelog', |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
452 changenav=changenav, |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
453 node=hex(cl.tip()), |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
454 rev=pos, changesets=count, |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
455 entries=lambda **x: changelist(limit=0,**x), |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
456 latestentry=lambda **x: changelist(limit=1,**x), |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
457 archives=self.archivelist("tip")) |
131 | 458 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
459 def search(self, tmpl, query): |
538 | 460 |
857
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
461 def changelist(**map): |
538 | 462 cl = self.repo.changelog |
463 count = 0 | |
464 qw = query.lower().split() | |
465 | |
466 def revgen(): | |
3473
0e68608bd11d
use xrange instead of range
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3445
diff
changeset
|
467 for i in xrange(cl.count() - 1, 0, -100): |
538 | 468 l = [] |
6017
b29b75ce9645
hgweb: fix search skipping tip
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5486
diff
changeset
|
469 for j in xrange(max(0, i - 100), i + 1): |
3208
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
470 ctx = self.repo.changectx(j) |
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
471 l.append(ctx) |
1023 | 472 l.reverse() |
538 | 473 for e in l: |
474 yield e | |
475 | |
3208
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
476 for ctx in revgen(): |
538 | 477 miss = 0 |
478 for q in qw: | |
3208
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
479 if not (q in ctx.user().lower() or |
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
480 q in ctx.description().lower() or |
4323
7843528a7922
hgweb: expand keyword search to full list of files
TK Soh <teekaysoh@yahoo.com>
parents:
4243
diff
changeset
|
481 q in " ".join(ctx.files()).lower()): |
538 | 482 miss = 1 |
483 break | |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
484 if miss: |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
485 continue |
538 | 486 |
487 count += 1 | |
3208
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
488 n = ctx.node() |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
489 showtags = webutil.showtag(self.repo, tmpl, 'changelogtag', n) |
538 | 490 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
491 yield tmpl('searchentry', |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
492 parity=parity.next(), |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
493 author=ctx.user(), |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
494 parent=webutil.siblings(ctx.parents()), |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
495 child=webutil.siblings(ctx.children()), |
6168
2ab54f48dbe8
hgweb: fix parameter mixup (issue1001)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6152
diff
changeset
|
496 changelogtag=showtags, |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
497 desc=ctx.description(), |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
498 date=ctx.date(), |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
499 files=self.listfilediffs(tmpl, ctx.files(), n), |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
500 rev=ctx.rev(), |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
501 node=hex(n), |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
502 tags=webutil.nodetagsdict(self.repo, n), |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
503 inbranch=webutil.nodeinbranch(self.repo, ctx), |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
504 branches=webutil.nodebranchdict(self.repo, ctx)) |
538 | 505 |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
506 if count >= self.maxchanges: |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
507 break |
538 | 508 |
509 cl = self.repo.changelog | |
4462
12e4d9524951
hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4458
diff
changeset
|
510 parity = paritygen(self.stripecount) |
538 | 511 |
5889
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
512 return tmpl('search', |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
513 query=query, |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
514 node=hex(cl.tip()), |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
515 entries=changelist, |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
516 archives=self.archivelist("tip")) |
538 | 517 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
518 def changeset(self, tmpl, ctx): |
3208
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
519 n = ctx.node() |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
520 showtags = webutil.showtag(self.repo, tmpl, 'changesettag', n) |
3208
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
521 parents = ctx.parents() |
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
522 p1 = parents[0].node() |
515 | 523 |
133
fb84d3e71042
added template support for some hgweb output, also, template files for
jake@edge2.net
parents:
132
diff
changeset
|
524 files = [] |
4462
12e4d9524951
hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4458
diff
changeset
|
525 parity = paritygen(self.stripecount) |
3208
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
526 for f in ctx.files(): |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
527 files.append(tmpl("filenodelink", |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
528 node=hex(n), file=f, |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
529 parity=parity.next())) |
138 | 530 |
857
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
531 def diff(**map): |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
532 yield self.diff(tmpl, p1, n, None) |
131 | 533 |
5889
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
534 return tmpl('changeset', |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
535 diff=diff, |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
536 rev=ctx.rev(), |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
537 node=hex(n), |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
538 parent=webutil.siblings(parents), |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
539 child=webutil.siblings(ctx.children()), |
6168
2ab54f48dbe8
hgweb: fix parameter mixup (issue1001)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6152
diff
changeset
|
540 changesettag=showtags, |
5889
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
541 author=ctx.user(), |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
542 desc=ctx.description(), |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
543 date=ctx.date(), |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
544 files=files, |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
545 archives=self.archivelist(hex(n)), |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
546 tags=webutil.nodetagsdict(self.repo, n), |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
547 branch=webutil.nodebranchnodefault(ctx), |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
548 inbranch=webutil.nodeinbranch(self.repo, ctx), |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
549 branches=webutil.nodebranchdict(self.repo, ctx)) |
131 | 550 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
551 def filelog(self, tmpl, fctx): |
3206
79fd7a92f3e2
hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents:
3205
diff
changeset
|
552 f = fctx.path() |
79fd7a92f3e2
hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents:
3205
diff
changeset
|
553 fl = fctx.filelog() |
138 | 554 count = fl.count() |
3407
03e7e8958a27
hgweb: hoist changenav up, and use it in the filelog
Brendan Cully <brendan@kublai.com>
parents:
3406
diff
changeset
|
555 pagelen = self.maxshortchanges |
3409
1ae738bacf74
Fixed page overlap for file revision links in hgweb.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3407
diff
changeset
|
556 pos = fctx.filerev() |
3673
eb0b4a2d70a9
white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3612
diff
changeset
|
557 start = max(0, pos - pagelen + 1) |
3409
1ae738bacf74
Fixed page overlap for file revision links in hgweb.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3407
diff
changeset
|
558 end = min(count, start + pagelen) |
1ae738bacf74
Fixed page overlap for file revision links in hgweb.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3407
diff
changeset
|
559 pos = end - 1 |
4462
12e4d9524951
hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4458
diff
changeset
|
560 parity = paritygen(self.stripecount, offset=start-end) |
138 | 561 |
5269
46c5e1ee8aaa
Added support for the Atom syndication format
Robert Bachmann <rbach@rbach.priv.at>
parents:
5123
diff
changeset
|
562 def entries(limit=0, **map): |
138 | 563 l = [] |
515 | 564 |
3473
0e68608bd11d
use xrange instead of range
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3445
diff
changeset
|
565 for i in xrange(start, end): |
3208
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
566 ctx = fctx.filectx(i) |
138 | 567 n = fl.node(i) |
133
fb84d3e71042
added template support for some hgweb output, also, template files for
jake@edge2.net
parents:
132
diff
changeset
|
568 |
4462
12e4d9524951
hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4458
diff
changeset
|
569 l.insert(0, {"parity": parity.next(), |
978
ea67e5b37043
hgweb: Changed file revision page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
977
diff
changeset
|
570 "filerev": i, |
ea67e5b37043
hgweb: Changed file revision page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
977
diff
changeset
|
571 "file": f, |
3206
79fd7a92f3e2
hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents:
3205
diff
changeset
|
572 "node": hex(ctx.node()), |
79fd7a92f3e2
hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents:
3205
diff
changeset
|
573 "author": ctx.user(), |
79fd7a92f3e2
hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents:
3205
diff
changeset
|
574 "date": ctx.date(), |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
575 "rename": webutil.renamelink(fl, n), |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
576 "parent": webutil.siblings(fctx.parents()), |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
577 "child": webutil.siblings(fctx.children()), |
3206
79fd7a92f3e2
hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents:
3205
diff
changeset
|
578 "desc": ctx.description()}) |
138 | 579 |
5269
46c5e1ee8aaa
Added support for the Atom syndication format
Robert Bachmann <rbach@rbach.priv.at>
parents:
5123
diff
changeset
|
580 if limit > 0: |
46c5e1ee8aaa
Added support for the Atom syndication format
Robert Bachmann <rbach@rbach.priv.at>
parents:
5123
diff
changeset
|
581 l = l[:limit] |
46c5e1ee8aaa
Added support for the Atom syndication format
Robert Bachmann <rbach@rbach.priv.at>
parents:
5123
diff
changeset
|
582 |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
583 for e in l: |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
584 yield e |
138 | 585 |
3422
0eba7e76cd02
Convert changenav bar from revisions to hashes (closes issue189)
Brendan Cully <brendan@kublai.com>
parents:
3409
diff
changeset
|
586 nodefunc = lambda x: fctx.filectx(fileid=x) |
0eba7e76cd02
Convert changenav bar from revisions to hashes (closes issue189)
Brendan Cully <brendan@kublai.com>
parents:
3409
diff
changeset
|
587 nav = revnavgen(pos, pagelen, count, nodefunc) |
5889
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
588 return tmpl("filelog", file=f, node=hex(fctx.node()), nav=nav, |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
589 entries=lambda **x: entries(limit=0, **x), |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
590 latestentry=lambda **x: entries(limit=1, **x)) |
131 | 591 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
592 def filerevision(self, tmpl, fctx): |
3206
79fd7a92f3e2
hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents:
3205
diff
changeset
|
593 f = fctx.path() |
79fd7a92f3e2
hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents:
3205
diff
changeset
|
594 text = fctx.data() |
79fd7a92f3e2
hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents:
3205
diff
changeset
|
595 fl = fctx.filelog() |
79fd7a92f3e2
hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents:
3205
diff
changeset
|
596 n = fctx.filenode() |
4462
12e4d9524951
hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4458
diff
changeset
|
597 parity = paritygen(self.stripecount) |
142 | 598 |
1411
e2ba788545bf
hgweb: make viewing of non-text work in hgweb
Matt Mackall <mpm@selenic.com>
parents:
1409
diff
changeset
|
599 if util.binary(text): |
5962
0011316fbe0e
hgweb: get rid of raw-related code in hgweb.filerevision()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5930
diff
changeset
|
600 mt = mimetypes.guess_type(f)[0] or 'application/octet-stream' |
0011316fbe0e
hgweb: get rid of raw-related code in hgweb.filerevision()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5930
diff
changeset
|
601 text = '(binary:%s)' % mt |
1411
e2ba788545bf
hgweb: make viewing of non-text work in hgweb
Matt Mackall <mpm@selenic.com>
parents:
1409
diff
changeset
|
602 |
142 | 603 def lines(): |
6122
800e2756c9ab
Add line anchors to annotate, changeset, diff, file views for hgweb
Edward Lee <edward.lee@engineering.uiuc.edu>
parents:
5336
diff
changeset
|
604 for lineno, t in enumerate(text.splitlines(1)): |
976
5d5ab159d197
hgweb: Changed file page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
975
diff
changeset
|
605 yield {"line": t, |
6122
800e2756c9ab
Add line anchors to annotate, changeset, diff, file views for hgweb
Edward Lee <edward.lee@engineering.uiuc.edu>
parents:
5336
diff
changeset
|
606 "lineid": "l%d" % (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
|
607 "linenumber": "% 6d" % (lineno + 1), |
4462
12e4d9524951
hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4458
diff
changeset
|
608 "parity": parity.next()} |
359 | 609 |
5889
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
610 return tmpl("filerevision", |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
611 file=f, |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
612 path=_up(f), |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
613 text=lines(), |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
614 rev=fctx.rev(), |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
615 node=hex(fctx.node()), |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
616 author=fctx.user(), |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
617 date=fctx.date(), |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
618 desc=fctx.description(), |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
619 branch=webutil.nodebranchnodefault(fctx), |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
620 parent=webutil.siblings(fctx.parents()), |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
621 child=webutil.siblings(fctx.children()), |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
622 rename=webutil.renamelink(fl, n), |
5889
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
623 permissions=fctx.manifest().flags(f)) |
138 | 624 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
625 def fileannotate(self, tmpl, fctx): |
3206
79fd7a92f3e2
hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents:
3205
diff
changeset
|
626 f = fctx.path() |
3173
3466bd7b9754
hgweb: use filectx.annotate instead of filelog
Brendan Cully <brendan@kublai.com>
parents:
3131
diff
changeset
|
627 n = fctx.filenode() |
3466bd7b9754
hgweb: use filectx.annotate instead of filelog
Brendan Cully <brendan@kublai.com>
parents:
3131
diff
changeset
|
628 fl = fctx.filelog() |
4462
12e4d9524951
hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4458
diff
changeset
|
629 parity = paritygen(self.stripecount) |
131 | 630 |
857
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
631 def annotate(**map): |
142 | 632 last = None |
6203
3a75fcc96dac
hgweb/annotate: handle binary files like hgweb/file
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6168
diff
changeset
|
633 if util.binary(fctx.data()): |
3a75fcc96dac
hgweb/annotate: handle binary files like hgweb/file
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6168
diff
changeset
|
634 mt = (mimetypes.guess_type(fctx.path())[0] |
3a75fcc96dac
hgweb/annotate: handle binary files like hgweb/file
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6168
diff
changeset
|
635 or 'application/octet-stream') |
3a75fcc96dac
hgweb/annotate: handle binary files like hgweb/file
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6168
diff
changeset
|
636 lines = enumerate([((fctx.filectx(fctx.filerev()), 1), |
3a75fcc96dac
hgweb/annotate: handle binary files like hgweb/file
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6168
diff
changeset
|
637 '(binary:%s)' % mt)]) |
3a75fcc96dac
hgweb/annotate: handle binary files like hgweb/file
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6168
diff
changeset
|
638 else: |
3a75fcc96dac
hgweb/annotate: handle binary files like hgweb/file
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6168
diff
changeset
|
639 lines = enumerate(fctx.annotate(follow=True, linenumber=True)) |
6125
74406f50bd46
Make hgweb annotate link to target line numbers (issue623)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6123
diff
changeset
|
640 for lineno, ((f, targetline), l) in lines: |
3175
fc379b91f602
hgweb: make annotate line revisions point to annotation for that rev
Brendan Cully <brendan@kublai.com>
parents:
3173
diff
changeset
|
641 fnode = f.filenode() |
3173
3466bd7b9754
hgweb: use filectx.annotate instead of filelog
Brendan Cully <brendan@kublai.com>
parents:
3131
diff
changeset
|
642 name = self.repo.ui.shortuser(f.user()) |
131 | 643 |
3175
fc379b91f602
hgweb: make annotate line revisions point to annotation for that rev
Brendan Cully <brendan@kublai.com>
parents:
3173
diff
changeset
|
644 if last != fnode: |
fc379b91f602
hgweb: make annotate line revisions point to annotation for that rev
Brendan Cully <brendan@kublai.com>
parents:
3173
diff
changeset
|
645 last = fnode |
142 | 646 |
4462
12e4d9524951
hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4458
diff
changeset
|
647 yield {"parity": parity.next(), |
3178
0d0d7317bbc8
hgweb: yield filenode as well as node in annotate, use filenode in annotateline
Brendan Cully <brendan@kublai.com>
parents:
3177
diff
changeset
|
648 "node": hex(f.node()), |
3403
372999405787
Back out d8eba1c3ce9b and a004164dbeef
Brendan Cully <brendan@kublai.com>
parents:
3402
diff
changeset
|
649 "rev": f.rev(), |
977
289975641886
hgweb: Changed annotate page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
976
diff
changeset
|
650 "author": name, |
3173
3466bd7b9754
hgweb: use filectx.annotate instead of filelog
Brendan Cully <brendan@kublai.com>
parents:
3131
diff
changeset
|
651 "file": f.path(), |
6125
74406f50bd46
Make hgweb annotate link to target line numbers (issue623)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6123
diff
changeset
|
652 "targetline": targetline, |
6122
800e2756c9ab
Add line anchors to annotate, changeset, diff, file views for hgweb
Edward Lee <edward.lee@engineering.uiuc.edu>
parents:
5336
diff
changeset
|
653 "line": l, |
800e2756c9ab
Add line anchors to annotate, changeset, diff, file views for hgweb
Edward Lee <edward.lee@engineering.uiuc.edu>
parents:
5336
diff
changeset
|
654 "lineid": "l%d" % (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
|
655 "linenumber": "% 6d" % (lineno + 1)} |
138 | 656 |
5889
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
657 return tmpl("fileannotate", |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
658 file=f, |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
659 annotate=annotate, |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
660 path=_up(f), |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
661 rev=fctx.rev(), |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
662 node=hex(fctx.node()), |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
663 author=fctx.user(), |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
664 date=fctx.date(), |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
665 desc=fctx.description(), |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
666 rename=webutil.renamelink(fl, n), |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
667 branch=webutil.nodebranchnodefault(fctx), |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
668 parent=webutil.siblings(fctx.parents()), |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
669 child=webutil.siblings(fctx.children()), |
5889
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
670 permissions=fctx.manifest().flags(f)) |
136 | 671 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
672 def manifest(self, tmpl, ctx, path): |
3205 | 673 mf = ctx.manifest() |
674 node = ctx.node() | |
138 | 675 |
676 files = {} | |
4462
12e4d9524951
hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4458
diff
changeset
|
677 parity = paritygen(self.stripecount) |
515 | 678 |
3595
fc34fd58ae7b
hgweb: fix handling of path for old style template
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3557
diff
changeset
|
679 if path and path[-1] != "/": |
fc34fd58ae7b
hgweb: fix handling of path for old style template
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3557
diff
changeset
|
680 path += "/" |
fc34fd58ae7b
hgweb: fix handling of path for old style template
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3557
diff
changeset
|
681 l = len(path) |
fc34fd58ae7b
hgweb: fix handling of path for old style template
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3557
diff
changeset
|
682 abspath = "/" + path |
131 | 683 |
3673
eb0b4a2d70a9
white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3612
diff
changeset
|
684 for f, n in mf.items(): |
3595
fc34fd58ae7b
hgweb: fix handling of path for old style template
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3557
diff
changeset
|
685 if f[:l] != path: |
138 | 686 continue |
687 remain = f[l:] | |
688 if "/" in remain: | |
2579
0875cda033fd
use __contains__, index or split instead of str.find
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2558
diff
changeset
|
689 short = remain[:remain.index("/") + 1] # bleah |
142 | 690 files[short] = (f, None) |
138 | 691 else: |
692 short = os.path.basename(remain) | |
693 files[short] = (f, n) | |
131 | 694 |
5561
22713dce19f6
hgweb: return meaningful HTTP status codes instead of nonsense
Bryan O'Sullivan <bos@serpentine.com>
parents:
5486
diff
changeset
|
695 if not files: |
6368
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6249
diff
changeset
|
696 raise ErrorResponse(HTTP_NOT_FOUND, 'path not found: ' + path) |
5561
22713dce19f6
hgweb: return meaningful HTTP status codes instead of nonsense
Bryan O'Sullivan <bos@serpentine.com>
parents:
5486
diff
changeset
|
697 |
857
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
698 def filelist(**map): |
138 | 699 fl = files.keys() |
700 fl.sort() | |
701 for f in fl: | |
702 full, fnode = files[f] | |
979
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
703 if not fnode: |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
704 continue |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
705 |
5273
6e0f05f6f68d
hgweb: Show date of last change for each file in manifest
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5269
diff
changeset
|
706 fctx = ctx.filectx(full) |
979
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
707 yield {"file": full, |
4462
12e4d9524951
hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4458
diff
changeset
|
708 "parity": parity.next(), |
979
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
709 "basename": f, |
5273
6e0f05f6f68d
hgweb: Show date of last change for each file in manifest
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5269
diff
changeset
|
710 "date": fctx.changectx().date(), |
6e0f05f6f68d
hgweb: Show date of last change for each file in manifest
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5269
diff
changeset
|
711 "size": fctx.size(), |
4745
e21a0e12ff10
hgweb: use lrwxrwxrwx as the permissions of a symlink
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4690
diff
changeset
|
712 "permissions": mf.flags(full)} |
138 | 713 |
979
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
714 def dirlist(**map): |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
715 fl = files.keys() |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
716 fl.sort() |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
717 for f in fl: |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
718 full, fnode = files[f] |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
719 if fnode: |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
720 continue |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
721 |
4462
12e4d9524951
hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4458
diff
changeset
|
722 yield {"parity": parity.next(), |
5064
ccdc8db02bdf
hgweb: don't use os.path.join to build URL parts
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4834
diff
changeset
|
723 "path": "%s%s" % (abspath, f), |
980 | 724 "basename": f[:-1]} |
982
8d2e24bae760
hgweb: convert index entries to list expansion style
mpm@selenic.com
parents:
981
diff
changeset
|
725 |
5889
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
726 return tmpl("manifest", |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
727 rev=ctx.rev(), |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
728 node=hex(node), |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
729 path=abspath, |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
730 up=_up(abspath), |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
731 upparity=parity.next(), |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
732 fentries=filelist, |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
733 dentries=dirlist, |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
734 archives=self.archivelist(hex(node)), |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
735 tags=webutil.nodetagsdict(self.repo, node), |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
736 inbranch=webutil.nodeinbranch(self.repo, ctx), |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
737 branches=webutil.nodebranchdict(self.repo, ctx)) |
131 | 738 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
739 def tags(self, tmpl): |
343 | 740 i = self.repo.tagslist() |
741 i.reverse() | |
4462
12e4d9524951
hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4458
diff
changeset
|
742 parity = paritygen(self.stripecount) |
168 | 743 |
5269
46c5e1ee8aaa
Added support for the Atom syndication format
Robert Bachmann <rbach@rbach.priv.at>
parents:
5123
diff
changeset
|
744 def entries(notip=False,limit=0, **map): |
46c5e1ee8aaa
Added support for the Atom syndication format
Robert Bachmann <rbach@rbach.priv.at>
parents:
5123
diff
changeset
|
745 count = 0 |
3673
eb0b4a2d70a9
white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3612
diff
changeset
|
746 for k, n in i: |
eb0b4a2d70a9
white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3612
diff
changeset
|
747 if notip and k == "tip": |
eb0b4a2d70a9
white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3612
diff
changeset
|
748 continue |
5269
46c5e1ee8aaa
Added support for the Atom syndication format
Robert Bachmann <rbach@rbach.priv.at>
parents:
5123
diff
changeset
|
749 if limit > 0 and count >= limit: |
46c5e1ee8aaa
Added support for the Atom syndication format
Robert Bachmann <rbach@rbach.priv.at>
parents:
5123
diff
changeset
|
750 continue |
46c5e1ee8aaa
Added support for the Atom syndication format
Robert Bachmann <rbach@rbach.priv.at>
parents:
5123
diff
changeset
|
751 count = count + 1 |
4462
12e4d9524951
hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4458
diff
changeset
|
752 yield {"parity": parity.next(), |
974
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
753 "tag": k, |
3973
b485a4459d96
hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3936
diff
changeset
|
754 "date": self.repo.changectx(n).date(), |
974
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
755 "node": hex(n)} |
168 | 756 |
5889
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
757 return tmpl("tags", |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
758 node=hex(self.repo.changelog.tip()), |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
759 entries=lambda **x: entries(False,0, **x), |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
760 entriesnotip=lambda **x: entries(True,0, **x), |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
761 latestentry=lambda **x: entries(True,1, **x)) |
168 | 762 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
763 def summary(self, tmpl): |
1572
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
764 i = self.repo.tagslist() |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
765 i.reverse() |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
766 |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
767 def tagentries(**map): |
4462
12e4d9524951
hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4458
diff
changeset
|
768 parity = paritygen(self.stripecount) |
1579
85803ec2daab
Remove tabs, and trailing whitespace from hgweb.py
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1575
diff
changeset
|
769 count = 0 |
3673
eb0b4a2d70a9
white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3612
diff
changeset
|
770 for k, n in i: |
1579
85803ec2daab
Remove tabs, and trailing whitespace from hgweb.py
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1575
diff
changeset
|
771 if k == "tip": # skip tip |
1572
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
772 continue; |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
773 |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
774 count += 1 |
1579
85803ec2daab
Remove tabs, and trailing whitespace from hgweb.py
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1575
diff
changeset
|
775 if count > 10: # limit to 10 tags |
1572
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
776 break; |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
777 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
778 yield tmpl("tagentry", |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
779 parity=parity.next(), |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
780 tag=k, |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
781 node=hex(n), |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
782 date=self.repo.changectx(n).date()) |
1579
85803ec2daab
Remove tabs, and trailing whitespace from hgweb.py
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1575
diff
changeset
|
783 |
4300
05d15c456fb2
hgweb: display named branches in gitweb-style summary page
greg@maptuit.com
parents:
4282
diff
changeset
|
784 |
05d15c456fb2
hgweb: display named branches in gitweb-style summary page
greg@maptuit.com
parents:
4282
diff
changeset
|
785 def branches(**map): |
4462
12e4d9524951
hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4458
diff
changeset
|
786 parity = paritygen(self.stripecount) |
3499
e0db0b7934f2
hgweb: add heads to gitweb summary
Brendan Cully <brendan@kublai.com>
parents:
3488
diff
changeset
|
787 |
4300
05d15c456fb2
hgweb: display named branches in gitweb-style summary page
greg@maptuit.com
parents:
4282
diff
changeset
|
788 b = self.repo.branchtags() |
05d15c456fb2
hgweb: display named branches in gitweb-style summary page
greg@maptuit.com
parents:
4282
diff
changeset
|
789 l = [(-self.repo.changelog.rev(n), n, t) for t, n in b.items()] |
05d15c456fb2
hgweb: display named branches in gitweb-style summary page
greg@maptuit.com
parents:
4282
diff
changeset
|
790 l.sort() |
3499
e0db0b7934f2
hgweb: add heads to gitweb summary
Brendan Cully <brendan@kublai.com>
parents:
3488
diff
changeset
|
791 |
4300
05d15c456fb2
hgweb: display named branches in gitweb-style summary page
greg@maptuit.com
parents:
4282
diff
changeset
|
792 for r,n,t in l: |
05d15c456fb2
hgweb: display named branches in gitweb-style summary page
greg@maptuit.com
parents:
4282
diff
changeset
|
793 ctx = self.repo.changectx(n) |
3499
e0db0b7934f2
hgweb: add heads to gitweb summary
Brendan Cully <brendan@kublai.com>
parents:
3488
diff
changeset
|
794 |
4462
12e4d9524951
hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4458
diff
changeset
|
795 yield {'parity': parity.next(), |
4300
05d15c456fb2
hgweb: display named branches in gitweb-style summary page
greg@maptuit.com
parents:
4282
diff
changeset
|
796 'branch': t, |
05d15c456fb2
hgweb: display named branches in gitweb-style summary page
greg@maptuit.com
parents:
4282
diff
changeset
|
797 'node': hex(n), |
3499
e0db0b7934f2
hgweb: add heads to gitweb summary
Brendan Cully <brendan@kublai.com>
parents:
3488
diff
changeset
|
798 'date': ctx.date()} |
e0db0b7934f2
hgweb: add heads to gitweb summary
Brendan Cully <brendan@kublai.com>
parents:
3488
diff
changeset
|
799 |
1572
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
800 def changelist(**map): |
4462
12e4d9524951
hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4458
diff
changeset
|
801 parity = paritygen(self.stripecount, offset=start-end) |
1572
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
802 l = [] # build a list in forward order for efficiency |
3473
0e68608bd11d
use xrange instead of range
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3445
diff
changeset
|
803 for i in xrange(start, end): |
3973
b485a4459d96
hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3936
diff
changeset
|
804 ctx = self.repo.changectx(i) |
4538
4272ae760bb1
gitweb: Display branch and tag labels
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
4469
diff
changeset
|
805 n = ctx.node() |
4272ae760bb1
gitweb: Display branch and tag labels
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
4469
diff
changeset
|
806 hn = hex(n) |
1572
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
807 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
808 l.insert(0, tmpl( |
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
809 'shortlogentry', |
4462
12e4d9524951
hgweb: use generator to count parity of horizontal stripes for easier reading.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4458
diff
changeset
|
810 parity=parity.next(), |
3973
b485a4459d96
hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3936
diff
changeset
|
811 author=ctx.user(), |
b485a4459d96
hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3936
diff
changeset
|
812 desc=ctx.description(), |
b485a4459d96
hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3936
diff
changeset
|
813 date=ctx.date(), |
b485a4459d96
hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3936
diff
changeset
|
814 rev=i, |
4538
4272ae760bb1
gitweb: Display branch and tag labels
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
4469
diff
changeset
|
815 node=hn, |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
816 tags=webutil.nodetagsdict(self.repo, n), |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
817 inbranch=webutil.nodeinbranch(self.repo, ctx), |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
818 branches=webutil.nodebranchdict(self.repo, ctx))) |
1572
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
819 |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
820 yield l |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
821 |
3973
b485a4459d96
hgweb: use contexts, fix coding style
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3936
diff
changeset
|
822 cl = self.repo.changelog |
1572
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
823 count = cl.count() |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
824 start = max(0, count - self.maxchanges) |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
825 end = min(count, start + self.maxchanges) |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
826 |
5889
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
827 return tmpl("summary", |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
828 desc=self.config("web", "description", "unknown"), |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
829 owner=get_contact(self.config) or "unknown", |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
830 lastchange=cl.read(cl.tip())[2], |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
831 tags=tagentries, |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
832 branches=branches, |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
833 shortlog=changelist, |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
834 node=hex(cl.tip()), |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
835 archives=self.archivelist("tip")) |
1579
85803ec2daab
Remove tabs, and trailing whitespace from hgweb.py
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1575
diff
changeset
|
836 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
837 def filediff(self, tmpl, fctx): |
3220
325278542ea8
hgweb: use contexts in more handlers
Brendan Cully <brendan@kublai.com>
parents:
3208
diff
changeset
|
838 n = fctx.node() |
325278542ea8
hgweb: use contexts in more handlers
Brendan Cully <brendan@kublai.com>
parents:
3208
diff
changeset
|
839 path = fctx.path() |
3406
970b2d6de3b3
hgweb: link to file parents in filediff, rather than changeset parents
Brendan Cully <brendan@kublai.com>
parents:
3403
diff
changeset
|
840 parents = fctx.parents() |
970b2d6de3b3
hgweb: link to file parents in filediff, rather than changeset parents
Brendan Cully <brendan@kublai.com>
parents:
3403
diff
changeset
|
841 p1 = parents and parents[0].node() or nullid |
515 | 842 |
857
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
843 def diff(**map): |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
844 yield self.diff(tmpl, p1, n, [path]) |
131 | 845 |
5889
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
846 return tmpl("filediff", |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
847 file=path, |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
848 node=hex(n), |
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
849 rev=fctx.rev(), |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
850 branch=webutil.nodebranchnodefault(fctx), |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
851 parent=webutil.siblings(parents), |
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6391
diff
changeset
|
852 child=webutil.siblings(fctx.children()), |
5889
209577095f20
hgweb: just return iterables instead of yielding them
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5886
diff
changeset
|
853 diff=diff) |
515 | 854 |
2113
633d733e7b11
make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2103
diff
changeset
|
855 archive_specs = { |
2361
d3adb454c5a9
Fix automatic decompression of tarballs with Firefox.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2359
diff
changeset
|
856 '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
|
857 '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
|
858 'zip': ('application/zip', 'zip', '.zip', None), |
633d733e7b11
make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2103
diff
changeset
|
859 } |
1076
01db658cc78a
tarball support v0.3
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1073
diff
changeset
|
860 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5599
diff
changeset
|
861 def archive(self, tmpl, req, key, type_): |
2113
633d733e7b11
make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2103
diff
changeset
|
862 reponame = re.sub(r"\W+", "-", os.path.basename(self.reponame)) |
4669
96e096fe9e86
hgweb_mod.archive(): Use 'key' instead of builtin 'id'.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4635
diff
changeset
|
863 cnode = self.repo.lookup(key) |
96e096fe9e86
hgweb_mod.archive(): Use 'key' instead of builtin 'id'.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4635
diff
changeset
|
864 arch_version = key |
96e096fe9e86
hgweb_mod.archive(): Use 'key' instead of builtin 'id'.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4635
diff
changeset
|
865 if cnode == key or key == 'tip': |
4164
5c1e18bb804c
hgweb: use the given revision in the name of the archive
Michael Gebetsroither <michael.geb@gmx.at>
parents:
4096
diff
changeset
|
866 arch_version = short(cnode) |
5c1e18bb804c
hgweb: use the given revision in the name of the archive
Michael Gebetsroither <michael.geb@gmx.at>
parents:
4096
diff
changeset
|
867 name = "%s-%s" % (reponame, arch_version) |
2394
a8f1049d1d2d
hgweb: fix errors and warnings found by pychecker
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2391
diff
changeset
|
868 mimetype, artype, extension, encoding = self.archive_specs[type_] |
5930
c301f15c965a
send conservatively capitalized HTTP headers
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5928
diff
changeset
|
869 headers = [ |
c301f15c965a
send conservatively capitalized HTTP headers
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5928
diff
changeset
|
870 ('Content-Type', mimetype), |
c301f15c965a
send conservatively capitalized HTTP headers
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5928
diff
changeset
|
871 ('Content-Disposition', 'attachment; filename=%s%s' % |
c301f15c965a
send conservatively capitalized HTTP headers
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5928
diff
changeset
|
872 (name, extension)) |
c301f15c965a
send conservatively capitalized HTTP headers
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5928
diff
changeset
|
873 ] |
2113
633d733e7b11
make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2103
diff
changeset
|
874 if encoding: |
5930
c301f15c965a
send conservatively capitalized HTTP headers
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5928
diff
changeset
|
875 headers.append(('Content-Encoding', encoding)) |
2113
633d733e7b11
make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2103
diff
changeset
|
876 req.header(headers) |
5993
948a41e77902
hgweb: explicit response status
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5976
diff
changeset
|
877 req.respond(HTTP_OK) |
5886
dd1998dd6f3b
hgweb: remove some legacy code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5833
diff
changeset
|
878 archival.archive(self.repo, req, cnode, artype, prefix=name) |
1076
01db658cc78a
tarball support v0.3
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1073
diff
changeset
|
879 |
2466
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
880 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
|
881 '''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
|
882 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
|
883 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
|
884 |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
885 user = req.env.get('REMOTE_USER') |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
886 |
3555
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
887 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
|
888 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
|
889 return False |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
890 |
3555
881064004fd0
use untrusted settings in hgweb
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
3499
diff
changeset
|
891 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
|
892 return (allow and (allow == ['*'] or user in allow)) or default |