Mercurial > hg-stable
annotate mercurial/hgweb/webcommands.py @ 14490:1d3e2349304a
web: provide diffstat to the changeset page
This includes all affected files, so it can be used for an extended view of
the files or as a replacement for the filenodelink and filenolink templates.
author | Steven Brown <StevenGBrown@gmail.com> |
---|---|
date | Sat, 28 May 2011 14:44:45 +0800 |
parents | 421d56a055fd |
children | 175e4b9d8a96 |
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 |
12666
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
16 from mercurial import help as helpmod |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
17 from mercurial.i18n import _ |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
18 |
5963
5be210afe1b8
hgweb: explicitly check if requested command exists
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5960
diff
changeset
|
19 # __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
|
20 # 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
|
21 |
5be210afe1b8
hgweb: explicitly check if requested command exists
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5960
diff
changeset
|
22 __all__ = [ |
5be210afe1b8
hgweb: explicitly check if requested command exists
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5960
diff
changeset
|
23 'log', 'rawfile', 'file', 'changelog', 'shortlog', 'changeset', 'rev', |
13597
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
24 'manifest', 'tags', 'bookmarks', 'branches', 'summary', 'filediff', 'diff', |
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
25 'annotate', 'filelog', 'archive', 'static', 'graph', 'help', |
5963
5be210afe1b8
hgweb: explicitly check if requested command exists
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5960
diff
changeset
|
26 ] |
5be210afe1b8
hgweb: explicitly check if requested command exists
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5960
diff
changeset
|
27 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
28 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
|
29 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
|
30 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
|
31 else: |
5964
1cd1582ef25f
hgweb: centralize req.write() calls
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5963
diff
changeset
|
32 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
|
33 |
5890
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
34 def rawfile(web, req, tmpl): |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6368
diff
changeset
|
35 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
|
36 if not path: |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
37 content = manifest(web, req, tmpl) |
5993
948a41e77902
hgweb: explicit response status
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5964
diff
changeset
|
38 req.respond(HTTP_OK, web.ctype) |
948a41e77902
hgweb: explicit response status
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5964
diff
changeset
|
39 return content |
5890
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
40 |
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
41 try: |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6368
diff
changeset
|
42 fctx = webutil.filectx(web.repo, req) |
7633 | 43 except error.LookupError, inst: |
6368
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6217
diff
changeset
|
44 try: |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
45 content = manifest(web, req, tmpl) |
6368
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6217
diff
changeset
|
46 req.respond(HTTP_OK, web.ctype) |
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6217
diff
changeset
|
47 return content |
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6217
diff
changeset
|
48 except ErrorResponse: |
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6217
diff
changeset
|
49 raise inst |
5890
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
50 |
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
51 path = fctx.path() |
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
52 text = fctx.data() |
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
53 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
|
54 if mt is None: |
029a54423a96
hgweb: Serve raw non-binary files as text/plain
Rocco Rutte <pdmef@gmx.net>
parents:
6857
diff
changeset
|
55 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
|
56 if mt.startswith('text/'): |
716e176a4e01
hgweb: specify a charset when sending raw text files
Julian Cowley <julian@lava.net>
parents:
10394
diff
changeset
|
57 mt += '; charset="%s"' % encoding.encoding |
5890
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
58 |
5993
948a41e77902
hgweb: explicit response status
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5964
diff
changeset
|
59 req.respond(HTTP_OK, mt, path, len(text)) |
5964
1cd1582ef25f
hgweb: centralize req.write() calls
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5963
diff
changeset
|
60 return [text] |
5890
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
61 |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
62 def _filerevision(web, tmpl, fctx): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
63 f = fctx.path() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
64 text = fctx.data() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
65 parity = paritygen(web.stripecount) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
66 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
67 if binary(text): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
68 mt = mimetypes.guess_type(f)[0] or 'application/octet-stream' |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
69 text = '(binary:%s)' % mt |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
70 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
71 def lines(): |
9136
31177742f54a
for calls expecting bool args, pass bool instead of int
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8842
diff
changeset
|
72 for lineno, t in enumerate(text.splitlines(True)): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
73 yield {"line": t, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
74 "lineid": "l%d" % (lineno + 1), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
75 "linenumber": "% 6d" % (lineno + 1), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
76 "parity": parity.next()} |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
77 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
78 return tmpl("filerevision", |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
79 file=f, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
80 path=webutil.up(f), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
81 text=lines(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
82 rev=fctx.rev(), |
14055
421d56a055fd
drop {short,hex}(ctx.node()) calls in favor of ctx methods
Alexander Solovyov <alexander@solovyov.net>
parents:
14043
diff
changeset
|
83 node=fctx.hex(), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
84 author=fctx.user(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
85 date=fctx.date(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
86 desc=fctx.description(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
87 branch=webutil.nodebranchnodefault(fctx), |
7671
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
88 parent=webutil.parents(fctx), |
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
89 child=webutil.children(fctx), |
6434
62e0bb41e682
hgweb: minor improvements for new web style
Matt Mackall <mpm@selenic.com>
parents:
6410
diff
changeset
|
90 rename=webutil.renamelink(fctx), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
91 permissions=fctx.manifest().flags(f)) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
92 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
93 def file(web, req, tmpl): |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6368
diff
changeset
|
94 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
|
95 if not path: |
6857 | 96 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
|
97 try: |
6857 | 98 return _filerevision(web, tmpl, webutil.filectx(web.repo, req)) |
7633 | 99 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
|
100 try: |
6857 | 101 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
|
102 except ErrorResponse: |
2ff0829bdae5
hgweb: do not use unassigned variables in exception handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6669
diff
changeset
|
103 raise inst |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
104 |
10247
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
105 def _search(web, req, tmpl): |
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
106 |
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
107 query = req.form['rev'][0] |
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
108 revcount = web.maxchanges |
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
109 if 'revcount' in req.form: |
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
110 revcount = int(req.form.get('revcount', [revcount])[0]) |
13931
c3372529247f
hgweb: set minimum number of revision to display to 1 when revcount is 0
Md. O. Shayan <mdoshayan@gmail.com>
parents:
13924
diff
changeset
|
111 revcount = max(revcount, 1) |
10247
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
112 tmpl.defaults['sessionvars']['revcount'] = revcount |
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
113 |
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
114 lessvars = copy.copy(tmpl.defaults['sessionvars']) |
13931
c3372529247f
hgweb: set minimum number of revision to display to 1 when revcount is 0
Md. O. Shayan <mdoshayan@gmail.com>
parents:
13924
diff
changeset
|
115 lessvars['revcount'] = max(revcount / 2, 1) |
10247
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
116 lessvars['rev'] = query |
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
117 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
|
118 morevars['revcount'] = revcount * 2 |
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
119 morevars['rev'] = query |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
120 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
121 def changelist(**map): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
122 count = 0 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
123 qw = query.lower().split() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
124 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
125 def revgen(): |
12059
0de6cfdcaad8
webcommands: remove unncessary access to repo.changelog
Patrick Mezard <pmezard@gmail.com>
parents:
11332
diff
changeset
|
126 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
|
127 l = [] |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
128 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
|
129 ctx = web.repo[j] |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
130 l.append(ctx) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
131 l.reverse() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
132 for e in l: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
133 yield e |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
134 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
135 for ctx in revgen(): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
136 miss = 0 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
137 for q in qw: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
138 if not (q in ctx.user().lower() or |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
139 q in ctx.description().lower() or |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
140 q in " ".join(ctx.files()).lower()): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
141 miss = 1 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
142 break |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
143 if miss: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
144 continue |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
145 |
6659
bc553c6d1ef9
webcommands: fix increments lost by 894875eae49b
Andrew Beekhof <beekhof@gmail.com>
parents:
6657
diff
changeset
|
146 count += 1 |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
147 n = ctx.node() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
148 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
|
149 files = webutil.listfilediffs(tmpl, ctx.files(), n, web.maxfiles) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
150 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
151 yield tmpl('searchentry', |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
152 parity=parity.next(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
153 author=ctx.user(), |
7671
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
154 parent=webutil.parents(ctx), |
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
155 child=webutil.children(ctx), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
156 changelogtag=showtags, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
157 desc=ctx.description(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
158 date=ctx.date(), |
7311
de9c87fe1620
hgweb: move another utility function into the webutil module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7310
diff
changeset
|
159 files=files, |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
160 rev=ctx.rev(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
161 node=hex(n), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
162 tags=webutil.nodetagsdict(web.repo, n), |
13794
5c18a0bca26f
hgweb: add bookmark labels to monoblue theme (based on 270f57d35525)
Yuya Nishihara <yuya@tcha.org>
parents:
13597
diff
changeset
|
163 bookmarks=webutil.nodebookmarksdict(web.repo, n), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
164 inbranch=webutil.nodeinbranch(web.repo, ctx), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
165 branches=webutil.nodebranchdict(web.repo, ctx)) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
166 |
10247
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
167 if count >= revcount: |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
168 break |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
169 |
12059
0de6cfdcaad8
webcommands: remove unncessary access to repo.changelog
Patrick Mezard <pmezard@gmail.com>
parents:
11332
diff
changeset
|
170 tip = web.repo['tip'] |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
171 parity = paritygen(web.stripecount) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
172 |
12059
0de6cfdcaad8
webcommands: remove unncessary access to repo.changelog
Patrick Mezard <pmezard@gmail.com>
parents:
11332
diff
changeset
|
173 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
|
174 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
|
175 morevars=morevars, lessvars=lessvars) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
176 |
10247
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
177 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
|
178 |
5915
d0576d065993
Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents:
5890
diff
changeset
|
179 if 'node' in req.form: |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6368
diff
changeset
|
180 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
|
181 else: |
5915
d0576d065993
Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents:
5890
diff
changeset
|
182 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
|
183 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
|
184 else: |
6750
fb42030d79d6
add __len__ and __iter__ methods to repo and revlog
Matt Mackall <mpm@selenic.com>
parents:
6747
diff
changeset
|
185 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
|
186 try: |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6720
diff
changeset
|
187 ctx = web.repo[hi] |
7637 | 188 except error.RepoError: |
10247
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
189 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
|
190 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
191 def changelist(limit=0, **map): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
192 l = [] # build a list in forward order for efficiency |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
193 for i in xrange(start, end): |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6720
diff
changeset
|
194 ctx = web.repo[i] |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
195 n = ctx.node() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
196 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
|
197 files = webutil.listfilediffs(tmpl, ctx.files(), n, web.maxfiles) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
198 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
199 l.insert(0, {"parity": parity.next(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
200 "author": ctx.user(), |
7671
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
201 "parent": webutil.parents(ctx, i - 1), |
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
202 "child": webutil.children(ctx, i + 1), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
203 "changelogtag": showtags, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
204 "desc": ctx.description(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
205 "date": ctx.date(), |
7311
de9c87fe1620
hgweb: move another utility function into the webutil module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7310
diff
changeset
|
206 "files": files, |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
207 "rev": i, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
208 "node": hex(n), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
209 "tags": webutil.nodetagsdict(web.repo, n), |
13596
270f57d35525
hgweb: add display of bookmarks for changelog and changeset
Alexander Solovyov <alexander@solovyov.net>
parents:
13199
diff
changeset
|
210 "bookmarks": webutil.nodebookmarksdict(web.repo, n), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
211 "inbranch": webutil.nodeinbranch(web.repo, ctx), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
212 "branches": webutil.nodebranchdict(web.repo, ctx) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
213 }) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
214 |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
215 if limit > 0: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
216 l = l[:limit] |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
217 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
218 for e in l: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
219 yield e |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
220 |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
221 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
|
222 if 'revcount' in req.form: |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
223 revcount = int(req.form.get('revcount', [revcount])[0]) |
13931
c3372529247f
hgweb: set minimum number of revision to display to 1 when revcount is 0
Md. O. Shayan <mdoshayan@gmail.com>
parents:
13924
diff
changeset
|
224 revcount = max(revcount, 1) |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
225 tmpl.defaults['sessionvars']['revcount'] = revcount |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
226 |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
227 lessvars = copy.copy(tmpl.defaults['sessionvars']) |
13931
c3372529247f
hgweb: set minimum number of revision to display to 1 when revcount is 0
Md. O. Shayan <mdoshayan@gmail.com>
parents:
13924
diff
changeset
|
228 lessvars['revcount'] = max(revcount / 2, 1) |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
229 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
|
230 morevars['revcount'] = revcount * 2 |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
231 |
12059
0de6cfdcaad8
webcommands: remove unncessary access to repo.changelog
Patrick Mezard <pmezard@gmail.com>
parents:
11332
diff
changeset
|
232 count = len(web.repo) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
233 pos = ctx.rev() |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
234 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
|
235 end = min(count, start + revcount) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
236 pos = end - 1 |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
237 parity = paritygen(web.stripecount, offset=start - end) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
238 |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
239 changenav = webutil.revnavgen(pos, revcount, count, web.repo.changectx) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
240 |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
241 return tmpl(shortlog and 'shortlog' or 'changelog', changenav=changenav, |
14055
421d56a055fd
drop {short,hex}(ctx.node()) calls in favor of ctx methods
Alexander Solovyov <alexander@solovyov.net>
parents:
14043
diff
changeset
|
242 node=ctx.hex(), rev=pos, changesets=count, |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
243 entries=lambda **x: changelist(limit=0,**x), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
244 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
|
245 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
|
246 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
|
247 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
248 def shortlog(web, req, tmpl): |
5964
1cd1582ef25f
hgweb: centralize req.write() calls
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5963
diff
changeset
|
249 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
|
250 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
251 def changeset(web, req, tmpl): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
252 ctx = webutil.changectx(web.repo, req) |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7305
diff
changeset
|
253 showtags = webutil.showtag(web.repo, tmpl, 'changesettag', ctx.node()) |
13596
270f57d35525
hgweb: add display of bookmarks for changelog and changeset
Alexander Solovyov <alexander@solovyov.net>
parents:
13199
diff
changeset
|
254 showbookmarks = webutil.showbookmark(web.repo, tmpl, 'changesetbookmark', |
270f57d35525
hgweb: add display of bookmarks for changelog and changeset
Alexander Solovyov <alexander@solovyov.net>
parents:
13199
diff
changeset
|
255 ctx.node()) |
7410
f1111704061e
coal/paper: show branch name in changeset view
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7409
diff
changeset
|
256 showbranch = webutil.nodebranchnodefault(ctx) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
257 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
258 files = [] |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
259 parity = paritygen(web.stripecount) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
260 for f in ctx.files(): |
7182
295af5bc1bcc
hgweb: remove links to non-existent file versions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7107
diff
changeset
|
261 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
|
262 files.append(tmpl(template, |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7305
diff
changeset
|
263 node=ctx.hex(), file=f, |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
264 parity=parity.next())) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
265 |
9402
5d49fdef6fd0
hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8842
diff
changeset
|
266 style = web.config('web', 'style', 'paper') |
5d49fdef6fd0
hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8842
diff
changeset
|
267 if 'style' in req.form: |
5d49fdef6fd0
hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8842
diff
changeset
|
268 style = req.form['style'][0] |
5d49fdef6fd0
hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8842
diff
changeset
|
269 |
14490
1d3e2349304a
web: provide diffstat to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14055
diff
changeset
|
270 parity = paritygen(web.stripecount) |
9402
5d49fdef6fd0
hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8842
diff
changeset
|
271 diffs = webutil.diffs(web.repo, tmpl, ctx, None, parity, style) |
14490
1d3e2349304a
web: provide diffstat to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14055
diff
changeset
|
272 |
1d3e2349304a
web: provide diffstat to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14055
diff
changeset
|
273 parity = paritygen(web.stripecount) |
1d3e2349304a
web: provide diffstat to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14055
diff
changeset
|
274 diffstat = lambda: webutil.diffstat(tmpl, ctx, parity) |
1d3e2349304a
web: provide diffstat to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14055
diff
changeset
|
275 |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
276 return tmpl('changeset', |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
277 diff=diffs, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
278 rev=ctx.rev(), |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7305
diff
changeset
|
279 node=ctx.hex(), |
7671
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
280 parent=webutil.parents(ctx), |
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
281 child=webutil.children(ctx), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
282 changesettag=showtags, |
13596
270f57d35525
hgweb: add display of bookmarks for changelog and changeset
Alexander Solovyov <alexander@solovyov.net>
parents:
13199
diff
changeset
|
283 changesetbookmark=showbookmarks, |
7410
f1111704061e
coal/paper: show branch name in changeset view
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7409
diff
changeset
|
284 changesetbranch=showbranch, |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
285 author=ctx.user(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
286 desc=ctx.description(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
287 date=ctx.date(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
288 files=files, |
14490
1d3e2349304a
web: provide diffstat to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14055
diff
changeset
|
289 diffstat=diffstat, |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7305
diff
changeset
|
290 archives=web.archivelist(ctx.hex()), |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7305
diff
changeset
|
291 tags=webutil.nodetagsdict(web.repo, ctx.node()), |
13596
270f57d35525
hgweb: add display of bookmarks for changelog and changeset
Alexander Solovyov <alexander@solovyov.net>
parents:
13199
diff
changeset
|
292 bookmarks=webutil.nodebookmarksdict(web.repo, ctx.node()), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
293 branch=webutil.nodebranchnodefault(ctx), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
294 inbranch=webutil.nodeinbranch(web.repo, ctx), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
295 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
|
296 |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
297 rev = changeset |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
298 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
299 def manifest(web, req, tmpl): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
300 ctx = webutil.changectx(web.repo, req) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
301 path = webutil.cleanpath(web.repo, req.form.get('file', [''])[0]) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
302 mf = ctx.manifest() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
303 node = ctx.node() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
304 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
305 files = {} |
7305
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
306 dirs = {} |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
307 parity = paritygen(web.stripecount) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
308 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
309 if path and path[-1] != "/": |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
310 path += "/" |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
311 l = len(path) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
312 abspath = "/" + path |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
313 |
7622
4dd7b28003d2
use dict.iteritems() rather than dict.items()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7612
diff
changeset
|
314 for f, n in mf.iteritems(): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
315 if f[:l] != path: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
316 continue |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
317 remain = f[l:] |
7305
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
318 elements = remain.split('/') |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
319 if len(elements) == 1: |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
320 files[remain] = f |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
321 else: |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
322 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
|
323 for elem in elements[0:-1]: |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
324 if elem not in h: |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
325 h[elem] = {} |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
326 h = h[elem] |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
327 if len(h) > 1: |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
328 break |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
329 h[None] = None # denotes files present |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
330 |
7565
5f162f61e479
hgweb: fix problems with empty repositories
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7434
diff
changeset
|
331 if mf and not files and not dirs: |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
332 raise ErrorResponse(HTTP_NOT_FOUND, 'path not found: ' + path) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
333 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
334 def filelist(**map): |
8209
a1a5a57efe90
replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents:
7966
diff
changeset
|
335 for f in sorted(files): |
7305
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
336 full = files[f] |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
337 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
338 fctx = ctx.filectx(full) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
339 yield {"file": full, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
340 "parity": parity.next(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
341 "basename": f, |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6720
diff
changeset
|
342 "date": fctx.date(), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
343 "size": fctx.size(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
344 "permissions": mf.flags(full)} |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
345 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
346 def dirlist(**map): |
8209
a1a5a57efe90
replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents:
7966
diff
changeset
|
347 for d in sorted(dirs): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
348 |
7305
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
349 emptydirs = [] |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
350 h = dirs[d] |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
351 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
|
352 k, v = h.items()[0] |
7305
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
353 if v: |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
354 emptydirs.append(k) |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
355 h = v |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
356 |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
357 path = "%s%s" % (abspath, d) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
358 yield {"parity": parity.next(), |
7305
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
359 "path": path, |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
360 "emptydirs": "/".join(emptydirs), |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
361 "basename": d} |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
362 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
363 return tmpl("manifest", |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
364 rev=ctx.rev(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
365 node=hex(node), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
366 path=abspath, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
367 up=webutil.up(abspath), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
368 upparity=parity.next(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
369 fentries=filelist, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
370 dentries=dirlist, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
371 archives=web.archivelist(hex(node)), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
372 tags=webutil.nodetagsdict(web.repo, node), |
13794
5c18a0bca26f
hgweb: add bookmark labels to monoblue theme (based on 270f57d35525)
Yuya Nishihara <yuya@tcha.org>
parents:
13597
diff
changeset
|
373 bookmarks=webutil.nodebookmarksdict(web.repo, node), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
374 inbranch=webutil.nodeinbranch(web.repo, ctx), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
375 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
|
376 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
377 def tags(web, req, tmpl): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
378 i = web.repo.tagslist() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
379 i.reverse() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
380 parity = paritygen(web.stripecount) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
381 |
9198
061eeb602354
coding style: use a space after comma
Martin Geisler <mg@lazybytes.net>
parents:
9136
diff
changeset
|
382 def entries(notip=False, limit=0, **map): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
383 count = 0 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
384 for k, n in i: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
385 if notip and k == "tip": |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
386 continue |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
387 if limit > 0 and count >= limit: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
388 continue |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
389 count = count + 1 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
390 yield {"parity": parity.next(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
391 "tag": k, |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6720
diff
changeset
|
392 "date": web.repo[n].date(), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
393 "node": hex(n)} |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
394 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
395 return tmpl("tags", |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
396 node=hex(web.repo.changelog.tip()), |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
397 entries=lambda **x: entries(False, 0, **x), |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
398 entriesnotip=lambda **x: entries(True, 0, **x), |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
399 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
|
400 |
13597
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
401 def bookmarks(web, req, tmpl): |
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
402 i = web.repo._bookmarks.items() |
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
403 parity = paritygen(web.stripecount) |
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
404 |
13923
2176c5babd53
hgweb: remove useless notip handling from bookmarks listing
Yuya Nishihara <yuya@tcha.org>
parents:
13922
diff
changeset
|
405 def entries(limit=0, **map): |
13597
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
406 count = 0 |
13922
b8dd2e95b0ca
hgweb: sort bookmarks in the same manner as console command
Yuya Nishihara <yuya@tcha.org>
parents:
13905
diff
changeset
|
407 for k, n in sorted(i): |
13597
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
408 if limit > 0 and count >= limit: |
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
409 continue |
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
410 count = count + 1 |
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
411 yield {"parity": parity.next(), |
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
412 "bookmark": k, |
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
413 "date": web.repo[n].date(), |
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
414 "node": hex(n)} |
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
415 |
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
416 return tmpl("bookmarks", |
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
417 node=hex(web.repo.changelog.tip()), |
13923
2176c5babd53
hgweb: remove useless notip handling from bookmarks listing
Yuya Nishihara <yuya@tcha.org>
parents:
13922
diff
changeset
|
418 entries=lambda **x: entries(0, **x), |
2176c5babd53
hgweb: remove useless notip handling from bookmarks listing
Yuya Nishihara <yuya@tcha.org>
parents:
13922
diff
changeset
|
419 latestentry=lambda **x: entries(1, **x)) |
13597
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
420 |
8352
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
421 def branches(web, req, tmpl): |
8354
418ea63f00fb
hgweb: use context api in branches webcommand
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8352
diff
changeset
|
422 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
|
423 heads = web.repo.heads() |
8352
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
424 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
|
425 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
|
426 |
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
427 def entries(limit, **map): |
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
428 count = 0 |
8713
de6bb29e208a
hgweb: allow distinction between open/closed branches on branches page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8390
diff
changeset
|
429 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
|
430 if limit > 0 and count >= limit: |
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
431 return |
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
432 count += 1 |
8796
2bcef677a6c3
localrepo: remove 'closed' argument to heads(...) function
John Mulligan <phlogistonjohn@asynchrono.us>
parents:
8713
diff
changeset
|
433 if ctx.node() not in heads: |
2bcef677a6c3
localrepo: remove 'closed' argument to heads(...) function
John Mulligan <phlogistonjohn@asynchrono.us>
parents:
8713
diff
changeset
|
434 status = 'inactive' |
2bcef677a6c3
localrepo: remove 'closed' argument to heads(...) function
John Mulligan <phlogistonjohn@asynchrono.us>
parents:
8713
diff
changeset
|
435 elif not web.repo.branchheads(ctx.branch()): |
2bcef677a6c3
localrepo: remove 'closed' argument to heads(...) function
John Mulligan <phlogistonjohn@asynchrono.us>
parents:
8713
diff
changeset
|
436 status = 'closed' |
2bcef677a6c3
localrepo: remove 'closed' argument to heads(...) function
John Mulligan <phlogistonjohn@asynchrono.us>
parents:
8713
diff
changeset
|
437 else: |
2bcef677a6c3
localrepo: remove 'closed' argument to heads(...) function
John Mulligan <phlogistonjohn@asynchrono.us>
parents:
8713
diff
changeset
|
438 status = 'open' |
8352
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
439 yield {'parity': parity.next(), |
8354
418ea63f00fb
hgweb: use context api in branches webcommand
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8352
diff
changeset
|
440 'branch': ctx.branch(), |
8713
de6bb29e208a
hgweb: allow distinction between open/closed branches on branches page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8390
diff
changeset
|
441 'status': status, |
8354
418ea63f00fb
hgweb: use context api in branches webcommand
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8352
diff
changeset
|
442 'node': ctx.hex(), |
418ea63f00fb
hgweb: use context api in branches webcommand
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8352
diff
changeset
|
443 'date': ctx.date()} |
8352
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
444 |
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
445 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
|
446 entries=lambda **x: entries(0, **x), |
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
447 latestentry=lambda **x: entries(1, **x)) |
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
448 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
449 def summary(web, req, tmpl): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
450 i = web.repo.tagslist() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
451 i.reverse() |
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 def tagentries(**map): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
454 parity = paritygen(web.stripecount) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
455 count = 0 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
456 for k, n in i: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
457 if k == "tip": # skip tip |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
458 continue |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
459 |
6659
bc553c6d1ef9
webcommands: fix increments lost by 894875eae49b
Andrew Beekhof <beekhof@gmail.com>
parents:
6657
diff
changeset
|
460 count += 1 |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
461 if count > 10: # limit to 10 tags |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
462 break |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
463 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
464 yield tmpl("tagentry", |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
465 parity=parity.next(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
466 tag=k, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
467 node=hex(n), |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6720
diff
changeset
|
468 date=web.repo[n].date()) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
469 |
13924
ea726c97c1b6
hgweb: add bookmarks listing to summary page of gitweb/monoblue styles
Yuya Nishihara <yuya@tcha.org>
parents:
13923
diff
changeset
|
470 def bookmarks(**map): |
ea726c97c1b6
hgweb: add bookmarks listing to summary page of gitweb/monoblue styles
Yuya Nishihara <yuya@tcha.org>
parents:
13923
diff
changeset
|
471 parity = paritygen(web.stripecount) |
ea726c97c1b6
hgweb: add bookmarks listing to summary page of gitweb/monoblue styles
Yuya Nishihara <yuya@tcha.org>
parents:
13923
diff
changeset
|
472 b = web.repo._bookmarks.items() |
ea726c97c1b6
hgweb: add bookmarks listing to summary page of gitweb/monoblue styles
Yuya Nishihara <yuya@tcha.org>
parents:
13923
diff
changeset
|
473 for k, n in sorted(b)[:10]: # limit to 10 bookmarks |
ea726c97c1b6
hgweb: add bookmarks listing to summary page of gitweb/monoblue styles
Yuya Nishihara <yuya@tcha.org>
parents:
13923
diff
changeset
|
474 yield {'parity': parity.next(), |
ea726c97c1b6
hgweb: add bookmarks listing to summary page of gitweb/monoblue styles
Yuya Nishihara <yuya@tcha.org>
parents:
13923
diff
changeset
|
475 'bookmark': k, |
ea726c97c1b6
hgweb: add bookmarks listing to summary page of gitweb/monoblue styles
Yuya Nishihara <yuya@tcha.org>
parents:
13923
diff
changeset
|
476 'date': web.repo[n].date(), |
ea726c97c1b6
hgweb: add bookmarks listing to summary page of gitweb/monoblue styles
Yuya Nishihara <yuya@tcha.org>
parents:
13923
diff
changeset
|
477 'node': hex(n)} |
ea726c97c1b6
hgweb: add bookmarks listing to summary page of gitweb/monoblue styles
Yuya Nishihara <yuya@tcha.org>
parents:
13923
diff
changeset
|
478 |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
479 def branches(**map): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
480 parity = paritygen(web.stripecount) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
481 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
482 b = web.repo.branchtags() |
7622
4dd7b28003d2
use dict.iteritems() rather than dict.items()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7612
diff
changeset
|
483 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
|
484 for r, n, t in sorted(l): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
485 yield {'parity': parity.next(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
486 'branch': t, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
487 'node': hex(n), |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6720
diff
changeset
|
488 'date': web.repo[n].date()} |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
489 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
490 def changelist(**map): |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
491 parity = paritygen(web.stripecount, offset=start - end) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
492 l = [] # build a list in forward order for efficiency |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
493 for i in xrange(start, end): |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6720
diff
changeset
|
494 ctx = web.repo[i] |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
495 n = ctx.node() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
496 hn = hex(n) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
497 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
498 l.insert(0, tmpl( |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
499 'shortlogentry', |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
500 parity=parity.next(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
501 author=ctx.user(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
502 desc=ctx.description(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
503 date=ctx.date(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
504 rev=i, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
505 node=hn, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
506 tags=webutil.nodetagsdict(web.repo, n), |
13794
5c18a0bca26f
hgweb: add bookmark labels to monoblue theme (based on 270f57d35525)
Yuya Nishihara <yuya@tcha.org>
parents:
13597
diff
changeset
|
507 bookmarks=webutil.nodebookmarksdict(web.repo, n), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
508 inbranch=webutil.nodeinbranch(web.repo, ctx), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
509 branches=webutil.nodebranchdict(web.repo, ctx))) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
510 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
511 yield l |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
512 |
12059
0de6cfdcaad8
webcommands: remove unncessary access to repo.changelog
Patrick Mezard <pmezard@gmail.com>
parents:
11332
diff
changeset
|
513 tip = web.repo['tip'] |
0de6cfdcaad8
webcommands: remove unncessary access to repo.changelog
Patrick Mezard <pmezard@gmail.com>
parents:
11332
diff
changeset
|
514 count = len(web.repo) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
515 start = max(0, count - web.maxchanges) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
516 end = min(count, start + web.maxchanges) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
517 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
518 return tmpl("summary", |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
519 desc=web.config("web", "description", "unknown"), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
520 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
|
521 lastchange=tip.date(), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
522 tags=tagentries, |
13924
ea726c97c1b6
hgweb: add bookmarks listing to summary page of gitweb/monoblue styles
Yuya Nishihara <yuya@tcha.org>
parents:
13923
diff
changeset
|
523 bookmarks=bookmarks, |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
524 branches=branches, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
525 shortlog=changelist, |
12059
0de6cfdcaad8
webcommands: remove unncessary access to repo.changelog
Patrick Mezard <pmezard@gmail.com>
parents:
11332
diff
changeset
|
526 node=tip.hex(), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
527 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
|
528 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
529 def filediff(web, req, tmpl): |
7183
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
530 fctx, ctx = None, None |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
531 try: |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
532 fctx = webutil.filectx(web.repo, req) |
7280
810ca383da9c
remove unused variables
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7183
diff
changeset
|
533 except LookupError: |
7183
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
534 ctx = webutil.changectx(web.repo, req) |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
535 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
|
536 if path not in ctx.files(): |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
537 raise |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
538 |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
539 if fctx is not None: |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
540 n = fctx.node() |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
541 path = fctx.path() |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
542 else: |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
543 n = ctx.node() |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
544 # path already defined in except clause |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
545 |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7305
diff
changeset
|
546 parity = paritygen(web.stripecount) |
9402
5d49fdef6fd0
hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8842
diff
changeset
|
547 style = web.config('web', 'style', 'paper') |
5d49fdef6fd0
hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8842
diff
changeset
|
548 if 'style' in req.form: |
5d49fdef6fd0
hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8842
diff
changeset
|
549 style = req.form['style'][0] |
5d49fdef6fd0
hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8842
diff
changeset
|
550 |
5d49fdef6fd0
hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8842
diff
changeset
|
551 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
|
552 rename = fctx and webutil.renamelink(fctx) or [] |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
553 ctx = fctx and fctx or ctx |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
554 return tmpl("filediff", |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
555 file=path, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
556 node=hex(n), |
7183
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
557 rev=ctx.rev(), |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
558 date=ctx.date(), |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
559 desc=ctx.description(), |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
560 author=ctx.user(), |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
561 rename=rename, |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
562 branch=webutil.nodebranchnodefault(ctx), |
7671
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
563 parent=webutil.parents(ctx), |
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
564 child=webutil.children(ctx), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
565 diff=diffs) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
566 |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
567 diff = filediff |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
568 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
569 def annotate(web, req, tmpl): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
570 fctx = webutil.filectx(web.repo, req) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
571 f = fctx.path() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
572 parity = paritygen(web.stripecount) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
573 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
574 def annotate(**map): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
575 last = None |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
576 if binary(fctx.data()): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
577 mt = (mimetypes.guess_type(fctx.path())[0] |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
578 or 'application/octet-stream') |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
579 lines = enumerate([((fctx.filectx(fctx.filerev()), 1), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
580 '(binary:%s)' % mt)]) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
581 else: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
582 lines = enumerate(fctx.annotate(follow=True, linenumber=True)) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
583 for lineno, ((f, targetline), l) in lines: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
584 fnode = f.filenode() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
585 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
586 if last != fnode: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
587 last = fnode |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
588 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
589 yield {"parity": parity.next(), |
14055
421d56a055fd
drop {short,hex}(ctx.node()) calls in favor of ctx methods
Alexander Solovyov <alexander@solovyov.net>
parents:
14043
diff
changeset
|
590 "node": f.hex(), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
591 "rev": f.rev(), |
6564
ccc2481e3954
webcommands: pass full author to annotate, fix templates (issue 1054)
Patrick Mezard <pmezard@gmail.com>
parents:
6437
diff
changeset
|
592 "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
|
593 "desc": f.description(), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
594 "file": f.path(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
595 "targetline": targetline, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
596 "line": l, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
597 "lineid": "l%d" % (lineno + 1), |
13199
a38df1250945
hgweb: added revision date to annotate line data
Oli Thissen <oli@tonick.net>
parents:
12696
diff
changeset
|
598 "linenumber": "% 6d" % (lineno + 1), |
a38df1250945
hgweb: added revision date to annotate line data
Oli Thissen <oli@tonick.net>
parents:
12696
diff
changeset
|
599 "revdate": f.date()} |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
600 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
601 return tmpl("fileannotate", |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
602 file=f, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
603 annotate=annotate, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
604 path=webutil.up(f), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
605 rev=fctx.rev(), |
14055
421d56a055fd
drop {short,hex}(ctx.node()) calls in favor of ctx methods
Alexander Solovyov <alexander@solovyov.net>
parents:
14043
diff
changeset
|
606 node=fctx.hex(), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
607 author=fctx.user(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
608 date=fctx.date(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
609 desc=fctx.description(), |
6434
62e0bb41e682
hgweb: minor improvements for new web style
Matt Mackall <mpm@selenic.com>
parents:
6410
diff
changeset
|
610 rename=webutil.renamelink(fctx), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
611 branch=webutil.nodebranchnodefault(fctx), |
7671
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
612 parent=webutil.parents(fctx), |
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
613 child=webutil.children(fctx), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
614 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
|
615 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
616 def filelog(web, req, tmpl): |
7300
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
617 |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
618 try: |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
619 fctx = webutil.filectx(web.repo, req) |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
620 f = fctx.path() |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
621 fl = fctx.filelog() |
7633 | 622 except error.LookupError: |
7300
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
623 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
|
624 fl = web.repo.file(f) |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
625 numrevs = len(fl) |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
626 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
|
627 raise |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
628 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
|
629 first = fl.linkrev(0) |
7300
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
630 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
|
631 raise |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
632 frev = numrevs - 1 |
7361
9fe97eea5510
linkrev: take a revision number rather than a hash
Matt Mackall <mpm@selenic.com>
parents:
7345
diff
changeset
|
633 while fl.linkrev(frev) > rev: |
7300
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
634 frev -= 1 |
7361
9fe97eea5510
linkrev: take a revision number rather than a hash
Matt Mackall <mpm@selenic.com>
parents:
7345
diff
changeset
|
635 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
|
636 |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
637 revcount = web.maxshortchanges |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
638 if 'revcount' in req.form: |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
639 revcount = int(req.form.get('revcount', [revcount])[0]) |
13931
c3372529247f
hgweb: set minimum number of revision to display to 1 when revcount is 0
Md. O. Shayan <mdoshayan@gmail.com>
parents:
13924
diff
changeset
|
640 revcount = max(revcount, 1) |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
641 tmpl.defaults['sessionvars']['revcount'] = revcount |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
642 |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
643 lessvars = copy.copy(tmpl.defaults['sessionvars']) |
13931
c3372529247f
hgweb: set minimum number of revision to display to 1 when revcount is 0
Md. O. Shayan <mdoshayan@gmail.com>
parents:
13924
diff
changeset
|
644 lessvars['revcount'] = max(revcount / 2, 1) |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
645 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
|
646 morevars['revcount'] = revcount * 2 |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
647 |
7300
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
648 count = fctx.filerev() + 1 |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
649 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
|
650 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
|
651 parity = paritygen(web.stripecount, offset=start - end) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
652 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
653 def entries(limit=0, **map): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
654 l = [] |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
655 |
7612
069b29656401
web: use the correct filectx in filelog
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7565
diff
changeset
|
656 repo = web.repo |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
657 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
|
658 iterfctx = fctx.filectx(i) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
659 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
660 l.insert(0, {"parity": parity.next(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
661 "filerev": i, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
662 "file": f, |
14055
421d56a055fd
drop {short,hex}(ctx.node()) calls in favor of ctx methods
Alexander Solovyov <alexander@solovyov.net>
parents:
14043
diff
changeset
|
663 "node": iterfctx.hex(), |
7612
069b29656401
web: use the correct filectx in filelog
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7565
diff
changeset
|
664 "author": iterfctx.user(), |
069b29656401
web: use the correct filectx in filelog
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7565
diff
changeset
|
665 "date": iterfctx.date(), |
069b29656401
web: use the correct filectx in filelog
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7565
diff
changeset
|
666 "rename": webutil.renamelink(iterfctx), |
7671
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
667 "parent": webutil.parents(iterfctx), |
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
668 "child": webutil.children(iterfctx), |
7612
069b29656401
web: use the correct filectx in filelog
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7565
diff
changeset
|
669 "desc": iterfctx.description(), |
069b29656401
web: use the correct filectx in filelog
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7565
diff
changeset
|
670 "tags": webutil.nodetagsdict(repo, iterfctx.node()), |
13794
5c18a0bca26f
hgweb: add bookmark labels to monoblue theme (based on 270f57d35525)
Yuya Nishihara <yuya@tcha.org>
parents:
13597
diff
changeset
|
671 "bookmarks": webutil.nodebookmarksdict( |
5c18a0bca26f
hgweb: add bookmark labels to monoblue theme (based on 270f57d35525)
Yuya Nishihara <yuya@tcha.org>
parents:
13597
diff
changeset
|
672 repo, iterfctx.node()), |
7612
069b29656401
web: use the correct filectx in filelog
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7565
diff
changeset
|
673 "branch": webutil.nodebranchnodefault(iterfctx), |
069b29656401
web: use the correct filectx in filelog
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7565
diff
changeset
|
674 "inbranch": webutil.nodeinbranch(repo, iterfctx), |
069b29656401
web: use the correct filectx in filelog
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7565
diff
changeset
|
675 "branches": webutil.nodebranchdict(repo, iterfctx)}) |
7434
cf7741aa1e96
kill some trailing spaces
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7410
diff
changeset
|
676 |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
677 if limit > 0: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
678 l = l[:limit] |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
679 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
680 for e in l: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
681 yield e |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
682 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
683 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
|
684 nav = webutil.revnavgen(end - 1, revcount, count, nodefunc) |
14055
421d56a055fd
drop {short,hex}(ctx.node()) calls in favor of ctx methods
Alexander Solovyov <alexander@solovyov.net>
parents:
14043
diff
changeset
|
685 return tmpl("filelog", file=f, node=fctx.hex(), nav=nav, |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
686 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
|
687 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
|
688 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
|
689 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
690 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
|
691 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
|
692 allowed = web.configlist("web", "allow_archive") |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
693 key = req.form['node'][0] |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
694 |
7029
b84d27386285
hgweb: Respond with HTTP 403 for disabled archive types instead of 404
Rocco Rutte <pdmef@gmx.net>
parents:
6981
diff
changeset
|
695 if type_ not in web.archives: |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
696 msg = 'Unsupported archive type: %s' % type_ |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
697 raise ErrorResponse(HTTP_NOT_FOUND, msg) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
698 |
7029
b84d27386285
hgweb: Respond with HTTP 403 for disabled archive types instead of 404
Rocco Rutte <pdmef@gmx.net>
parents:
6981
diff
changeset
|
699 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
|
700 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
|
701 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
|
702 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
|
703 |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
704 reponame = re.sub(r"\W+", "-", os.path.basename(web.reponame)) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
705 cnode = web.repo.lookup(key) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
706 arch_version = key |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
707 if cnode == key or key == 'tip': |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
708 arch_version = short(cnode) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
709 name = "%s-%s" % (reponame, arch_version) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
710 mimetype, artype, extension, encoding = web.archive_specs[type_] |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
711 headers = [ |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
712 ('Content-Type', mimetype), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
713 ('Content-Disposition', 'attachment; filename=%s%s' % (name, extension)) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
714 ] |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
715 if encoding: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
716 headers.append(('Content-Encoding', encoding)) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
717 req.header(headers) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
718 req.respond(HTTP_OK) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
719 archival.archive(web.repo, req, cnode, artype, prefix=name) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
720 return [] |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
721 |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
722 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
723 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
|
724 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
|
725 # 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
|
726 # 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
|
727 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
|
728 if not static: |
7966
aa983c3d94a9
templater: move stylemap function from hgweb to templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7876
diff
changeset
|
729 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
|
730 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
|
731 tp = [tp] |
7288
9c399c53469d
Allow per-file shadowing of static directory in templatepath
Brendan Cully <brendan@kublai.com>
parents:
7280
diff
changeset
|
732 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
|
733 return [staticfile(static, fname, req)] |
6691
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
734 |
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
735 def graph(web, req, tmpl): |
10245
207b94f6b65d
hgweb: make graph page size equal to shortlog
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9404
diff
changeset
|
736 |
6691
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
737 rev = webutil.changectx(web.repo, req).rev() |
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
738 bg_height = 39 |
10245
207b94f6b65d
hgweb: make graph page size equal to shortlog
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9404
diff
changeset
|
739 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
|
740 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
|
741 revcount = int(req.form.get('revcount', [revcount])[0]) |
13931
c3372529247f
hgweb: set minimum number of revision to display to 1 when revcount is 0
Md. O. Shayan <mdoshayan@gmail.com>
parents:
13924
diff
changeset
|
742 revcount = max(revcount, 1) |
7345
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7332
diff
changeset
|
743 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
|
744 |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7332
diff
changeset
|
745 lessvars = copy.copy(tmpl.defaults['sessionvars']) |
13931
c3372529247f
hgweb: set minimum number of revision to display to 1 when revcount is 0
Md. O. Shayan <mdoshayan@gmail.com>
parents:
13924
diff
changeset
|
746 lessvars['revcount'] = max(revcount / 2, 1) |
7345
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7332
diff
changeset
|
747 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
|
748 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
|
749 |
6750
fb42030d79d6
add __len__ and __iter__ methods to repo and revlog
Matt Mackall <mpm@selenic.com>
parents:
6747
diff
changeset
|
750 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
|
751 revcount = min(max_rev, revcount) |
6691
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
752 revnode = web.repo.changelog.node(rev) |
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
753 revnode_hex = hex(revnode) |
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
754 uprev = min(max_rev, rev + revcount) |
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
755 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
|
756 count = len(web.repo) |
7332
5c95d7667dd1
hgweb: fix pagination for graph
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7311
diff
changeset
|
757 changenav = webutil.revnavgen(rev, revcount, count, web.repo.changectx) |
13905
08d49b6b8d32
hgweb: fix inconsistant display of graphlog (issue1706)
Md. O. Shayan <mdoshayan@gmail.com>
parents:
13794
diff
changeset
|
758 startrev = rev |
08d49b6b8d32
hgweb: fix inconsistant display of graphlog (issue1706)
Md. O. Shayan <mdoshayan@gmail.com>
parents:
13794
diff
changeset
|
759 # if starting revision is less than 60 set it to uprev |
08d49b6b8d32
hgweb: fix inconsistant display of graphlog (issue1706)
Md. O. Shayan <mdoshayan@gmail.com>
parents:
13794
diff
changeset
|
760 if rev < web.maxshortchanges: |
08d49b6b8d32
hgweb: fix inconsistant display of graphlog (issue1706)
Md. O. Shayan <mdoshayan@gmail.com>
parents:
13794
diff
changeset
|
761 startrev = uprev |
6691
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
762 |
14043
1c1e1232abdc
graphlog: make use of graphmod's revset support
Alexander Solovyov <alexander@solovyov.net>
parents:
13931
diff
changeset
|
763 dag = graphmod.dagwalker(web.repo, range(startrev, downrev - 1, -1)) |
8842
acd03a6e2426
graphmod/webcommands: use generic DAG walks
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8796
diff
changeset
|
764 tree = list(graphmod.colored(dag)) |
10394
4612cded5176
fix coding style (reported by pylint)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
765 canvasheight = (len(tree) + 1) * bg_height - 27 |
6691
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
766 data = [] |
8842
acd03a6e2426
graphmod/webcommands: use generic DAG walks
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8796
diff
changeset
|
767 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
|
768 if type != graphmod.CHANGESET: |
acd03a6e2426
graphmod/webcommands: use generic DAG walks
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8796
diff
changeset
|
769 continue |
14055
421d56a055fd
drop {short,hex}(ctx.node()) calls in favor of ctx methods
Alexander Solovyov <alexander@solovyov.net>
parents:
14043
diff
changeset
|
770 node = str(ctx) |
6691
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
771 age = templatefilters.age(ctx.date()) |
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
772 desc = templatefilters.firstline(ctx.description()) |
8236
9f53e203a09b
webcommands: move nonempty logic from JavaScript to Python
Martin Geisler <mg@lazybytes.net>
parents:
8225
diff
changeset
|
773 desc = cgi.escape(templatefilters.nonempty(desc)) |
6691
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
774 user = cgi.escape(templatefilters.person(ctx.user())) |
6720
084c9f1ef2bd
graph: display branch name alongside tags
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6704
diff
changeset
|
775 branch = ctx.branch() |
084c9f1ef2bd
graph: display branch name alongside tags
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6704
diff
changeset
|
776 branch = branch, web.repo.branchtags().get(branch) == ctx.node() |
13597
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
777 data.append((node, vtx, edges, desc, user, age, branch, ctx.tags(), |
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
778 ctx.bookmarks())) |
6691
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
779 |
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
780 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
|
781 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
|
782 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
|
783 node=revnode_hex, changenav=changenav) |
12666
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
784 |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
785 def _getdoc(e): |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
786 doc = e[0].__doc__ |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
787 if doc: |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
788 doc = doc.split('\n')[0] |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
789 else: |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
790 doc = _('(no help text available)') |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
791 return doc |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
792 |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
793 def help(web, req, tmpl): |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
794 from mercurial import commands # avoid cycle |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
795 |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
796 topicname = req.form.get('node', [None])[0] |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
797 if not topicname: |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
798 def topics(**map): |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
799 for entries, summary, _ in helpmod.helptable: |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
800 entries = sorted(entries, key=len) |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
801 yield {'topic': entries[-1], 'summary': summary} |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
802 |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
803 early, other = [], [] |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
804 primary = lambda s: s.split('|')[0] |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
805 for c, e in commands.table.iteritems(): |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
806 doc = _getdoc(e) |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
807 if 'DEPRECATED' in doc or c.startswith('debug'): |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
808 continue |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
809 cmd = primary(c) |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
810 if cmd.startswith('^'): |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
811 early.append((cmd[1:], doc)) |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
812 else: |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
813 other.append((cmd, doc)) |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
814 |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
815 early.sort() |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
816 other.sort() |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
817 |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
818 def earlycommands(**map): |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
819 for c, doc in early: |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
820 yield {'topic': c, 'summary': doc} |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
821 |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
822 def othercommands(**map): |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
823 for c, doc in other: |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
824 yield {'topic': c, 'summary': doc} |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
825 |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
826 return tmpl('helptopics', topics=topics, earlycommands=earlycommands, |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
827 othercommands=othercommands, title='Index') |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
828 |
12696
ef969e58a394
hgweb: another fix for the help termwidth bug
Matt Mackall <mpm@selenic.com>
parents:
12692
diff
changeset
|
829 u = webutil.wsgiui() |
12666
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
830 u.pushbuffer() |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
831 try: |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
832 commands.help_(u, topicname) |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
833 except error.UnknownCommand: |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
834 raise ErrorResponse(HTTP_NOT_FOUND) |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
835 doc = u.popbuffer() |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
836 return tmpl('help', topic=topicname, doc=doc) |