Mercurial > hg-stable
annotate mercurial/hgweb/webcommands.py @ 18427:56ca4443a343
hgweb: use changelog for iteration
Iterating through changelog is necessary to enforce filtering.
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Fri, 11 Jan 2013 01:08:00 +0100 |
parents | e3f5cef11d6a |
children | 8c10f760ca34 |
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 |
17302
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
11 from mercurial.node import short, hex, nullid |
7873
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 |
15528
a84698badf0b
annotate: support diff whitespace filtering flags (issue3030)
Patrick Mezard <pmezard@gmail.com>
parents:
15004
diff
changeset
|
15 from mercurial import graphmod, patch |
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 |
17933
8243dd66e0e3
webcommands: allow hgweb's archive to recurse into subrepos
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17322
diff
changeset
|
17 from mercurial import scmutil |
12666
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
18 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
|
19 |
5963
5be210afe1b8
hgweb: explicitly check if requested command exists
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5960
diff
changeset
|
20 # __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
|
21 # 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
|
22 |
5be210afe1b8
hgweb: explicitly check if requested command exists
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5960
diff
changeset
|
23 __all__ = [ |
5be210afe1b8
hgweb: explicitly check if requested command exists
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5960
diff
changeset
|
24 '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
|
25 'manifest', 'tags', 'bookmarks', 'branches', 'summary', 'filediff', 'diff', |
17202
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
26 'comparison', 'annotate', 'filelog', 'archive', 'static', 'graph', 'help', |
5963
5be210afe1b8
hgweb: explicitly check if requested command exists
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5960
diff
changeset
|
27 ] |
5be210afe1b8
hgweb: explicitly check if requested command exists
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5960
diff
changeset
|
28 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
29 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
|
30 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
|
31 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
|
32 else: |
5964
1cd1582ef25f
hgweb: centralize req.write() calls
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5963
diff
changeset
|
33 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
|
34 |
5890
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
35 def rawfile(web, req, tmpl): |
15004
d06b9c55ddab
hgweb: raw file mimetype guessing configurable, off by default (BC) (issue2923)
Matt Mackall <mpm@selenic.com>
parents:
14771
diff
changeset
|
36 guessmime = web.configbool('web', 'guessmime', False) |
d06b9c55ddab
hgweb: raw file mimetype guessing configurable, off by default (BC) (issue2923)
Matt Mackall <mpm@selenic.com>
parents:
14771
diff
changeset
|
37 |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6368
diff
changeset
|
38 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
|
39 if not path: |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
40 content = manifest(web, req, tmpl) |
5993
948a41e77902
hgweb: explicit response status
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5964
diff
changeset
|
41 req.respond(HTTP_OK, web.ctype) |
948a41e77902
hgweb: explicit response status
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5964
diff
changeset
|
42 return content |
5890
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
43 |
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
44 try: |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6368
diff
changeset
|
45 fctx = webutil.filectx(web.repo, req) |
7633 | 46 except error.LookupError, inst: |
6368
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6217
diff
changeset
|
47 try: |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
48 content = manifest(web, req, tmpl) |
6368
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6217
diff
changeset
|
49 req.respond(HTTP_OK, web.ctype) |
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6217
diff
changeset
|
50 return content |
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6217
diff
changeset
|
51 except ErrorResponse: |
2c370f08c486
hgweb: better error messages
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6217
diff
changeset
|
52 raise inst |
5890
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
53 |
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
54 path = fctx.path() |
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
55 text = fctx.data() |
15004
d06b9c55ddab
hgweb: raw file mimetype guessing configurable, off by default (BC) (issue2923)
Matt Mackall <mpm@selenic.com>
parents:
14771
diff
changeset
|
56 mt = 'application/binary' |
d06b9c55ddab
hgweb: raw file mimetype guessing configurable, off by default (BC) (issue2923)
Matt Mackall <mpm@selenic.com>
parents:
14771
diff
changeset
|
57 if guessmime: |
d06b9c55ddab
hgweb: raw file mimetype guessing configurable, off by default (BC) (issue2923)
Matt Mackall <mpm@selenic.com>
parents:
14771
diff
changeset
|
58 mt = mimetypes.guess_type(path)[0] |
d06b9c55ddab
hgweb: raw file mimetype guessing configurable, off by default (BC) (issue2923)
Matt Mackall <mpm@selenic.com>
parents:
14771
diff
changeset
|
59 if mt is None: |
d06b9c55ddab
hgweb: raw file mimetype guessing configurable, off by default (BC) (issue2923)
Matt Mackall <mpm@selenic.com>
parents:
14771
diff
changeset
|
60 mt = binary(text) and 'application/binary' or 'text/plain' |
11332
716e176a4e01
hgweb: specify a charset when sending raw text files
Julian Cowley <julian@lava.net>
parents:
10394
diff
changeset
|
61 if mt.startswith('text/'): |
716e176a4e01
hgweb: specify a charset when sending raw text files
Julian Cowley <julian@lava.net>
parents:
10394
diff
changeset
|
62 mt += '; charset="%s"' % encoding.encoding |
5890
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
63 |
18352
e33b9b92a200
hgweb: pass the actual response body to request.response, not just the length
Mads Kiilerich <mads@kiilerich.com>
parents:
18348
diff
changeset
|
64 req.respond(HTTP_OK, mt, path, body=text) |
e33b9b92a200
hgweb: pass the actual response body to request.response, not just the length
Mads Kiilerich <mads@kiilerich.com>
parents:
18348
diff
changeset
|
65 return [] |
5890
a0e20a5eba3c
hgweb: fast path for sending raw files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5600
diff
changeset
|
66 |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
67 def _filerevision(web, tmpl, fctx): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
68 f = fctx.path() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
69 text = fctx.data() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
70 parity = paritygen(web.stripecount) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
71 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
72 if binary(text): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
73 mt = mimetypes.guess_type(f)[0] or 'application/octet-stream' |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
74 text = '(binary:%s)' % mt |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
75 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
76 def lines(): |
9136
31177742f54a
for calls expecting bool args, pass bool instead of int
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8842
diff
changeset
|
77 for lineno, t in enumerate(text.splitlines(True)): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
78 yield {"line": t, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
79 "lineid": "l%d" % (lineno + 1), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
80 "linenumber": "% 6d" % (lineno + 1), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
81 "parity": parity.next()} |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
82 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
83 return tmpl("filerevision", |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
84 file=f, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
85 path=webutil.up(f), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
86 text=lines(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
87 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
|
88 node=fctx.hex(), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
89 author=fctx.user(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
90 date=fctx.date(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
91 desc=fctx.description(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
92 branch=webutil.nodebranchnodefault(fctx), |
7671
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
93 parent=webutil.parents(fctx), |
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
94 child=webutil.children(fctx), |
6434
62e0bb41e682
hgweb: minor improvements for new web style
Matt Mackall <mpm@selenic.com>
parents:
6410
diff
changeset
|
95 rename=webutil.renamelink(fctx), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
96 permissions=fctx.manifest().flags(f)) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
97 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
98 def file(web, req, tmpl): |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6368
diff
changeset
|
99 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
|
100 if not path: |
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 try: |
6857 | 103 return _filerevision(web, tmpl, webutil.filectx(web.repo, req)) |
7633 | 104 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
|
105 try: |
6857 | 106 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
|
107 except ErrorResponse: |
2ff0829bdae5
hgweb: do not use unassigned variables in exception handling
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6669
diff
changeset
|
108 raise inst |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
109 |
10247
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
110 def _search(web, req, tmpl): |
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
111 |
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
112 query = req.form['rev'][0] |
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
113 revcount = web.maxchanges |
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
114 if 'revcount' in req.form: |
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
115 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
|
116 revcount = max(revcount, 1) |
10247
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
117 tmpl.defaults['sessionvars']['revcount'] = revcount |
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
118 |
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
119 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
|
120 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
|
121 lessvars['rev'] = query |
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
122 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
|
123 morevars['revcount'] = revcount * 2 |
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
124 morevars['rev'] = query |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
125 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
126 def changelist(**map): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
127 count = 0 |
15727
917f263eeb26
i18n: use "encoding.lower()" to normalize string in hgweb search query
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15528
diff
changeset
|
128 lower = encoding.lower |
917f263eeb26
i18n: use "encoding.lower()" to normalize string in hgweb search query
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15528
diff
changeset
|
129 qw = lower(query).split() |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
130 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
131 def revgen(): |
12059
0de6cfdcaad8
webcommands: remove unncessary access to repo.changelog
Patrick Mezard <pmezard@gmail.com>
parents:
11332
diff
changeset
|
132 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
|
133 l = [] |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
134 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
|
135 ctx = web.repo[j] |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
136 l.append(ctx) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
137 l.reverse() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
138 for e in l: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
139 yield e |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
140 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
141 for ctx in revgen(): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
142 miss = 0 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
143 for q in qw: |
15727
917f263eeb26
i18n: use "encoding.lower()" to normalize string in hgweb search query
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15528
diff
changeset
|
144 if not (q in lower(ctx.user()) or |
917f263eeb26
i18n: use "encoding.lower()" to normalize string in hgweb search query
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15528
diff
changeset
|
145 q in lower(ctx.description()) or |
917f263eeb26
i18n: use "encoding.lower()" to normalize string in hgweb search query
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15528
diff
changeset
|
146 q in lower(" ".join(ctx.files()))): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
147 miss = 1 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
148 break |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
149 if miss: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
150 continue |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
151 |
6659
bc553c6d1ef9
webcommands: fix increments lost by 894875eae49b
Andrew Beekhof <beekhof@gmail.com>
parents:
6657
diff
changeset
|
152 count += 1 |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
153 n = ctx.node() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
154 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
|
155 files = webutil.listfilediffs(tmpl, ctx.files(), n, web.maxfiles) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
156 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
157 yield tmpl('searchentry', |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
158 parity=parity.next(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
159 author=ctx.user(), |
7671
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
160 parent=webutil.parents(ctx), |
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
161 child=webutil.children(ctx), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
162 changelogtag=showtags, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
163 desc=ctx.description(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
164 date=ctx.date(), |
7311
de9c87fe1620
hgweb: move another utility function into the webutil module
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7310
diff
changeset
|
165 files=files, |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
166 rev=ctx.rev(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
167 node=hex(n), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
168 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
|
169 bookmarks=webutil.nodebookmarksdict(web.repo, n), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
170 inbranch=webutil.nodeinbranch(web.repo, ctx), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
171 branches=webutil.nodebranchdict(web.repo, ctx)) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
172 |
10247
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
173 if count >= revcount: |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
174 break |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
175 |
12059
0de6cfdcaad8
webcommands: remove unncessary access to repo.changelog
Patrick Mezard <pmezard@gmail.com>
parents:
11332
diff
changeset
|
176 tip = web.repo['tip'] |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
177 parity = paritygen(web.stripecount) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
178 |
12059
0de6cfdcaad8
webcommands: remove unncessary access to repo.changelog
Patrick Mezard <pmezard@gmail.com>
parents:
11332
diff
changeset
|
179 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
|
180 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
|
181 morevars=morevars, lessvars=lessvars) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
182 |
10247
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
183 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
|
184 |
5915
d0576d065993
Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents:
5890
diff
changeset
|
185 if 'node' in req.form: |
6392
2540521dc7c1
hgweb: separate out utility functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6368
diff
changeset
|
186 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
|
187 else: |
5915
d0576d065993
Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents:
5890
diff
changeset
|
188 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
|
189 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
|
190 else: |
6750
fb42030d79d6
add __len__ and __iter__ methods to repo and revlog
Matt Mackall <mpm@selenic.com>
parents:
6747
diff
changeset
|
191 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
|
192 try: |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6720
diff
changeset
|
193 ctx = web.repo[hi] |
7637 | 194 except error.RepoError: |
10247
e8c7410371e0
hgweb: add less/more links for search logs (issue1972)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10246
diff
changeset
|
195 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
|
196 |
18402
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
197 def changelist(latestonly, **map): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
198 l = [] # build a list in forward order for efficiency |
18427
56ca4443a343
hgweb: use changelog for iteration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18409
diff
changeset
|
199 revs = [] |
56ca4443a343
hgweb: use changelog for iteration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18409
diff
changeset
|
200 if start < end: |
56ca4443a343
hgweb: use changelog for iteration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18409
diff
changeset
|
201 revs = web.repo.changelog.revs(start, end - 1) |
18402
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
202 if latestonly: |
18427
56ca4443a343
hgweb: use changelog for iteration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18409
diff
changeset
|
203 for r in revs: |
56ca4443a343
hgweb: use changelog for iteration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18409
diff
changeset
|
204 pass |
56ca4443a343
hgweb: use changelog for iteration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18409
diff
changeset
|
205 revs = (r,) |
18402
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
206 for i in revs: |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6720
diff
changeset
|
207 ctx = web.repo[i] |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
208 n = ctx.node() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
209 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
|
210 files = webutil.listfilediffs(tmpl, ctx.files(), n, web.maxfiles) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
211 |
18319
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
212 l.append({"parity": parity.next(), |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
213 "author": ctx.user(), |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
214 "parent": webutil.parents(ctx, i - 1), |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
215 "child": webutil.children(ctx, i + 1), |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
216 "changelogtag": showtags, |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
217 "desc": ctx.description(), |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
218 "date": ctx.date(), |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
219 "files": files, |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
220 "rev": i, |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
221 "node": hex(n), |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
222 "tags": webutil.nodetagsdict(web.repo, n), |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
223 "bookmarks": webutil.nodebookmarksdict(web.repo, n), |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
224 "inbranch": webutil.nodeinbranch(web.repo, ctx), |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
225 "branches": webutil.nodebranchdict(web.repo, ctx) |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
226 }) |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
227 for e in reversed(l): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
228 yield e |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
229 |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
230 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
|
231 if 'revcount' in req.form: |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
232 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
|
233 revcount = max(revcount, 1) |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
234 tmpl.defaults['sessionvars']['revcount'] = revcount |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
235 |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
236 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
|
237 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
|
238 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
|
239 morevars['revcount'] = revcount * 2 |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
240 |
12059
0de6cfdcaad8
webcommands: remove unncessary access to repo.changelog
Patrick Mezard <pmezard@gmail.com>
parents:
11332
diff
changeset
|
241 count = len(web.repo) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
242 pos = ctx.rev() |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
243 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
|
244 end = min(count, start + revcount) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
245 pos = end - 1 |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
246 parity = paritygen(web.stripecount, offset=start - end) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
247 |
18409
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
248 changenav = webutil.revnav(web.repo).gen(pos, revcount, count) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
249 |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
250 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
|
251 node=ctx.hex(), rev=pos, changesets=count, |
18402
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
252 entries=lambda **x: changelist(latestonly=False, **x), |
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
253 latestentry=lambda **x: changelist(latestonly=True, **x), |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
254 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
|
255 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
|
256 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
257 def shortlog(web, req, tmpl): |
5964
1cd1582ef25f
hgweb: centralize req.write() calls
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5963
diff
changeset
|
258 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
|
259 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
260 def changeset(web, req, tmpl): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
261 ctx = webutil.changectx(web.repo, req) |
17991
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17933
diff
changeset
|
262 basectx = webutil.basechangectx(web.repo, req) |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17933
diff
changeset
|
263 if basectx is None: |
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17933
diff
changeset
|
264 basectx = ctx.p1() |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7305
diff
changeset
|
265 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
|
266 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
|
267 ctx.node()) |
7410
f1111704061e
coal/paper: show branch name in changeset view
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7409
diff
changeset
|
268 showbranch = webutil.nodebranchnodefault(ctx) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
269 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
270 files = [] |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
271 parity = paritygen(web.stripecount) |
16308
2695aaf4eb72
hgweb: add block numbers to diff regions and related links
Paul Boddie <paul@boddie.org.uk>
parents:
16129
diff
changeset
|
272 for blockno, f in enumerate(ctx.files()): |
7182
295af5bc1bcc
hgweb: remove links to non-existent file versions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7107
diff
changeset
|
273 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
|
274 files.append(tmpl(template, |
16308
2695aaf4eb72
hgweb: add block numbers to diff regions and related links
Paul Boddie <paul@boddie.org.uk>
parents:
16129
diff
changeset
|
275 node=ctx.hex(), file=f, blockno=blockno + 1, |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
276 parity=parity.next())) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
277 |
9402
5d49fdef6fd0
hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8842
diff
changeset
|
278 style = web.config('web', 'style', 'paper') |
5d49fdef6fd0
hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8842
diff
changeset
|
279 if 'style' in req.form: |
5d49fdef6fd0
hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8842
diff
changeset
|
280 style = req.form['style'][0] |
5d49fdef6fd0
hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8842
diff
changeset
|
281 |
14490
1d3e2349304a
web: provide diffstat to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14055
diff
changeset
|
282 parity = paritygen(web.stripecount) |
17991
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17933
diff
changeset
|
283 diffs = webutil.diffs(web.repo, tmpl, ctx, basectx, None, parity, style) |
14490
1d3e2349304a
web: provide diffstat to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14055
diff
changeset
|
284 |
1d3e2349304a
web: provide diffstat to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14055
diff
changeset
|
285 parity = paritygen(web.stripecount) |
17991
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17933
diff
changeset
|
286 diffstatgen = webutil.diffstatgen(ctx, basectx) |
14570
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14514
diff
changeset
|
287 diffstat = webutil.diffstat(tmpl, ctx, diffstatgen, parity) |
14490
1d3e2349304a
web: provide diffstat to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14055
diff
changeset
|
288 |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
289 return tmpl('changeset', |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
290 diff=diffs, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
291 rev=ctx.rev(), |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7305
diff
changeset
|
292 node=ctx.hex(), |
7671
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
293 parent=webutil.parents(ctx), |
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
294 child=webutil.children(ctx), |
17991
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17933
diff
changeset
|
295 currentbaseline=basectx.hex(), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
296 changesettag=showtags, |
13596
270f57d35525
hgweb: add display of bookmarks for changelog and changeset
Alexander Solovyov <alexander@solovyov.net>
parents:
13199
diff
changeset
|
297 changesetbookmark=showbookmarks, |
7410
f1111704061e
coal/paper: show branch name in changeset view
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7409
diff
changeset
|
298 changesetbranch=showbranch, |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
299 author=ctx.user(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
300 desc=ctx.description(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
301 date=ctx.date(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
302 files=files, |
14570
9f908ef5a595
web: provide diff summary to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14514
diff
changeset
|
303 diffsummary=lambda **x: webutil.diffsummary(diffstatgen), |
14490
1d3e2349304a
web: provide diffstat to the changeset page
Steven Brown <StevenGBrown@gmail.com>
parents:
14055
diff
changeset
|
304 diffstat=diffstat, |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7305
diff
changeset
|
305 archives=web.archivelist(ctx.hex()), |
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7305
diff
changeset
|
306 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
|
307 bookmarks=webutil.nodebookmarksdict(web.repo, ctx.node()), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
308 branch=webutil.nodebranchnodefault(ctx), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
309 inbranch=webutil.nodeinbranch(web.repo, ctx), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
310 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
|
311 |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
312 rev = changeset |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
313 |
16448
e6b45e9a75dc
hgweb: add hook for remapping repository path into virtual paths
Martin Geisler <mg@lazybytes.net>
parents:
16308
diff
changeset
|
314 def decodepath(path): |
e6b45e9a75dc
hgweb: add hook for remapping repository path into virtual paths
Martin Geisler <mg@lazybytes.net>
parents:
16308
diff
changeset
|
315 """Hook for mapping a path in the repository to a path in the |
e6b45e9a75dc
hgweb: add hook for remapping repository path into virtual paths
Martin Geisler <mg@lazybytes.net>
parents:
16308
diff
changeset
|
316 working copy. |
e6b45e9a75dc
hgweb: add hook for remapping repository path into virtual paths
Martin Geisler <mg@lazybytes.net>
parents:
16308
diff
changeset
|
317 |
e6b45e9a75dc
hgweb: add hook for remapping repository path into virtual paths
Martin Geisler <mg@lazybytes.net>
parents:
16308
diff
changeset
|
318 Extensions (e.g., largefiles) can override this to remap files in |
e6b45e9a75dc
hgweb: add hook for remapping repository path into virtual paths
Martin Geisler <mg@lazybytes.net>
parents:
16308
diff
changeset
|
319 the virtual file system presented by the manifest command below.""" |
e6b45e9a75dc
hgweb: add hook for remapping repository path into virtual paths
Martin Geisler <mg@lazybytes.net>
parents:
16308
diff
changeset
|
320 return path |
e6b45e9a75dc
hgweb: add hook for remapping repository path into virtual paths
Martin Geisler <mg@lazybytes.net>
parents:
16308
diff
changeset
|
321 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
322 def manifest(web, req, tmpl): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
323 ctx = webutil.changectx(web.repo, req) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
324 path = webutil.cleanpath(web.repo, req.form.get('file', [''])[0]) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
325 mf = ctx.manifest() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
326 node = ctx.node() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
327 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
328 files = {} |
7305
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
329 dirs = {} |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
330 parity = paritygen(web.stripecount) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
331 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
332 if path and path[-1] != "/": |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
333 path += "/" |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
334 l = len(path) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
335 abspath = "/" + path |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
336 |
16448
e6b45e9a75dc
hgweb: add hook for remapping repository path into virtual paths
Martin Geisler <mg@lazybytes.net>
parents:
16308
diff
changeset
|
337 for full, n in mf.iteritems(): |
e6b45e9a75dc
hgweb: add hook for remapping repository path into virtual paths
Martin Geisler <mg@lazybytes.net>
parents:
16308
diff
changeset
|
338 # the virtual path (working copy path) used for the full |
e6b45e9a75dc
hgweb: add hook for remapping repository path into virtual paths
Martin Geisler <mg@lazybytes.net>
parents:
16308
diff
changeset
|
339 # (repository) path |
e6b45e9a75dc
hgweb: add hook for remapping repository path into virtual paths
Martin Geisler <mg@lazybytes.net>
parents:
16308
diff
changeset
|
340 f = decodepath(full) |
e6b45e9a75dc
hgweb: add hook for remapping repository path into virtual paths
Martin Geisler <mg@lazybytes.net>
parents:
16308
diff
changeset
|
341 |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
342 if f[:l] != path: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
343 continue |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
344 remain = f[l:] |
7305
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
345 elements = remain.split('/') |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
346 if len(elements) == 1: |
16448
e6b45e9a75dc
hgweb: add hook for remapping repository path into virtual paths
Martin Geisler <mg@lazybytes.net>
parents:
16308
diff
changeset
|
347 files[remain] = full |
7305
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
348 else: |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
349 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
|
350 for elem in elements[0:-1]: |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
351 if elem not in h: |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
352 h[elem] = {} |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
353 h = h[elem] |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
354 if len(h) > 1: |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
355 break |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
356 h[None] = None # denotes files present |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
357 |
7565
5f162f61e479
hgweb: fix problems with empty repositories
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7434
diff
changeset
|
358 if mf and not files and not dirs: |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
359 raise ErrorResponse(HTTP_NOT_FOUND, 'path not found: ' + path) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
360 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
361 def filelist(**map): |
8209
a1a5a57efe90
replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents:
7966
diff
changeset
|
362 for f in sorted(files): |
7305
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
363 full = files[f] |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
364 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
365 fctx = ctx.filectx(full) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
366 yield {"file": full, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
367 "parity": parity.next(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
368 "basename": f, |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6720
diff
changeset
|
369 "date": fctx.date(), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
370 "size": fctx.size(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
371 "permissions": mf.flags(full)} |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
372 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
373 def dirlist(**map): |
8209
a1a5a57efe90
replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents:
7966
diff
changeset
|
374 for d in sorted(dirs): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
375 |
7305
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
376 emptydirs = [] |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
377 h = dirs[d] |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
378 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
|
379 k, v = h.items()[0] |
7305
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
380 if v: |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
381 emptydirs.append(k) |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
382 h = v |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
383 |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
384 path = "%s%s" % (abspath, d) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
385 yield {"parity": parity.next(), |
7305
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
386 "path": path, |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
387 "emptydirs": "/".join(emptydirs), |
c21d236ca897
hgweb: descend empty directories in web view
Ry4an Brase <ry4an-hg@ry4an.org>
parents:
7300
diff
changeset
|
388 "basename": d} |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
389 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
390 return tmpl("manifest", |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
391 rev=ctx.rev(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
392 node=hex(node), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
393 path=abspath, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
394 up=webutil.up(abspath), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
395 upparity=parity.next(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
396 fentries=filelist, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
397 dentries=dirlist, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
398 archives=web.archivelist(hex(node)), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
399 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
|
400 bookmarks=webutil.nodebookmarksdict(web.repo, node), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
401 inbranch=webutil.nodeinbranch(web.repo, ctx), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
402 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
|
403 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
404 def tags(web, req, tmpl): |
18029
109a6a9dcca8
hgweb: fix iterator reuse in atom feed generation
Matt Mackall <mpm@selenic.com>
parents:
17322
diff
changeset
|
405 i = list(reversed(web.repo.tagslist())) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
406 parity = paritygen(web.stripecount) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
407 |
18402
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
408 def entries(notip, latestonly, **map): |
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
409 t = i |
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
410 if notip: |
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
411 t = [(k, n) for k, n in i if k != "tip"] |
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
412 if latestonly: |
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
413 t = t[:1] |
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
414 for k, n in t: |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
415 yield {"parity": parity.next(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
416 "tag": k, |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6720
diff
changeset
|
417 "date": web.repo[n].date(), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
418 "node": hex(n)} |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
419 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
420 return tmpl("tags", |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
421 node=hex(web.repo.changelog.tip()), |
18402
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
422 entries=lambda **x: entries(False, False, **x), |
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
423 entriesnotip=lambda **x: entries(True, False, **x), |
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
424 latestentry=lambda **x: entries(True, True, **x)) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
425 |
13597
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
426 def bookmarks(web, req, tmpl): |
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
427 i = web.repo._bookmarks.items() |
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
428 parity = paritygen(web.stripecount) |
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
429 |
18402
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
430 def entries(latestonly, **map): |
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
431 if latestonly: |
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
432 t = [min(i)] |
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
433 else: |
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
434 t = sorted(i) |
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
435 for k, n in t: |
13597
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
436 yield {"parity": parity.next(), |
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
437 "bookmark": k, |
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
438 "date": web.repo[n].date(), |
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
439 "node": hex(n)} |
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
440 |
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
441 return tmpl("bookmarks", |
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
442 node=hex(web.repo.changelog.tip()), |
18402
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
443 entries=lambda **x: entries(latestonly=False, **x), |
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
444 latestentry=lambda **x: entries(latestonly=True, **x)) |
13597
38c9837b1f75
hgweb: add separate page with bookmarks listing
Alexander Solovyov <alexander@solovyov.net>
parents:
13596
diff
changeset
|
445 |
8352
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
446 def branches(web, req, tmpl): |
18030
ebc0fa067c07
hgweb: avoid generator exhaustion with branches
Matt Mackall <mpm@selenic.com>
parents:
18029
diff
changeset
|
447 tips = [] |
8796
2bcef677a6c3
localrepo: remove 'closed' argument to heads(...) function
John Mulligan <phlogistonjohn@asynchrono.us>
parents:
8713
diff
changeset
|
448 heads = web.repo.heads() |
8352
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
449 parity = paritygen(web.stripecount) |
16720
e825a89de5d7
context: add changectx.closesbranch() method
Brodie Rao <brodie@sf.io>
parents:
16719
diff
changeset
|
450 sortkey = lambda ctx: (not ctx.closesbranch(), ctx.rev()) |
8352
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
451 |
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
452 def entries(limit, **map): |
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
453 count = 0 |
18030
ebc0fa067c07
hgweb: avoid generator exhaustion with branches
Matt Mackall <mpm@selenic.com>
parents:
18029
diff
changeset
|
454 if not tips: |
ebc0fa067c07
hgweb: avoid generator exhaustion with branches
Matt Mackall <mpm@selenic.com>
parents:
18029
diff
changeset
|
455 for t, n in web.repo.branchtags().iteritems(): |
ebc0fa067c07
hgweb: avoid generator exhaustion with branches
Matt Mackall <mpm@selenic.com>
parents:
18029
diff
changeset
|
456 tips.append(web.repo[n]) |
8713
de6bb29e208a
hgweb: allow distinction between open/closed branches on branches page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8390
diff
changeset
|
457 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
|
458 if limit > 0 and count >= limit: |
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
459 return |
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
460 count += 1 |
14771
0cc66f13bea0
hgweb: treat branch attribute `closed' as more important than `inactive'
Jesse Long <jpl@unknown.za.net>
parents:
14570
diff
changeset
|
461 if not web.repo.branchheads(ctx.branch()): |
0cc66f13bea0
hgweb: treat branch attribute `closed' as more important than `inactive'
Jesse Long <jpl@unknown.za.net>
parents:
14570
diff
changeset
|
462 status = 'closed' |
0cc66f13bea0
hgweb: treat branch attribute `closed' as more important than `inactive'
Jesse Long <jpl@unknown.za.net>
parents:
14570
diff
changeset
|
463 elif ctx.node() not in heads: |
8796
2bcef677a6c3
localrepo: remove 'closed' argument to heads(...) function
John Mulligan <phlogistonjohn@asynchrono.us>
parents:
8713
diff
changeset
|
464 status = 'inactive' |
2bcef677a6c3
localrepo: remove 'closed' argument to heads(...) function
John Mulligan <phlogistonjohn@asynchrono.us>
parents:
8713
diff
changeset
|
465 else: |
2bcef677a6c3
localrepo: remove 'closed' argument to heads(...) function
John Mulligan <phlogistonjohn@asynchrono.us>
parents:
8713
diff
changeset
|
466 status = 'open' |
8352
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
467 yield {'parity': parity.next(), |
8354
418ea63f00fb
hgweb: use context api in branches webcommand
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8352
diff
changeset
|
468 'branch': ctx.branch(), |
8713
de6bb29e208a
hgweb: allow distinction between open/closed branches on branches page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8390
diff
changeset
|
469 'status': status, |
8354
418ea63f00fb
hgweb: use context api in branches webcommand
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8352
diff
changeset
|
470 'node': ctx.hex(), |
418ea63f00fb
hgweb: use context api in branches webcommand
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8352
diff
changeset
|
471 'date': ctx.date()} |
8352
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
472 |
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
473 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
|
474 entries=lambda **x: entries(0, **x), |
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
475 latestentry=lambda **x: entries(1, **x)) |
eefcb59d44d6
webcommands: add 'branches' command, similar to 'tags'
Sune Foldager <cryo@cyanite.org>
parents:
8236
diff
changeset
|
476 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
477 def summary(web, req, tmpl): |
17261
c0068b058fcd
webcommands: do not modify repo.tagslist()
Patrick Mezard <patrick@mezard.eu>
parents:
17202
diff
changeset
|
478 i = reversed(web.repo.tagslist()) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
479 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
480 def tagentries(**map): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
481 parity = paritygen(web.stripecount) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
482 count = 0 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
483 for k, n in i: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
484 if k == "tip": # skip tip |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
485 continue |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
486 |
6659
bc553c6d1ef9
webcommands: fix increments lost by 894875eae49b
Andrew Beekhof <beekhof@gmail.com>
parents:
6657
diff
changeset
|
487 count += 1 |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
488 if count > 10: # limit to 10 tags |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
489 break |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
490 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
491 yield tmpl("tagentry", |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
492 parity=parity.next(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
493 tag=k, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
494 node=hex(n), |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6720
diff
changeset
|
495 date=web.repo[n].date()) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
496 |
13924
ea726c97c1b6
hgweb: add bookmarks listing to summary page of gitweb/monoblue styles
Yuya Nishihara <yuya@tcha.org>
parents:
13923
diff
changeset
|
497 def bookmarks(**map): |
ea726c97c1b6
hgweb: add bookmarks listing to summary page of gitweb/monoblue styles
Yuya Nishihara <yuya@tcha.org>
parents:
13923
diff
changeset
|
498 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
|
499 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
|
500 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
|
501 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
|
502 'bookmark': k, |
ea726c97c1b6
hgweb: add bookmarks listing to summary page of gitweb/monoblue styles
Yuya Nishihara <yuya@tcha.org>
parents:
13923
diff
changeset
|
503 '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
|
504 'node': hex(n)} |
ea726c97c1b6
hgweb: add bookmarks listing to summary page of gitweb/monoblue styles
Yuya Nishihara <yuya@tcha.org>
parents:
13923
diff
changeset
|
505 |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
506 def branches(**map): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
507 parity = paritygen(web.stripecount) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
508 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
509 b = web.repo.branchtags() |
7622
4dd7b28003d2
use dict.iteritems() rather than dict.items()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7612
diff
changeset
|
510 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
|
511 for r, n, t in sorted(l): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
512 yield {'parity': parity.next(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
513 'branch': t, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
514 'node': hex(n), |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6720
diff
changeset
|
515 'date': web.repo[n].date()} |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
516 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
517 def changelist(**map): |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
518 parity = paritygen(web.stripecount, offset=start - end) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
519 l = [] # build a list in forward order for efficiency |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
520 for i in xrange(start, end): |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6720
diff
changeset
|
521 ctx = web.repo[i] |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
522 n = ctx.node() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
523 hn = hex(n) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
524 |
18319
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
525 l.append(tmpl( |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
526 'shortlogentry', |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
527 parity=parity.next(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
528 author=ctx.user(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
529 desc=ctx.description(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
530 date=ctx.date(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
531 rev=i, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
532 node=hn, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
533 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
|
534 bookmarks=webutil.nodebookmarksdict(web.repo, n), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
535 inbranch=webutil.nodeinbranch(web.repo, ctx), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
536 branches=webutil.nodebranchdict(web.repo, ctx))) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
537 |
18319
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
538 l.reverse() |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
539 yield l |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
540 |
12059
0de6cfdcaad8
webcommands: remove unncessary access to repo.changelog
Patrick Mezard <pmezard@gmail.com>
parents:
11332
diff
changeset
|
541 tip = web.repo['tip'] |
0de6cfdcaad8
webcommands: remove unncessary access to repo.changelog
Patrick Mezard <pmezard@gmail.com>
parents:
11332
diff
changeset
|
542 count = len(web.repo) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
543 start = max(0, count - web.maxchanges) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
544 end = min(count, start + web.maxchanges) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
545 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
546 return tmpl("summary", |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
547 desc=web.config("web", "description", "unknown"), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
548 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
|
549 lastchange=tip.date(), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
550 tags=tagentries, |
13924
ea726c97c1b6
hgweb: add bookmarks listing to summary page of gitweb/monoblue styles
Yuya Nishihara <yuya@tcha.org>
parents:
13923
diff
changeset
|
551 bookmarks=bookmarks, |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
552 branches=branches, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
553 shortlog=changelist, |
12059
0de6cfdcaad8
webcommands: remove unncessary access to repo.changelog
Patrick Mezard <pmezard@gmail.com>
parents:
11332
diff
changeset
|
554 node=tip.hex(), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
555 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
|
556 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
557 def filediff(web, req, tmpl): |
7183
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
558 fctx, ctx = None, None |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
559 try: |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
560 fctx = webutil.filectx(web.repo, req) |
7280
810ca383da9c
remove unused variables
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7183
diff
changeset
|
561 except LookupError: |
7183
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
562 ctx = webutil.changectx(web.repo, req) |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
563 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
|
564 if path not in ctx.files(): |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
565 raise |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
566 |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
567 if fctx is not None: |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
568 n = fctx.node() |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
569 path = fctx.path() |
16722
7bf48bc7de23
hgweb: fix filediff base calculation
Matt Mackall <mpm@selenic.com>
parents:
16469
diff
changeset
|
570 ctx = fctx.changectx() |
7183
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
571 else: |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
572 n = ctx.node() |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
573 # path already defined in except clause |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
574 |
7310
bd522d09d5e3
hgweb: move the diffs() generator into webutil
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7305
diff
changeset
|
575 parity = paritygen(web.stripecount) |
9402
5d49fdef6fd0
hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8842
diff
changeset
|
576 style = web.config('web', 'style', 'paper') |
5d49fdef6fd0
hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8842
diff
changeset
|
577 if 'style' in req.form: |
5d49fdef6fd0
hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8842
diff
changeset
|
578 style = req.form['style'][0] |
5d49fdef6fd0
hgweb: show diff header line in raw diffs
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8842
diff
changeset
|
579 |
17991
d605a82cf189
hgweb: display diff for a changeset against any parents (issue2810)
Weiwen <weiwen@fb.com>
parents:
17933
diff
changeset
|
580 diffs = webutil.diffs(web.repo, tmpl, ctx, None, [path], parity, style) |
7183
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
581 rename = fctx and webutil.renamelink(fctx) or [] |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
582 ctx = fctx and fctx or ctx |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
583 return tmpl("filediff", |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
584 file=path, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
585 node=hex(n), |
7183
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
586 rev=ctx.rev(), |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
587 date=ctx.date(), |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
588 desc=ctx.description(), |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
589 author=ctx.user(), |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
590 rename=rename, |
099b4f9be5ab
hgweb: working diff for removed files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7182
diff
changeset
|
591 branch=webutil.nodebranchnodefault(ctx), |
7671
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
592 parent=webutil.parents(ctx), |
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
593 child=webutil.children(ctx), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
594 diff=diffs) |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
595 |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
596 diff = filediff |
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
597 |
17202
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
598 def comparison(web, req, tmpl): |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
599 ctx = webutil.changectx(web.repo, req) |
17289
f2d6b4f8e78c
hgweb: avoid traceback when file or node parameters are missing
Ross Lagerwall <rosslagerwall@gmail.com>
parents:
17261
diff
changeset
|
600 if 'file' not in req.form: |
f2d6b4f8e78c
hgweb: avoid traceback when file or node parameters are missing
Ross Lagerwall <rosslagerwall@gmail.com>
parents:
17261
diff
changeset
|
601 raise ErrorResponse(HTTP_NOT_FOUND, 'file not given') |
17202
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
602 path = webutil.cleanpath(web.repo, req.form['file'][0]) |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
603 rename = path in ctx and webutil.renamelink(ctx[path]) or [] |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
604 |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
605 parsecontext = lambda v: v == 'full' and -1 or int(v) |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
606 if 'context' in req.form: |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
607 context = parsecontext(req.form['context'][0]) |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
608 else: |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
609 context = parsecontext(web.config('web', 'comparisoncontext', '5')) |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
610 |
17302
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
611 def filelines(f): |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
612 if binary(f.data()): |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
613 mt = mimetypes.guess_type(f.path())[0] |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
614 if not mt: |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
615 mt = 'application/octet-stream' |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
616 return [_('(binary file %s, hash: %s)') % (mt, hex(f.filenode()))] |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
617 return f.data().splitlines() |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
618 |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
619 if path in ctx: |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
620 fctx = ctx[path] |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
621 rightrev = fctx.filerev() |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
622 rightnode = fctx.filenode() |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
623 rightlines = filelines(fctx) |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
624 parents = fctx.parents() |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
625 if not parents: |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
626 leftrev = -1 |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
627 leftnode = nullid |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
628 leftlines = () |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
629 else: |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
630 pfctx = parents[0] |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
631 leftrev = pfctx.filerev() |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
632 leftnode = pfctx.filenode() |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
633 leftlines = filelines(pfctx) |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
634 else: |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
635 rightrev = -1 |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
636 rightnode = nullid |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
637 rightlines = () |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
638 fctx = ctx.parents()[0][path] |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
639 leftrev = fctx.filerev() |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
640 leftnode = fctx.filenode() |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
641 leftlines = filelines(fctx) |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
642 |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
643 comparison = webutil.compare(tmpl, context, leftlines, rightlines) |
17202
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
644 return tmpl('filecomparison', |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
645 file=path, |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
646 node=hex(ctx.node()), |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
647 rev=ctx.rev(), |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
648 date=ctx.date(), |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
649 desc=ctx.description(), |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
650 author=ctx.user(), |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
651 rename=rename, |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
652 branch=webutil.nodebranchnodefault(ctx), |
17303
06217d3cf8d9
hgweb: fixes invalid parents / children in comparison
wujek srujek <wujek.srujek@googlemail.com>
parents:
17302
diff
changeset
|
653 parent=webutil.parents(fctx), |
06217d3cf8d9
hgweb: fixes invalid parents / children in comparison
wujek srujek <wujek.srujek@googlemail.com>
parents:
17302
diff
changeset
|
654 child=webutil.children(fctx), |
17302
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
655 leftrev=leftrev, |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
656 leftnode=hex(leftnode), |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
657 rightrev=rightrev, |
5c64ce6168da
hgweb: fixes traceback for invalid files by removing top-level template
wujek srujek <wujek.srujek@googlemail.com>
parents:
17289
diff
changeset
|
658 rightnode=hex(rightnode), |
17202
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
659 comparison=comparison) |
1ae119269ddc
hgweb: side-by-side comparison functionality
wujek srujek
parents:
17146
diff
changeset
|
660 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
661 def annotate(web, req, tmpl): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
662 fctx = webutil.filectx(web.repo, req) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
663 f = fctx.path() |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
664 parity = paritygen(web.stripecount) |
15528
a84698badf0b
annotate: support diff whitespace filtering flags (issue3030)
Patrick Mezard <pmezard@gmail.com>
parents:
15004
diff
changeset
|
665 diffopts = patch.diffopts(web.repo.ui, untrusted=True, section='annotate') |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
666 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
667 def annotate(**map): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
668 last = None |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
669 if binary(fctx.data()): |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
670 mt = (mimetypes.guess_type(fctx.path())[0] |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
671 or 'application/octet-stream') |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
672 lines = enumerate([((fctx.filectx(fctx.filerev()), 1), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
673 '(binary:%s)' % mt)]) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
674 else: |
15528
a84698badf0b
annotate: support diff whitespace filtering flags (issue3030)
Patrick Mezard <pmezard@gmail.com>
parents:
15004
diff
changeset
|
675 lines = enumerate(fctx.annotate(follow=True, linenumber=True, |
a84698badf0b
annotate: support diff whitespace filtering flags (issue3030)
Patrick Mezard <pmezard@gmail.com>
parents:
15004
diff
changeset
|
676 diffopts=diffopts)) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
677 for lineno, ((f, targetline), l) in lines: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
678 fnode = f.filenode() |
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 if last != fnode: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
681 last = fnode |
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 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
|
684 "node": f.hex(), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
685 "rev": f.rev(), |
6564
ccc2481e3954
webcommands: pass full author to annotate, fix templates (issue 1054)
Patrick Mezard <pmezard@gmail.com>
parents:
6437
diff
changeset
|
686 "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
|
687 "desc": f.description(), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
688 "file": f.path(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
689 "targetline": targetline, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
690 "line": l, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
691 "lineid": "l%d" % (lineno + 1), |
13199
a38df1250945
hgweb: added revision date to annotate line data
Oli Thissen <oli@tonick.net>
parents:
12696
diff
changeset
|
692 "linenumber": "% 6d" % (lineno + 1), |
a38df1250945
hgweb: added revision date to annotate line data
Oli Thissen <oli@tonick.net>
parents:
12696
diff
changeset
|
693 "revdate": f.date()} |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
694 |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
695 return tmpl("fileannotate", |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
696 file=f, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
697 annotate=annotate, |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
698 path=webutil.up(f), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
699 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
|
700 node=fctx.hex(), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
701 author=fctx.user(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
702 date=fctx.date(), |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
703 desc=fctx.description(), |
6434
62e0bb41e682
hgweb: minor improvements for new web style
Matt Mackall <mpm@selenic.com>
parents:
6410
diff
changeset
|
704 rename=webutil.renamelink(fctx), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
705 branch=webutil.nodebranchnodefault(fctx), |
7671
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
706 parent=webutil.parents(fctx), |
06cf09c822c4
hgweb: simplify parents/children generation code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7637
diff
changeset
|
707 child=webutil.children(fctx), |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
708 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
|
709 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
710 def filelog(web, req, tmpl): |
7300
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
711 |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
712 try: |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
713 fctx = webutil.filectx(web.repo, req) |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
714 f = fctx.path() |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
715 fl = fctx.filelog() |
7633 | 716 except error.LookupError: |
7300
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
717 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
|
718 fl = web.repo.file(f) |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
719 numrevs = len(fl) |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
720 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
|
721 raise |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
722 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
|
723 first = fl.linkrev(0) |
7300
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
724 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
|
725 raise |
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
726 frev = numrevs - 1 |
7361
9fe97eea5510
linkrev: take a revision number rather than a hash
Matt Mackall <mpm@selenic.com>
parents:
7345
diff
changeset
|
727 while fl.linkrev(frev) > rev: |
7300
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
728 frev -= 1 |
7361
9fe97eea5510
linkrev: take a revision number rather than a hash
Matt Mackall <mpm@selenic.com>
parents:
7345
diff
changeset
|
729 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
|
730 |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
731 revcount = web.maxshortchanges |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
732 if 'revcount' in req.form: |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
733 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
|
734 revcount = max(revcount, 1) |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
735 tmpl.defaults['sessionvars']['revcount'] = revcount |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
736 |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
737 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
|
738 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
|
739 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
|
740 morevars['revcount'] = revcount * 2 |
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
741 |
7300
591767e6ea7a
hgweb: conditionally show file logs for deleted files
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7288
diff
changeset
|
742 count = fctx.filerev() + 1 |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
743 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
|
744 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
|
745 parity = paritygen(web.stripecount, offset=start - end) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
746 |
18402
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
747 def entries(latestonly, **map): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
748 l = [] |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
749 |
7612
069b29656401
web: use the correct filectx in filelog
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7565
diff
changeset
|
750 repo = web.repo |
18427
56ca4443a343
hgweb: use changelog for iteration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18409
diff
changeset
|
751 revs = repo.changelog.revs(start, end - 1) |
18402
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
752 if latestonly: |
18427
56ca4443a343
hgweb: use changelog for iteration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18409
diff
changeset
|
753 for r in revs: |
56ca4443a343
hgweb: use changelog for iteration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18409
diff
changeset
|
754 pass |
56ca4443a343
hgweb: use changelog for iteration
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18409
diff
changeset
|
755 revs = (r,) |
18402
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
756 for i in revs: |
7612
069b29656401
web: use the correct filectx in filelog
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
7565
diff
changeset
|
757 iterfctx = fctx.filectx(i) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
758 |
18319
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
759 l.append({"parity": parity.next(), |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
760 "filerev": i, |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
761 "file": f, |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
762 "node": iterfctx.hex(), |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
763 "author": iterfctx.user(), |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
764 "date": iterfctx.date(), |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
765 "rename": webutil.renamelink(iterfctx), |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
766 "parent": webutil.parents(iterfctx), |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
767 "child": webutil.children(iterfctx), |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
768 "desc": iterfctx.description(), |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
769 "tags": webutil.nodetagsdict(repo, iterfctx.node()), |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
770 "bookmarks": webutil.nodebookmarksdict( |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
771 repo, iterfctx.node()), |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
772 "branch": webutil.nodebranchnodefault(iterfctx), |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
773 "inbranch": webutil.nodeinbranch(repo, iterfctx), |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
774 "branches": webutil.nodebranchdict(repo, iterfctx)}) |
e350ce798b63
hgweb: no do not use listinsert(0, ...)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18037
diff
changeset
|
775 for e in reversed(l): |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
776 yield e |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
777 |
18409
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
778 revnav = webutil.filerevnav(web.repo, fctx.path()) |
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
779 nav = revnav.gen(end - 1, revcount, count) |
14055
421d56a055fd
drop {short,hex}(ctx.node()) calls in favor of ctx methods
Alexander Solovyov <alexander@solovyov.net>
parents:
14043
diff
changeset
|
780 return tmpl("filelog", file=f, node=fctx.hex(), nav=nav, |
18402
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
781 entries=lambda **x: entries(latestonly=False, **x), |
bfba6d954108
hgweb: `limit` argument is actually `latestonly` renames and enforce
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18352
diff
changeset
|
782 latestentry=lambda **x: entries(latestonly=True, **x), |
10246
b9d02695bde4
hgweb: add less/more links to shortlog/filelog nav
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
10245
diff
changeset
|
783 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
|
784 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
785 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
|
786 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
|
787 allowed = web.configlist("web", "allow_archive") |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
788 key = req.form['node'][0] |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
789 |
7029
b84d27386285
hgweb: Respond with HTTP 403 for disabled archive types instead of 404
Rocco Rutte <pdmef@gmx.net>
parents:
6981
diff
changeset
|
790 if type_ not in web.archives: |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
791 msg = 'Unsupported archive type: %s' % type_ |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
792 raise ErrorResponse(HTTP_NOT_FOUND, msg) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
793 |
7029
b84d27386285
hgweb: Respond with HTTP 403 for disabled archive types instead of 404
Rocco Rutte <pdmef@gmx.net>
parents:
6981
diff
changeset
|
794 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
|
795 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
|
796 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
|
797 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
|
798 |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
799 reponame = re.sub(r"\W+", "-", os.path.basename(web.reponame)) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
800 cnode = web.repo.lookup(key) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
801 arch_version = key |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
802 if cnode == key or key == 'tip': |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
803 arch_version = short(cnode) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
804 name = "%s-%s" % (reponame, arch_version) |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
805 mimetype, artype, extension, encoding = web.archive_specs[type_] |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
806 headers = [ |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
807 ('Content-Disposition', 'attachment; filename=%s%s' % (name, extension)) |
18347
853221386f48
hgweb: make type a mandatory parameter to request.respond
Mads Kiilerich <mads@kiilerich.com>
parents:
18319
diff
changeset
|
808 ] |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
809 if encoding: |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
810 headers.append(('Content-Encoding', encoding)) |
18348
764a758780b6
hgweb: simplify wsgirequest header handling
Mads Kiilerich <mads@kiilerich.com>
parents:
18347
diff
changeset
|
811 req.headers.extend(headers) |
18347
853221386f48
hgweb: make type a mandatory parameter to request.respond
Mads Kiilerich <mads@kiilerich.com>
parents:
18319
diff
changeset
|
812 req.respond(HTTP_OK, mimetype) |
17933
8243dd66e0e3
webcommands: allow hgweb's archive to recurse into subrepos
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17322
diff
changeset
|
813 |
8243dd66e0e3
webcommands: allow hgweb's archive to recurse into subrepos
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17322
diff
changeset
|
814 ctx = webutil.changectx(web.repo, req) |
8243dd66e0e3
webcommands: allow hgweb's archive to recurse into subrepos
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17322
diff
changeset
|
815 archival.archive(web.repo, req, cnode, artype, prefix=name, |
8243dd66e0e3
webcommands: allow hgweb's archive to recurse into subrepos
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17322
diff
changeset
|
816 matchfn=scmutil.match(ctx, []), |
8243dd66e0e3
webcommands: allow hgweb's archive to recurse into subrepos
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17322
diff
changeset
|
817 subrepos=web.configbool("web", "archivesubrepos")) |
6393
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
818 return [] |
894875eae49b
hgweb: refactor hgweb code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6392
diff
changeset
|
819 |
5591
08887121a652
split out hgweb commands into a separate file, move some code around
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
820 |
5600
9d900f7282e6
hgweb: explicitly pass around the templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5598
diff
changeset
|
821 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
|
822 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
|
823 # 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
|
824 # 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
|
825 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
|
826 if not static: |
7966
aa983c3d94a9
templater: move stylemap function from hgweb to templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7876
diff
changeset
|
827 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
|
828 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
|
829 tp = [tp] |
7288
9c399c53469d
Allow per-file shadowing of static directory in templatepath
Brendan Cully <brendan@kublai.com>
parents:
7280
diff
changeset
|
830 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
|
831 return [staticfile(static, fname, req)] |
6691
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
832 |
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
833 def graph(web, req, tmpl): |
10245
207b94f6b65d
hgweb: make graph page size equal to shortlog
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9404
diff
changeset
|
834 |
17318
7ac5800dbc8f
hgweb: fix graph view paging
Patrick Mezard <patrick@mezard.eu>
parents:
17303
diff
changeset
|
835 ctx = webutil.changectx(web.repo, req) |
7ac5800dbc8f
hgweb: fix graph view paging
Patrick Mezard <patrick@mezard.eu>
parents:
17303
diff
changeset
|
836 rev = ctx.rev() |
7ac5800dbc8f
hgweb: fix graph view paging
Patrick Mezard <patrick@mezard.eu>
parents:
17303
diff
changeset
|
837 |
6691
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
838 bg_height = 39 |
10245
207b94f6b65d
hgweb: make graph page size equal to shortlog
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9404
diff
changeset
|
839 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
|
840 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
|
841 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
|
842 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
|
843 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
|
844 |
55651328dfcc
hgweb: fix up the less/more links on the graph page
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7332
diff
changeset
|
845 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
|
846 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
|
847 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
|
848 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
|
849 |
17318
7ac5800dbc8f
hgweb: fix graph view paging
Patrick Mezard <patrick@mezard.eu>
parents:
17303
diff
changeset
|
850 count = len(web.repo) |
7ac5800dbc8f
hgweb: fix graph view paging
Patrick Mezard <patrick@mezard.eu>
parents:
17303
diff
changeset
|
851 pos = rev |
7ac5800dbc8f
hgweb: fix graph view paging
Patrick Mezard <patrick@mezard.eu>
parents:
17303
diff
changeset
|
852 start = max(0, pos - revcount + 1) |
7ac5800dbc8f
hgweb: fix graph view paging
Patrick Mezard <patrick@mezard.eu>
parents:
17303
diff
changeset
|
853 end = min(count, start + revcount) |
7ac5800dbc8f
hgweb: fix graph view paging
Patrick Mezard <patrick@mezard.eu>
parents:
17303
diff
changeset
|
854 pos = end - 1 |
7ac5800dbc8f
hgweb: fix graph view paging
Patrick Mezard <patrick@mezard.eu>
parents:
17303
diff
changeset
|
855 |
7ac5800dbc8f
hgweb: fix graph view paging
Patrick Mezard <patrick@mezard.eu>
parents:
17303
diff
changeset
|
856 uprev = min(max(0, count - 1), rev + revcount) |
6691
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
857 downrev = max(0, rev - revcount) |
18409
e3f5cef11d6a
hgweb: pass repo object to revnav construction
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
18408
diff
changeset
|
858 changenav = webutil.revnav(web.repo).gen(pos, revcount, count) |
6691
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
859 |
17318
7ac5800dbc8f
hgweb: fix graph view paging
Patrick Mezard <patrick@mezard.eu>
parents:
17303
diff
changeset
|
860 dag = graphmod.dagwalker(web.repo, range(start, end)[::-1]) |
16129
5e50982c633c
graph: in hgrc specify line width for main branch
Constantine Linnick <theaspect@gmail.com>
parents:
15727
diff
changeset
|
861 tree = list(graphmod.colored(dag, web.repo)) |
16773
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
862 |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
863 def getcolumns(tree): |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
864 cols = 0 |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
865 for (id, type, ctx, vtx, edges) in tree: |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
866 if type != graphmod.CHANGESET: |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
867 continue |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
868 cols = max(cols, max([edge[0] for edge in edges] or [0]), |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
869 max([edge[1] for edge in edges] or [0])) |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
870 return cols |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
871 |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
872 def graphdata(usetuples, **map): |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
873 data = [] |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
874 |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
875 row = 0 |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
876 for (id, type, ctx, vtx, edges) in tree: |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
877 if type != graphmod.CHANGESET: |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
878 continue |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
879 node = str(ctx) |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
880 age = templatefilters.age(ctx.date()) |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
881 desc = templatefilters.firstline(ctx.description()) |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
882 desc = cgi.escape(templatefilters.nonempty(desc)) |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
883 user = cgi.escape(templatefilters.person(ctx.user())) |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
884 branch = ctx.branch() |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
885 try: |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
886 branchnode = web.repo.branchtip(branch) |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
887 except error.RepoLookupError: |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
888 branchnode = None |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
889 branch = branch, branchnode == ctx.node() |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
890 |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
891 if usetuples: |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
892 data.append((node, vtx, edges, desc, user, age, branch, |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
893 ctx.tags(), ctx.bookmarks())) |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
894 else: |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
895 edgedata = [dict(col=edge[0], nextcol=edge[1], |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
896 color=(edge[2] - 1) % 6 + 1, |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
897 width=edge[3], bcolor=edge[4]) |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
898 for edge in edges] |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
899 |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
900 data.append( |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
901 dict(node=node, |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
902 col=vtx[0], |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
903 color=(vtx[1] - 1) % 6 + 1, |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
904 edges=edgedata, |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
905 row=row, |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
906 nextrow=row + 1, |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
907 desc=desc, |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
908 user=user, |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
909 age=age, |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
910 bookmarks=webutil.nodebookmarksdict( |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
911 web.repo, ctx.node()), |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
912 branches=webutil.nodebranchdict(web.repo, ctx), |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
913 inbranch=webutil.nodeinbranch(web.repo, ctx), |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
914 tags=webutil.nodetagsdict(web.repo, ctx.node()))) |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
915 |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
916 row += 1 |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
917 |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
918 return data |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
919 |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
920 cols = getcolumns(tree) |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
921 rows = len(tree) |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
922 canvasheight = (rows + 1) * bg_height - 27 |
6691
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
923 |
0dba955c2636
add graph page to hgweb
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6670
diff
changeset
|
924 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
|
925 lessvars=lessvars, morevars=morevars, downrev=downrev, |
16773
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
926 cols=cols, rows=rows, |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
927 canvaswidth=(cols + 1) * bg_height, |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
928 truecanvasheight=rows * bg_height, |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
929 canvasheight=canvasheight, bg_height=bg_height, |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
930 jsdata=lambda **x: graphdata(True, **x), |
d490edc71146
hgweb: make graph data suitable for template usage
Paul Boddie <paul@boddie.org.uk>
parents:
16727
diff
changeset
|
931 nodes=lambda **x: graphdata(False, **x), |
17318
7ac5800dbc8f
hgweb: fix graph view paging
Patrick Mezard <patrick@mezard.eu>
parents:
17303
diff
changeset
|
932 node=ctx.hex(), changenav=changenav) |
12666
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
933 |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
934 def _getdoc(e): |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
935 doc = e[0].__doc__ |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
936 if doc: |
16469
dd68c972d089
i18n: show localized messages for commands/extensions in hgweb help top (issue3383)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16448
diff
changeset
|
937 doc = _(doc).split('\n')[0] |
12666
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
938 else: |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
939 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
|
940 return doc |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
941 |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
942 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
|
943 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
|
944 |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
945 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
|
946 if not topicname: |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
947 def topics(**map): |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
948 for entries, summary, _ in helpmod.helptable: |
17322
7124f984dc8d
help: use the first topic name from helptable, not the longest alias
Mads Kiilerich <mads@kiilerich.com>
parents:
17318
diff
changeset
|
949 yield {'topic': entries[0], 'summary': summary} |
12666
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
950 |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
951 early, other = [], [] |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
952 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
|
953 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
|
954 doc = _getdoc(e) |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
955 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
|
956 continue |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
957 cmd = primary(c) |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
958 if cmd.startswith('^'): |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
959 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
|
960 else: |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
961 other.append((cmd, doc)) |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
962 |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
963 early.sort() |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
964 other.sort() |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
965 |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
966 def earlycommands(**map): |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
967 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
|
968 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
|
969 |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
970 def othercommands(**map): |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
971 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
|
972 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
|
973 |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
974 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
|
975 othercommands=othercommands, title='Index') |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
976 |
12696
ef969e58a394
hgweb: another fix for the help termwidth bug
Matt Mackall <mpm@selenic.com>
parents:
12692
diff
changeset
|
977 u = webutil.wsgiui() |
12666
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
978 u.pushbuffer() |
17146
6b40cc67ceb4
hgweb: show help with verbose sections included
Adrian Buehlmann <adrian@cadifra.com>
parents:
16773
diff
changeset
|
979 u.verbose = True |
12666
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
980 try: |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
981 commands.help_(u, topicname) |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
982 except error.UnknownCommand: |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
983 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
|
984 doc = u.popbuffer() |
ead4e21f49f1
web: add a help view for getting hg help output
Augie Fackler <durin42@gmail.com>
parents:
12063
diff
changeset
|
985 return tmpl('help', topic=topicname, doc=doc) |