Mercurial > hg
annotate mercurial/hgweb/webcommands.py @ 12280:6ee719f56f01
tests: remove exec bit from .t files
author | Sune Foldager <cryo@cyanite.org> |
---|---|
date | Tue, 14 Sep 2010 16:03:10 +0200 |
parents | 516b000fbb7e |
children | ead4e21f49f1 |
rev | line source |
---|---|
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
1 # |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
2 # Copyright 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net> |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
3 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
4 # |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8209
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
10263 | 6 # GNU General Public License version 2 or any later version. |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
7 |
7345
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7332
diff
changeset
|
8 import os, mimetypes, re, cgi, copy |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6368
diff
changeset
|
9 import webutil |
11332
716e176a4e01
hgweb: specify a charset when sending raw text files
Julian Cowley <julian@lava.net>
parents:
10394
diff
changeset
|
10 from mercurial import error, encoding, archival, templater, templatefilters |
7873
4a4c7f6a5912
cleanup: drop unused imports
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7671
diff
changeset
|
11 from mercurial.node import short, hex |
4a4c7f6a5912
cleanup: drop unused imports
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7671
diff
changeset
|
12 from mercurial.util import binary |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
13 from common import paritygen, staticfile, get_contact, ErrorResponse |
7029
b84d27386285
hgweb: Respond with HTTP 403 for disabled archive types instead of 404
Rocco Rutte <pdmef@gmx.net>
parents:
6981
diff
changeset
|
14 from common import HTTP_OK, HTTP_FORBIDDEN, HTTP_NOT_FOUND |
8390
beae42f3d93b
drop unused imports
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8354
diff
changeset
|
15 from mercurial import graphmod |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
16 |
5963
5be210afe1b8
hgweb: explicitly check if requested command exists
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5960
diff
changeset
|
17 # __all__ is populated with the allowed commands. Be sure to add to it if |
5be210afe1b8
hgweb: explicitly check if requested command exists
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5960
diff
changeset
|
18 # you're adding a new command, or the new command won't work. |
5be210afe1b8
hgweb: explicitly check if requested command exists
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5960
diff
changeset
|
19 |
5be210afe1b8
hgweb: explicitly check if requested command exists
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5960
diff
changeset
|
20 __all__ = [ |
5be210afe1b8
hgweb: explicitly check if requested command exists
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5960
diff
changeset
|
21 'log', 'rawfile', 'file', 'changelog', 'shortlog', 'changeset', 'rev', |
8352
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
22 'manifest', 'tags', 'branches', 'summary', 'filediff', 'diff', 'annotate', |
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
23 'filelog', 'archive', 'static', 'graph', |
5963
5be210afe1b8
hgweb: explicitly check if requested command exists
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5960
diff
changeset
|
24 ] |
5be210afe1b8
hgweb: explicitly check if requested command exists
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5960
diff
changeset
|
25 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
26 def log(web, req, tmpl): |
5915
d0576d065993
Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents:
5890
diff
changeset
|
27 if 'file' in req.form and req.form['file'][0]: |
5964
1cd1582ef25f
hgweb: centralize req.write() calls
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5963
diff
changeset
|
28 return filelog(web, req, tmpl) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
29 else: |
5964
1cd1582ef25f
hgweb: centralize req.write() calls
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5963
diff
changeset
|
30 return changelog(web, req, tmpl) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
31 |
5890
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
32 def rawfile(web, req, tmpl): |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6368
diff
changeset
|
33 path = webutil.cleanpath(web.repo, req.form.get('file', [''])[0]) |
5890
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
34 if not path: |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
35 content = manifest(web, req, tmpl) |
5993
948a41e77902
hgweb: explicit response status
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5964
diff
changeset
|
36 req.respond(HTTP_OK, web.ctype) |
948a41e77902
hgweb: explicit response status
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5964
diff
changeset
|
37 return content |
5890
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
38 |
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
39 try: |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6368
diff
changeset
|
40 fctx = webutil.filectx(web.repo, req) |
7633 | 41 except error.LookupError, inst: |
6368
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6217
diff
changeset
|
42 try: |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
43 content = manifest(web, req, tmpl) |
6368
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6217
diff
changeset
|
44 req.respond(HTTP_OK, web.ctype) |
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6217
diff
changeset
|
45 return content |
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6217
diff
changeset
|
46 except ErrorResponse: |
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6217
diff
changeset
|
47 raise inst |
5890
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
48 |
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
49 path = fctx.path() |
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
50 text = fctx.data() |
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
51 mt = mimetypes.guess_type(path)[0] |
6981
029a54423a96
hgweb: Serve raw non-binary files as text/plain
Rocco Rutte <pdmef@gmx.net>
parents:
6857
diff
changeset
|
52 if mt is None: |
029a54423a96
hgweb: Serve raw non-binary files as text/plain
Rocco Rutte <pdmef@gmx.net>
parents:
6857
diff
changeset
|
53 mt = binary(text) and 'application/octet-stream' or 'text/plain' |
11332
716e176a4e01
hgweb: specify a charset when sending raw text files
Julian Cowley <julian@lava.net>
parents:
10394
diff
changeset
|
54 if mt.startswith('text/'): |
716e176a4e01
hgweb: specify a charset when sending raw text files
Julian Cowley <julian@lava.net>
parents:
10394
diff
changeset
|
55 mt += '; charset="%s"' % encoding.encoding |
5890
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
56 |
5993
948a41e77902
hgweb: explicit response status
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5964
diff
changeset
|
57 req.respond(HTTP_OK, mt, path, len(text)) |
5964
1cd1582ef25f
hgweb: centralize req.write() calls
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5963
diff
changeset
|
58 return [text] |
5890
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
59 |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
60 def _filerevision(web, tmpl, fctx): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
61 f = fctx.path() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
62 text = fctx.data() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
63 parity = paritygen(web.stripecount) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
64 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
65 if binary(text): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
66 mt = mimetypes.guess_type(f)[0] or 'application/octet-stream' |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
67 text = '(binary:%s)' % mt |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
68 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
69 def lines(): |
9136
31177742f54a
for calls expecting bool args, pass bool instead of int
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8842
diff
changeset
|
70 for lineno, t in enumerate(text.splitlines(True)): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
71 yield {"line": t, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
72 "lineid": "l%d" % (lineno + 1), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
73 "linenumber": "% 6d" % (lineno + 1), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
74 "parity": parity.next()} |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
75 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
76 return tmpl("filerevision", |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
77 file=f, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
78 path=webutil.up(f), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
79 text=lines(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
80 rev=fctx.rev(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
81 node=hex(fctx.node()), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
82 author=fctx.user(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
83 date=fctx.date(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
84 desc=fctx.description(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
85 branch=webutil.nodebranchnodefault(fctx), |
7671
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
86 parent=webutil.parents(fctx), |
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
87 child=webutil.children(fctx), |
6434
62e0bb41e682
hgweb: minor improvements for new web style
Matt Mackall <mpm@selenic.com>
parents:
6410
diff
changeset
|
88 rename=webutil.renamelink(fctx), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
89 permissions=fctx.manifest().flags(f)) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
90 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
91 def file(web, req, tmpl): |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6368
diff
changeset
|
92 path = webutil.cleanpath(web.repo, req.form.get('file', [''])[0]) |
6853
2ff0829bdae5
hgweb: do not use unassigned variables in exception handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6669
diff
changeset
|
93 if not path: |
6857 | 94 return manifest(web, req, tmpl) |
6853
2ff0829bdae5
hgweb: do not use unassigned variables in exception handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6669
diff
changeset
|
95 try: |
6857 | 96 return _filerevision(web, tmpl, webutil.filectx(web.repo, req)) |
7633 | 97 except error.LookupError, inst: |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
98 try: |
6857 | 99 return manifest(web, req, tmpl) |
6853
2ff0829bdae5
hgweb: do not use unassigned variables in exception handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6669
diff
changeset
|
100 except ErrorResponse: |
2ff0829bdae5
hgweb: do not use unassigned variables in exception handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6669
diff
changeset
|
101 raise inst |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
102 |
10247
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
103 def _search(web, req, tmpl): |
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
104 |
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
105 query = req.form['rev'][0] |
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
106 revcount = web.maxchanges |
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
107 if 'revcount' in req.form: |
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
108 revcount = int(req.form.get('revcount', [revcount])[0]) |
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
109 tmpl.defaults['sessionvars']['revcount'] = revcount |
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
110 |
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
111 lessvars = copy.copy(tmpl.defaults['sessionvars']) |
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
112 lessvars['revcount'] = revcount / 2 |
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
113 lessvars['rev'] = query |
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
114 morevars = copy.copy(tmpl.defaults['sessionvars']) |
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
115 morevars['revcount'] = revcount * 2 |
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
116 morevars['rev'] = query |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
117 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
118 def changelist(**map): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
119 count = 0 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
120 qw = query.lower().split() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
121 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
122 def revgen(): |
12059
0de6cfdcaad8
webcommands: remove unncessary access to repo.changelog
Patrick Mezard <pmezard@gmail.com>
parents:
11332
diff
changeset
|
123 for i in xrange(len(web.repo) - 1, 0, -100): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
124 l = [] |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
125 for j in xrange(max(0, i - 100), i + 1): |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6720
diff
changeset
|
126 ctx = web.repo[j] |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
127 l.append(ctx) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
128 l.reverse() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
129 for e in l: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
130 yield e |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
131 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
132 for ctx in revgen(): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
133 miss = 0 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
134 for q in qw: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
135 if not (q in ctx.user().lower() or |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
136 q in ctx.description().lower() or |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
137 q in " ".join(ctx.files()).lower()): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
138 miss = 1 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
139 break |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
140 if miss: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
141 continue |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
142 |
6659
bc553c6d1ef9
webcommands: fix increments lost by 894875eae49b
Andrew Beekhof <beekhof@gmail.com>
parents:
6657
diff
changeset
|
143 count += 1 |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
144 n = ctx.node() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
145 showtags = webutil.showtag(web.repo, tmpl, 'changelogtag', n) |
7311
de9c87fe1620
hgweb: move another utility function into the webutil module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7310
diff
changeset
|
146 files = webutil.listfilediffs(tmpl, ctx.files(), n, web.maxfiles) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
147 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
148 yield tmpl('searchentry', |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
149 parity=parity.next(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
150 author=ctx.user(), |
7671
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
151 parent=webutil.parents(ctx), |
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
152 child=webutil.children(ctx), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
153 changelogtag=showtags, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
154 desc=ctx.description(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
155 date=ctx.date(), |
7311
de9c87fe1620
hgweb: move another utility function into the webutil module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7310
diff
changeset
|
156 files=files, |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
157 rev=ctx.rev(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
158 node=hex(n), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
159 tags=webutil.nodetagsdict(web.repo, n), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
160 inbranch=webutil.nodeinbranch(web.repo, ctx), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
161 branches=webutil.nodebranchdict(web.repo, ctx)) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
162 |
10247
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
163 if count >= revcount: |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
164 break |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
165 |
12059
0de6cfdcaad8
webcommands: remove unncessary access to repo.changelog
Patrick Mezard <pmezard@gmail.com>
parents:
11332
diff
changeset
|
166 tip = web.repo['tip'] |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
167 parity = paritygen(web.stripecount) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
168 |
12059
0de6cfdcaad8
webcommands: remove unncessary access to repo.changelog
Patrick Mezard <pmezard@gmail.com>
parents:
11332
diff
changeset
|
169 return tmpl('search', query=query, node=tip.hex(), |
10247
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
170 entries=changelist, archives=web.archivelist("tip"), |
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
171 morevars=morevars, lessvars=lessvars) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
172 |
10247
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
173 def changelog(web, req, tmpl, shortlog=False): |
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
174 |
5915
d0576d065993
Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents:
5890
diff
changeset
|
175 if 'node' in req.form: |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6368
diff
changeset
|
176 ctx = webutil.changectx(web.repo, req) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
177 else: |
5915
d0576d065993
Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents:
5890
diff
changeset
|
178 if 'rev' in req.form: |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
179 hi = req.form['rev'][0] |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
180 else: |
6750
fb42030d79d6
add __len__ and __iter__ methods to repo and revlog
Matt Mackall <mpm@selenic.com>
parents:
6747
diff
changeset
|
181 hi = len(web.repo) - 1 |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
182 try: |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6720
diff
changeset
|
183 ctx = web.repo[hi] |
7637 | 184 except error.RepoError: |
10247
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
185 return _search(web, req, tmpl) # XXX redirect to 404 page? |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
186 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
187 def changelist(limit=0, **map): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
188 l = [] # build a list in forward order for efficiency |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
189 for i in xrange(start, end): |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6720
diff
changeset
|
190 ctx = web.repo[i] |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
191 n = ctx.node() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
192 showtags = webutil.showtag(web.repo, tmpl, 'changelogtag', n) |
7311
de9c87fe1620
hgweb: move another utility function into the webutil module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7310
diff
changeset
|
193 files = webutil.listfilediffs(tmpl, ctx.files(), n, web.maxfiles) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
194 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
195 l.insert(0, {"parity": parity.next(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
196 "author": ctx.user(), |
7671
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
197 "parent": webutil.parents(ctx, i - 1), |
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
198 "child": webutil.children(ctx, i + 1), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
199 "changelogtag": showtags, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
200 "desc": ctx.description(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
201 "date": ctx.date(), |
7311
de9c87fe1620
hgweb: move another utility function into the webutil module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7310
diff
changeset
|
202 "files": files, |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
203 "rev": i, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
204 "node": hex(n), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
205 "tags": webutil.nodetagsdict(web.repo, n), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
206 "inbranch": webutil.nodeinbranch(web.repo, ctx), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
207 "branches": webutil.nodebranchdict(web.repo, ctx) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
208 }) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
209 |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
210 if limit > 0: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
211 l = l[:limit] |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
212 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
213 for e in l: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
214 yield e |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
215 |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
216 revcount = shortlog and web.maxshortchanges or web.maxchanges |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
217 if 'revcount' in req.form: |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
218 revcount = int(req.form.get('revcount', [revcount])[0]) |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
219 tmpl.defaults['sessionvars']['revcount'] = revcount |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
220 |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
221 lessvars = copy.copy(tmpl.defaults['sessionvars']) |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
222 lessvars['revcount'] = revcount / 2 |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
223 morevars = copy.copy(tmpl.defaults['sessionvars']) |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
224 morevars['revcount'] = revcount * 2 |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
225 |
12059
0de6cfdcaad8
webcommands: remove unncessary access to repo.changelog
Patrick Mezard <pmezard@gmail.com>
parents:
11332
diff
changeset
|
226 count = len(web.repo) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
227 pos = ctx.rev() |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
228 start = max(0, pos - revcount + 1) |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
229 end = min(count, start + revcount) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
230 pos = end - 1 |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
231 parity = paritygen(web.stripecount, offset=start - end) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
232 |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
233 changenav = webutil.revnavgen(pos, revcount, count, web.repo.changectx) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
234 |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
235 return tmpl(shortlog and 'shortlog' or 'changelog', changenav=changenav, |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
236 node=hex(ctx.node()), rev=pos, changesets=count, |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
237 entries=lambda **x: changelist(limit=0,**x), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
238 latestentry=lambda **x: changelist(limit=1,**x), |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
239 archives=web.archivelist("tip"), revcount=revcount, |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
240 morevars=morevars, lessvars=lessvars) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
241 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
242 def shortlog(web, req, tmpl): |
5964
1cd1582ef25f
hgweb: centralize req.write() calls
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5963
diff
changeset
|
243 return changelog(web, req, tmpl, shortlog = True) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
244 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
245 def changeset(web, req, tmpl): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
246 ctx = webutil.changectx(web.repo, req) |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7305
diff
changeset
|
247 showtags = webutil.showtag(web.repo, tmpl, 'changesettag', ctx.node()) |
7410
f1111704061e
coal/paper: show branch name in changeset view
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7409
diff
changeset
|
248 showbranch = webutil.nodebranchnodefault(ctx) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
249 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
250 files = [] |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
251 parity = paritygen(web.stripecount) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
252 for f in ctx.files(): |
7182
295af5bc1bcc
hgweb: remove links to non-existent file versions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7107
diff
changeset
|
253 template = f in ctx and 'filenodelink' or 'filenolink' |
295af5bc1bcc
hgweb: remove links to non-existent file versions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7107
diff
changeset
|
254 files.append(tmpl(template, |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7305
diff
changeset
|
255 node=ctx.hex(), file=f, |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
256 parity=parity.next())) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
257 |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7305
diff
changeset
|
258 parity = paritygen(web.stripecount) |
9402
5d49fdef6fd0
hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8842
diff
changeset
|
259 style = web.config('web', 'style', 'paper') |
5d49fdef6fd0
hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8842
diff
changeset
|
260 if 'style' in req.form: |
5d49fdef6fd0
hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8842
diff
changeset
|
261 style = req.form['style'][0] |
5d49fdef6fd0
hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8842
diff
changeset
|
262 |
5d49fdef6fd0
hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8842
diff
changeset
|
263 diffs = webutil.diffs(web.repo, tmpl, ctx, None, parity, style) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
264 return tmpl('changeset', |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
265 diff=diffs, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
266 rev=ctx.rev(), |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7305
diff
changeset
|
267 node=ctx.hex(), |
7671
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
268 parent=webutil.parents(ctx), |
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
269 child=webutil.children(ctx), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
270 changesettag=showtags, |
7410
f1111704061e
coal/paper: show branch name in changeset view
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7409
diff
changeset
|
271 changesetbranch=showbranch, |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
272 author=ctx.user(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
273 desc=ctx.description(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
274 date=ctx.date(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
275 files=files, |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7305
diff
changeset
|
276 archives=web.archivelist(ctx.hex()), |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7305
diff
changeset
|
277 tags=webutil.nodetagsdict(web.repo, ctx.node()), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
278 branch=webutil.nodebranchnodefault(ctx), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
279 inbranch=webutil.nodeinbranch(web.repo, ctx), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
280 branches=webutil.nodebranchdict(web.repo, ctx)) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
281 |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
282 rev = changeset |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
283 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
284 def manifest(web, req, tmpl): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
285 ctx = webutil.changectx(web.repo, req) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
286 path = webutil.cleanpath(web.repo, req.form.get('file', [''])[0]) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
287 mf = ctx.manifest() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
288 node = ctx.node() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
289 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
290 files = {} |
7305
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
291 dirs = {} |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
292 parity = paritygen(web.stripecount) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
293 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
294 if path and path[-1] != "/": |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
295 path += "/" |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
296 l = len(path) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
297 abspath = "/" + path |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
298 |
7622
4dd7b28003d2
use dict.iteritems() rather than dict.items()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7612
diff
changeset
|
299 for f, n in mf.iteritems(): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
300 if f[:l] != path: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
301 continue |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
302 remain = f[l:] |
7305
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
303 elements = remain.split('/') |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
304 if len(elements) == 1: |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
305 files[remain] = f |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
306 else: |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
307 h = dirs # need to retain ref to dirs (root) |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
308 for elem in elements[0:-1]: |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
309 if elem not in h: |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
310 h[elem] = {} |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
311 h = h[elem] |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
312 if len(h) > 1: |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
313 break |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
314 h[None] = None # denotes files present |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
315 |
7565
5f162f61e479
hgweb: fix problems with empty repositories
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7434
diff
changeset
|
316 if mf and not files and not dirs: |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
317 raise ErrorResponse(HTTP_NOT_FOUND, 'path not found: ' + path) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
318 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
319 def filelist(**map): |
8209
a1a5a57efe90
replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents:
7966
diff
changeset
|
320 for f in sorted(files): |
7305
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
321 full = files[f] |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
322 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
323 fctx = ctx.filectx(full) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
324 yield {"file": full, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
325 "parity": parity.next(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
326 "basename": f, |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6720
diff
changeset
|
327 "date": fctx.date(), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
328 "size": fctx.size(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
329 "permissions": mf.flags(full)} |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
330 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
331 def dirlist(**map): |
8209
a1a5a57efe90
replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents:
7966
diff
changeset
|
332 for d in sorted(dirs): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
333 |
7305
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
334 emptydirs = [] |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
335 h = dirs[d] |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
336 while isinstance(h, dict) and len(h) == 1: |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
337 k, v = h.items()[0] |
7305
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
338 if v: |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
339 emptydirs.append(k) |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
340 h = v |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
341 |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
342 path = "%s%s" % (abspath, d) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
343 yield {"parity": parity.next(), |
7305
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
344 "path": path, |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
345 "emptydirs": "/".join(emptydirs), |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
346 "basename": d} |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
347 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
348 return tmpl("manifest", |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
349 rev=ctx.rev(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
350 node=hex(node), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
351 path=abspath, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
352 up=webutil.up(abspath), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
353 upparity=parity.next(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
354 fentries=filelist, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
355 dentries=dirlist, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
356 archives=web.archivelist(hex(node)), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
357 tags=webutil.nodetagsdict(web.repo, node), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
358 inbranch=webutil.nodeinbranch(web.repo, ctx), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
359 branches=webutil.nodebranchdict(web.repo, ctx)) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
360 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
361 def tags(web, req, tmpl): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
362 i = web.repo.tagslist() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
363 i.reverse() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
364 parity = paritygen(web.stripecount) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
365 |
9198
061eeb602354
coding style: use a space after comma
Martin Geisler <mg@lazybytes.net>
parents:
9136
diff
changeset
|
366 def entries(notip=False, limit=0, **map): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
367 count = 0 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
368 for k, n in i: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
369 if notip and k == "tip": |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
370 continue |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
371 if limit > 0 and count >= limit: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
372 continue |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
373 count = count + 1 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
374 yield {"parity": parity.next(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
375 "tag": k, |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6720
diff
changeset
|
376 "date": web.repo[n].date(), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
377 "node": hex(n)} |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
378 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
379 return tmpl("tags", |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
380 node=hex(web.repo.changelog.tip()), |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
381 entries=lambda **x: entries(False, 0, **x), |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
382 entriesnotip=lambda **x: entries(True, 0, **x), |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
383 latestentry=lambda **x: entries(True, 1, **x)) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
384 |
8352
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
385 def branches(web, req, tmpl): |
8354
418ea63f00fb
hgweb: use context api in branches webcommand
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8352
diff
changeset
|
386 tips = (web.repo[n] for t, n in web.repo.branchtags().iteritems()) |
8796
2bcef677a6c3
localrepo: remove 'closed' argument to heads(...) function
John Mulligan <phlogistonjohn@asynchrono.us>
parents:
8713
diff
changeset
|
387 heads = web.repo.heads() |
8352
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
388 parity = paritygen(web.stripecount) |
8713
de6bb29e208a
hgweb: allow distinction between open/closed branches on branches page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8390
diff
changeset
|
389 sortkey = lambda ctx: ('close' not in ctx.extra(), ctx.rev()) |
8352
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
390 |
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
391 def entries(limit, **map): |
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
392 count = 0 |
8713
de6bb29e208a
hgweb: allow distinction between open/closed branches on branches page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8390
diff
changeset
|
393 for ctx in sorted(tips, key=sortkey, reverse=True): |
8352
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
394 if limit > 0 and count >= limit: |
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
395 return |
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
396 count += 1 |
8796
2bcef677a6c3
localrepo: remove 'closed' argument to heads(...) function
John Mulligan <phlogistonjohn@asynchrono.us>
parents:
8713
diff
changeset
|
397 if ctx.node() not in heads: |
2bcef677a6c3
localrepo: remove 'closed' argument to heads(...) function
John Mulligan <phlogistonjohn@asynchrono.us>
parents:
8713
diff
changeset
|
398 status = 'inactive' |
2bcef677a6c3
localrepo: remove 'closed' argument to heads(...) function
John Mulligan <phlogistonjohn@asynchrono.us>
parents:
8713
diff
changeset
|
399 elif not web.repo.branchheads(ctx.branch()): |
2bcef677a6c3
localrepo: remove 'closed' argument to heads(...) function
John Mulligan <phlogistonjohn@asynchrono.us>
parents:
8713
diff
changeset
|
400 status = 'closed' |
2bcef677a6c3
localrepo: remove 'closed' argument to heads(...) function
John Mulligan <phlogistonjohn@asynchrono.us>
parents:
8713
diff
changeset
|
401 else: |
2bcef677a6c3
localrepo: remove 'closed' argument to heads(...) function
John Mulligan <phlogistonjohn@asynchrono.us>
parents:
8713
diff
changeset
|
402 status = 'open' |
8352
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
403 yield {'parity': parity.next(), |
8354
418ea63f00fb
hgweb: use context api in branches webcommand
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8352
diff
changeset
|
404 'branch': ctx.branch(), |
8713
de6bb29e208a
hgweb: allow distinction between open/closed branches on branches page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8390
diff
changeset
|
405 'status': status, |
8354
418ea63f00fb
hgweb: use context api in branches webcommand
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8352
diff
changeset
|
406 'node': ctx.hex(), |
418ea63f00fb
hgweb: use context api in branches webcommand
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8352
diff
changeset
|
407 'date': ctx.date()} |
8352
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
408 |
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
409 return tmpl('branches', node=hex(web.repo.changelog.tip()), |
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
410 entries=lambda **x: entries(0, **x), |
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
411 latestentry=lambda **x: entries(1, **x)) |
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
412 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
413 def summary(web, req, tmpl): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
414 i = web.repo.tagslist() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
415 i.reverse() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
416 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
417 def tagentries(**map): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
418 parity = paritygen(web.stripecount) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
419 count = 0 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
420 for k, n in i: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
421 if k == "tip": # skip tip |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
422 continue |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
423 |
6659
bc553c6d1ef9
webcommands: fix increments lost by 894875eae49b
Andrew Beekhof <beekhof@gmail.com>
parents:
6657
diff
changeset
|
424 count += 1 |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
425 if count > 10: # limit to 10 tags |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
426 break |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
427 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
428 yield tmpl("tagentry", |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
429 parity=parity.next(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
430 tag=k, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
431 node=hex(n), |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6720
diff
changeset
|
432 date=web.repo[n].date()) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
433 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
434 def branches(**map): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
435 parity = paritygen(web.stripecount) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
436 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
437 b = web.repo.branchtags() |
7622
4dd7b28003d2
use dict.iteritems() rather than dict.items()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7612
diff
changeset
|
438 l = [(-web.repo.changelog.rev(n), n, t) for t, n in b.iteritems()] |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
439 for r, n, t in sorted(l): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
440 yield {'parity': parity.next(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
441 'branch': t, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
442 'node': hex(n), |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6720
diff
changeset
|
443 'date': web.repo[n].date()} |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
444 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
445 def changelist(**map): |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
446 parity = paritygen(web.stripecount, offset=start - end) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
447 l = [] # build a list in forward order for efficiency |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
448 for i in xrange(start, end): |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6720
diff
changeset
|
449 ctx = web.repo[i] |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
450 n = ctx.node() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
451 hn = hex(n) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
452 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
453 l.insert(0, tmpl( |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
454 'shortlogentry', |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
455 parity=parity.next(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
456 author=ctx.user(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
457 desc=ctx.description(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
458 date=ctx.date(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
459 rev=i, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
460 node=hn, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
461 tags=webutil.nodetagsdict(web.repo, n), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
462 inbranch=webutil.nodeinbranch(web.repo, ctx), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
463 branches=webutil.nodebranchdict(web.repo, ctx))) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
464 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
465 yield l |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
466 |
12059
0de6cfdcaad8
webcommands: remove unncessary access to repo.changelog
Patrick Mezard <pmezard@gmail.com>
parents:
11332
diff
changeset
|
467 tip = web.repo['tip'] |
0de6cfdcaad8
webcommands: remove unncessary access to repo.changelog
Patrick Mezard <pmezard@gmail.com>
parents:
11332
diff
changeset
|
468 count = len(web.repo) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
469 start = max(0, count - web.maxchanges) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
470 end = min(count, start + web.maxchanges) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
471 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
472 return tmpl("summary", |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
473 desc=web.config("web", "description", "unknown"), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
474 owner=get_contact(web.config) or "unknown", |
12059
0de6cfdcaad8
webcommands: remove unncessary access to repo.changelog
Patrick Mezard <pmezard@gmail.com>
parents:
11332
diff
changeset
|
475 lastchange=tip.date(), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
476 tags=tagentries, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
477 branches=branches, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
478 shortlog=changelist, |
12059
0de6cfdcaad8
webcommands: remove unncessary access to repo.changelog
Patrick Mezard <pmezard@gmail.com>
parents:
11332
diff
changeset
|
479 node=tip.hex(), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
480 archives=web.archivelist("tip")) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
481 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
482 def filediff(web, req, tmpl): |
7183
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
483 fctx, ctx = None, None |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
484 try: |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
485 fctx = webutil.filectx(web.repo, req) |
7280
810ca383da9c
remove unused variables
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7183
diff
changeset
|
486 except LookupError: |
7183
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
487 ctx = webutil.changectx(web.repo, req) |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
488 path = webutil.cleanpath(web.repo, req.form['file'][0]) |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
489 if path not in ctx.files(): |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
490 raise |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
491 |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
492 if fctx is not None: |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
493 n = fctx.node() |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
494 path = fctx.path() |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
495 else: |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
496 n = ctx.node() |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
497 # path already defined in except clause |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
498 |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7305
diff
changeset
|
499 parity = paritygen(web.stripecount) |
9402
5d49fdef6fd0
hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8842
diff
changeset
|
500 style = web.config('web', 'style', 'paper') |
5d49fdef6fd0
hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8842
diff
changeset
|
501 if 'style' in req.form: |
5d49fdef6fd0
hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8842
diff
changeset
|
502 style = req.form['style'][0] |
5d49fdef6fd0
hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8842
diff
changeset
|
503 |
5d49fdef6fd0
hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8842
diff
changeset
|
504 diffs = webutil.diffs(web.repo, tmpl, fctx or ctx, [path], parity, style) |
7183
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
505 rename = fctx and webutil.renamelink(fctx) or [] |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
506 ctx = fctx and fctx or ctx |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
507 return tmpl("filediff", |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
508 file=path, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
509 node=hex(n), |
7183
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
510 rev=ctx.rev(), |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
511 date=ctx.date(), |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
512 desc=ctx.description(), |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
513 author=ctx.user(), |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
514 rename=rename, |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
515 branch=webutil.nodebranchnodefault(ctx), |
7671
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
516 parent=webutil.parents(ctx), |
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
517 child=webutil.children(ctx), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
518 diff=diffs) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
519 |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
520 diff = filediff |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
521 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
522 def annotate(web, req, tmpl): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
523 fctx = webutil.filectx(web.repo, req) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
524 f = fctx.path() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
525 parity = paritygen(web.stripecount) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
526 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
527 def annotate(**map): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
528 last = None |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
529 if binary(fctx.data()): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
530 mt = (mimetypes.guess_type(fctx.path())[0] |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
531 or 'application/octet-stream') |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
532 lines = enumerate([((fctx.filectx(fctx.filerev()), 1), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
533 '(binary:%s)' % mt)]) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
534 else: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
535 lines = enumerate(fctx.annotate(follow=True, linenumber=True)) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
536 for lineno, ((f, targetline), l) in lines: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
537 fnode = f.filenode() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
538 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
539 if last != fnode: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
540 last = fnode |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
541 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
542 yield {"parity": parity.next(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
543 "node": hex(f.node()), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
544 "rev": f.rev(), |
6564
ccc2481e3954
webcommands: pass full author to annotate, fix templates (issue 1054)
Patrick Mezard <pmezard@gmail.com>
parents:
6437
diff
changeset
|
545 "author": f.user(), |
6657
a51093361e1c
hgweb: show cset node and description when hovering over annotate prefix
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6564
diff
changeset
|
546 "desc": f.description(), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
547 "file": f.path(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
548 "targetline": targetline, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
549 "line": l, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
550 "lineid": "l%d" % (lineno + 1), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
551 "linenumber": "% 6d" % (lineno + 1)} |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
552 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
553 return tmpl("fileannotate", |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
554 file=f, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
555 annotate=annotate, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
556 path=webutil.up(f), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
557 rev=fctx.rev(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
558 node=hex(fctx.node()), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
559 author=fctx.user(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
560 date=fctx.date(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
561 desc=fctx.description(), |
6434
62e0bb41e682
hgweb: minor improvements for new web style
Matt Mackall <mpm@selenic.com>
parents:
6410
diff
changeset
|
562 rename=webutil.renamelink(fctx), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
563 branch=webutil.nodebranchnodefault(fctx), |
7671
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
564 parent=webutil.parents(fctx), |
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
565 child=webutil.children(fctx), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
566 permissions=fctx.manifest().flags(f)) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
567 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
568 def filelog(web, req, tmpl): |
7300
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
569 |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
570 try: |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
571 fctx = webutil.filectx(web.repo, req) |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
572 f = fctx.path() |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
573 fl = fctx.filelog() |
7633 | 574 except error.LookupError: |
7300
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
575 f = webutil.cleanpath(web.repo, req.form['file'][0]) |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
576 fl = web.repo.file(f) |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
577 numrevs = len(fl) |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
578 if not numrevs: # file doesn't exist at all |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
579 raise |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
580 rev = webutil.changectx(web.repo, req).rev() |
7361
9fe97eea5510
linkrev: take a revision number rather than a hash
Matt Mackall <mpm@selenic.com>
parents:
7345
diff
changeset
|
581 first = fl.linkrev(0) |
7300
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
582 if rev < first: # current rev is from before file existed |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
583 raise |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
584 frev = numrevs - 1 |
7361
9fe97eea5510
linkrev: take a revision number rather than a hash
Matt Mackall <mpm@selenic.com>
parents:
7345
diff
changeset
|
585 while fl.linkrev(frev) > rev: |
7300
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
586 frev -= 1 |
7361
9fe97eea5510
linkrev: take a revision number rather than a hash
Matt Mackall <mpm@selenic.com>
parents:
7345
diff
changeset
|
587 fctx = web.repo.filectx(f, fl.linkrev(frev)) |
7300
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
588 |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
589 revcount = web.maxshortchanges |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
590 if 'revcount' in req.form: |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
591 revcount = int(req.form.get('revcount', [revcount])[0]) |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
592 tmpl.defaults['sessionvars']['revcount'] = revcount |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
593 |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
594 lessvars = copy.copy(tmpl.defaults['sessionvars']) |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
595 lessvars['revcount'] = revcount / 2 |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
596 morevars = copy.copy(tmpl.defaults['sessionvars']) |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
597 morevars['revcount'] = revcount * 2 |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
598 |
7300
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
599 count = fctx.filerev() + 1 |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
600 start = max(0, fctx.filerev() - revcount + 1) # first rev on this page |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
601 end = min(count, start + revcount) # last rev on this page |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
602 parity = paritygen(web.stripecount, offset=start - end) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
603 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
604 def entries(limit=0, **map): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
605 l = [] |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
606 |
7612
069b29656401
web: use the correct filectx in filelog
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7565
diff
changeset
|
607 repo = web.repo |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
608 for i in xrange(start, end): |
7612
069b29656401
web: use the correct filectx in filelog
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7565
diff
changeset
|
609 iterfctx = fctx.filectx(i) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
610 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
611 l.insert(0, {"parity": parity.next(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
612 "filerev": i, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
613 "file": f, |
7612
069b29656401
web: use the correct filectx in filelog
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7565
diff
changeset
|
614 "node": hex(iterfctx.node()), |
069b29656401
web: use the correct filectx in filelog
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7565
diff
changeset
|
615 "author": iterfctx.user(), |
069b29656401
web: use the correct filectx in filelog
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7565
diff
changeset
|
616 "date": iterfctx.date(), |
069b29656401
web: use the correct filectx in filelog
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7565
diff
changeset
|
617 "rename": webutil.renamelink(iterfctx), |
7671
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
618 "parent": webutil.parents(iterfctx), |
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
619 "child": webutil.children(iterfctx), |
7612
069b29656401
web: use the correct filectx in filelog
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7565
diff
changeset
|
620 "desc": iterfctx.description(), |
069b29656401
web: use the correct filectx in filelog
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7565
diff
changeset
|
621 "tags": webutil.nodetagsdict(repo, iterfctx.node()), |
069b29656401
web: use the correct filectx in filelog
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7565
diff
changeset
|
622 "branch": webutil.nodebranchnodefault(iterfctx), |
069b29656401
web: use the correct filectx in filelog
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7565
diff
changeset
|
623 "inbranch": webutil.nodeinbranch(repo, iterfctx), |
069b29656401
web: use the correct filectx in filelog
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7565
diff
changeset
|
624 "branches": webutil.nodebranchdict(repo, iterfctx)}) |
7434
cf7741aa1e96
kill some trailing spaces
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7410
diff
changeset
|
625 |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
626 if limit > 0: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
627 l = l[:limit] |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
628 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
629 for e in l: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
630 yield e |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
631 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
632 nodefunc = lambda x: fctx.filectx(fileid=x) |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
633 nav = webutil.revnavgen(end - 1, revcount, count, nodefunc) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
634 return tmpl("filelog", file=f, node=hex(fctx.node()), nav=nav, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
635 entries=lambda **x: entries(limit=0, **x), |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
636 latestentry=lambda **x: entries(limit=1, **x), |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
637 revcount=revcount, morevars=morevars, lessvars=lessvars) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
638 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
639 def archive(web, req, tmpl): |
6669
782dbbdfb1d7
fix traceback in hgweb when URL doesn't end in one of the archive specs
Ali Saidi <saidi@eecs.umich.edu>
parents:
6368
diff
changeset
|
640 type_ = req.form.get('type', [None])[0] |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
641 allowed = web.configlist("web", "allow_archive") |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
642 key = req.form['node'][0] |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
643 |
7029
b84d27386285
hgweb: Respond with HTTP 403 for disabled archive types instead of 404
Rocco Rutte <pdmef@gmx.net>
parents:
6981
diff
changeset
|
644 if type_ not in web.archives: |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
645 msg = 'Unsupported archive type: %s' % type_ |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
646 raise ErrorResponse(HTTP_NOT_FOUND, msg) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
647 |
7029
b84d27386285
hgweb: Respond with HTTP 403 for disabled archive types instead of 404
Rocco Rutte <pdmef@gmx.net>
parents:
6981
diff
changeset
|
648 if not ((type_ in allowed or |
b84d27386285
hgweb: Respond with HTTP 403 for disabled archive types instead of 404
Rocco Rutte <pdmef@gmx.net>
parents:
6981
diff
changeset
|
649 web.configbool("web", "allow" + type_, False))): |
b84d27386285
hgweb: Respond with HTTP 403 for disabled archive types instead of 404
Rocco Rutte <pdmef@gmx.net>
parents:
6981
diff
changeset
|
650 msg = 'Archive type not allowed: %s' % type_ |
b84d27386285
hgweb: Respond with HTTP 403 for disabled archive types instead of 404
Rocco Rutte <pdmef@gmx.net>
parents:
6981
diff
changeset
|
651 raise ErrorResponse(HTTP_FORBIDDEN, msg) |
b84d27386285
hgweb: Respond with HTTP 403 for disabled archive types instead of 404
Rocco Rutte <pdmef@gmx.net>
parents:
6981
diff
changeset
|
652 |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
653 reponame = re.sub(r"\W+", "-", os.path.basename(web.reponame)) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
654 cnode = web.repo.lookup(key) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
655 arch_version = key |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
656 if cnode == key or key == 'tip': |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
657 arch_version = short(cnode) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
658 name = "%s-%s" % (reponame, arch_version) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
659 mimetype, artype, extension, encoding = web.archive_specs[type_] |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
660 headers = [ |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
661 ('Content-Type', mimetype), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
662 ('Content-Disposition', 'attachment; filename=%s%s' % (name, extension)) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
663 ] |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
664 if encoding: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
665 headers.append(('Content-Encoding', encoding)) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
666 req.header(headers) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
667 req.respond(HTTP_OK) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
668 archival.archive(web.repo, req, cnode, artype, prefix=name) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
669 return [] |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
670 |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
671 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
672 def static(web, req, tmpl): |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
673 fname = req.form['file'][0] |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
674 # a repo owner may set web.static in .hg/hgrc to get any file |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
675 # readable by the user running the CGI script |
7107
125c8fedcbe0
Allow hgweb to search for templates in more than one path.
Brendan Cully <brendan@kublai.com>
parents:
7102
diff
changeset
|
676 static = web.config("web", "static", None, untrusted=False) |
125c8fedcbe0
Allow hgweb to search for templates in more than one path.
Brendan Cully <brendan@kublai.com>
parents:
7102
diff
changeset
|
677 if not static: |
7966
aa983c3d94a9
templater: move stylemap function from hgweb to templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7876
diff
changeset
|
678 tp = web.templatepath or templater.templatepath() |
7107
125c8fedcbe0
Allow hgweb to search for templates in more than one path.
Brendan Cully <brendan@kublai.com>
parents:
7102
diff
changeset
|
679 if isinstance(tp, str): |
125c8fedcbe0
Allow hgweb to search for templates in more than one path.
Brendan Cully <brendan@kublai.com>
parents:
7102
diff
changeset
|
680 tp = [tp] |
7288
9c399c53469d
Allow per-file shadowing of static directory in templatepath
Brendan Cully <brendan@kublai.com>
parents:
7280
diff
changeset
|
681 static = [os.path.join(p, 'static') for p in tp] |
5964
1cd1582ef25f
hgweb: centralize req.write() calls
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5963
diff
changeset
|
682 return [staticfile(static, fname, req)] |
6691
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
683 |
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
684 def graph(web, req, tmpl): |
10245
207b94f6b65d
hgweb: make graph page size equal to shortlog
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9404
diff
changeset
|
685 |
6691
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
686 rev = webutil.changectx(web.repo, req).rev() |
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
687 bg_height = 39 |
10245
207b94f6b65d
hgweb: make graph page size equal to shortlog
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9404
diff
changeset
|
688 revcount = web.maxshortchanges |
7345
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7332
diff
changeset
|
689 if 'revcount' in req.form: |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7332
diff
changeset
|
690 revcount = int(req.form.get('revcount', [revcount])[0]) |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7332
diff
changeset
|
691 tmpl.defaults['sessionvars']['revcount'] = revcount |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7332
diff
changeset
|
692 |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7332
diff
changeset
|
693 lessvars = copy.copy(tmpl.defaults['sessionvars']) |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7332
diff
changeset
|
694 lessvars['revcount'] = revcount / 2 |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7332
diff
changeset
|
695 morevars = copy.copy(tmpl.defaults['sessionvars']) |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7332
diff
changeset
|
696 morevars['revcount'] = revcount * 2 |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7332
diff
changeset
|
697 |
6750
fb42030d79d6
add __len__ and __iter__ methods to repo and revlog
Matt Mackall <mpm@selenic.com>
parents:
6747
diff
changeset
|
698 max_rev = len(web.repo) - 1 |
7345
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7332
diff
changeset
|
699 revcount = min(max_rev, revcount) |
6691
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
700 revnode = web.repo.changelog.node(rev) |
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
701 revnode_hex = hex(revnode) |
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
702 uprev = min(max_rev, rev + revcount) |
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
703 downrev = max(0, rev - revcount) |
6750
fb42030d79d6
add __len__ and __iter__ methods to repo and revlog
Matt Mackall <mpm@selenic.com>
parents:
6747
diff
changeset
|
704 count = len(web.repo) |
7332
5c95d7667dd1
hgweb: fix pagination for graph
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
705 changenav = webutil.revnavgen(rev, revcount, count, web.repo.changectx) |
6691
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
706 |
8842
acd03a6e2426
graphmod/webcommands: use generic DAG walks
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8796
diff
changeset
|
707 dag = graphmod.revisions(web.repo, rev, downrev) |
acd03a6e2426
graphmod/webcommands: use generic DAG walks
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8796
diff
changeset
|
708 tree = list(graphmod.colored(dag)) |
10394
4612cded5176
fix coding style (reported by pylint)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
709 canvasheight = (len(tree) + 1) * bg_height - 27 |
6691
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
710 data = [] |
8842
acd03a6e2426
graphmod/webcommands: use generic DAG walks
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8796
diff
changeset
|
711 for (id, type, ctx, vtx, edges) in tree: |
acd03a6e2426
graphmod/webcommands: use generic DAG walks
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8796
diff
changeset
|
712 if type != graphmod.CHANGESET: |
acd03a6e2426
graphmod/webcommands: use generic DAG walks
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8796
diff
changeset
|
713 continue |
6691
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
714 node = short(ctx.node()) |
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
715 age = templatefilters.age(ctx.date()) |
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
716 desc = templatefilters.firstline(ctx.description()) |
8236
9f53e203a09b
webcommands: move nonempty logic from JavaScript to Python
Martin Geisler <mg@lazybytes.net>
parents:
8225
diff
changeset
|
717 desc = cgi.escape(templatefilters.nonempty(desc)) |
6691
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
718 user = cgi.escape(templatefilters.person(ctx.user())) |
6720
084c9f1ef2bd
graph: display branch name alongside tags
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6704
diff
changeset
|
719 branch = ctx.branch() |
084c9f1ef2bd
graph: display branch name alongside tags
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6704
diff
changeset
|
720 branch = branch, web.repo.branchtags().get(branch) == ctx.node() |
084c9f1ef2bd
graph: display branch name alongside tags
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6704
diff
changeset
|
721 data.append((node, vtx, edges, desc, user, age, branch, ctx.tags())) |
6691
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
722 |
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
723 return tmpl('graph', rev=rev, revcount=revcount, uprev=uprev, |
7345
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7332
diff
changeset
|
724 lessvars=lessvars, morevars=morevars, downrev=downrev, |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7332
diff
changeset
|
725 canvasheight=canvasheight, jsdata=data, bg_height=bg_height, |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7332
diff
changeset
|
726 node=revnode_hex, changenav=changenav) |