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