Mercurial > hg
annotate mercurial/hgweb/hgwebdir_mod.py @ 48599:dfbfa802876b
requirements: move "bookmark in store" requirements in the right module
There seems to be no reasons to not have it with the others.
Differential Revision: https://phab.mercurial-scm.org/D12030
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Mon, 17 Jan 2022 19:18:20 +0100 |
parents | de2e04fe4897 |
children | 6000f5b25c9b |
rev | line source |
---|---|
2391
d351a3be3371
Fixing up comment headers for split up code.
Eric Hopper <hopper@omnifarious.org>
parents:
2360
diff
changeset
|
1 # hgweb/hgwebdir_mod.py - Web interface for a directory of repositories. |
131 | 2 # |
238
3b92f8fe47ae
hgweb.py: kill #! line, clean up copyright notice
mpm@selenic.com
parents:
222
diff
changeset
|
3 # Copyright 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net> |
46819
d4ba4d51f85f
contributor: change mentions of mpm to olivia
Raphaël Gomès <rgomes@octobus.net>
parents:
45378
diff
changeset
|
4 # Copyright 2005, 2006 Olivia Mackall <olivia@selenic.com> |
131 | 5 # |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8216
diff
changeset
|
6 # This software may be used and distributed according to the terms of the |
10263 | 7 # GNU General Public License version 2 or any later version. |
131 | 8 |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
9 from __future__ import absolute_import |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
10 |
36845
ff2370a70fe8
hgweb: garbage collect on every request
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34703
diff
changeset
|
11 import gc |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
12 import os |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
13 import time |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
14 |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
15 from ..i18n import _ |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
16 |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
17 from .common import ( |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
18 ErrorResponse, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
19 HTTP_SERVER_ERROR, |
30766
d7bf7d2bd5ab
hgweb: support Content Security Policy
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30749
diff
changeset
|
20 cspvalues, |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
21 get_contact, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
22 get_mtime, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
23 ismember, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
24 paritygen, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
25 staticfile, |
36907
c1de7efca574
hgweb: port to new response API
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36906
diff
changeset
|
26 statusmessage, |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
27 ) |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
28 |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
29 from .. import ( |
34244
fe5202bef5ce
configitems: register the 'web.refreshinterval' config
Boris Feld <boris.feld@octobus.net>
parents:
34243
diff
changeset
|
30 configitems, |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
31 encoding, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
32 error, |
40728
2cd5f1fac788
hgweb: load globally-enabled extensions explicitly
Yuya Nishihara <yuya@tcha.org>
parents:
39793
diff
changeset
|
33 extensions, |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
34 hg, |
43633
0b7733719d21
utils: move finddirs() to pathutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
43106
diff
changeset
|
35 pathutil, |
29787
80df04266a16
hgweb: profile HTTP requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29786
diff
changeset
|
36 profiling, |
34358
8cbcee0b923d
py3: remove use of str() in hgwebdir
Yuya Nishihara <yuya@tcha.org>
parents:
34257
diff
changeset
|
37 pycompat, |
44245
bf23d6ee7ec7
config: also respect HGRCSKIPREPO in hgwebdir_mod
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43986
diff
changeset
|
38 rcutil, |
38928
4167437a45dd
hgweb: use registrar to add "motd" template keyword
Yuya Nishihara <yuya@tcha.org>
parents:
38745
diff
changeset
|
39 registrar, |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
40 scmutil, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
41 templater, |
37508
30a7b32897f1
hgwebdir: wrap {entries} with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
37019
diff
changeset
|
42 templateutil, |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
43 ui as uimod, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
44 util, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
45 ) |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
46 |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
47 from . import ( |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
48 hgweb_mod, |
36804
b9b968e21f78
hgweb: rename req to wsgireq
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36607
diff
changeset
|
49 request as requestmod, |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
50 webutil, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
51 wsgicgi, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
52 ) |
36607
c6061cadb400
util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents:
34703
diff
changeset
|
53 from ..utils import dateutil |
138 | 54 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
55 |
8215
227707c90548
hgweb: some cleanups in hgwebdir, remove double defaults
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8209
diff
changeset
|
56 def cleannames(items): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
57 return [(util.pconvert(name).strip(b'/'), path) for name, path in items] |
1181
4f5001f5b4c3
Make sure the repository names don't have slashes at the at or else in some
Vincent Wagelaar <vincent@ricardis.tudelft.nl>
parents:
1180
diff
changeset
|
58 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
59 |
8529
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
8389
diff
changeset
|
60 def findrepos(paths): |
9723
a235644a0b93
hgweb: use a tuple-list instead of dictionary for append-only store
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9363
diff
changeset
|
61 repos = [] |
8529
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
8389
diff
changeset
|
62 for prefix, root in cleannames(paths): |
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
8389
diff
changeset
|
63 roothead, roottail = os.path.split(root) |
17104
5a9acb0b2086
help: improve hgweb help
Mads Kiilerich <mads@kiilerich.com>
parents:
16754
diff
changeset
|
64 # "foo = /bar/*" or "foo = /bar/**" lets every repo /bar/N in or below |
5a9acb0b2086
help: improve hgweb help
Mads Kiilerich <mads@kiilerich.com>
parents:
16754
diff
changeset
|
65 # /bar/ be served as as foo/N . |
5a9acb0b2086
help: improve hgweb help
Mads Kiilerich <mads@kiilerich.com>
parents:
16754
diff
changeset
|
66 # '*' will not search inside dirs with .hg (except .hg/patches), |
5a9acb0b2086
help: improve hgweb help
Mads Kiilerich <mads@kiilerich.com>
parents:
16754
diff
changeset
|
67 # '**' will search inside dirs with .hg (and thus also find subrepos). |
8529
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
8389
diff
changeset
|
68 try: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
69 recurse = {b'*': False, b'**': True}[roottail] |
8529
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
8389
diff
changeset
|
70 except KeyError: |
9723
a235644a0b93
hgweb: use a tuple-list instead of dictionary for append-only store
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9363
diff
changeset
|
71 repos.append((prefix, root)) |
8529
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
8389
diff
changeset
|
72 continue |
47627
aceede7c4929
windows: use abspath in hgwebdir
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46819
diff
changeset
|
73 roothead = os.path.normpath(util.abspath(roothead)) |
13975
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13964
diff
changeset
|
74 paths = scmutil.walkrepos(roothead, followsym=True, recurse=recurse) |
13402
f947d9a4c45c
hgweb: doctest of url creation from wildcard expansion
Mads Kiilerich <mads@kiilerich.com>
parents:
13214
diff
changeset
|
75 repos.extend(urlrepos(prefix, roothead, paths)) |
9723
a235644a0b93
hgweb: use a tuple-list instead of dictionary for append-only store
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9363
diff
changeset
|
76 return repos |
8529
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
8389
diff
changeset
|
77 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
78 |
13402
f947d9a4c45c
hgweb: doctest of url creation from wildcard expansion
Mads Kiilerich <mads@kiilerich.com>
parents:
13214
diff
changeset
|
79 def urlrepos(prefix, roothead, paths): |
f947d9a4c45c
hgweb: doctest of url creation from wildcard expansion
Mads Kiilerich <mads@kiilerich.com>
parents:
13214
diff
changeset
|
80 """yield url paths and filesystem paths from a list of repo paths |
f947d9a4c45c
hgweb: doctest of url creation from wildcard expansion
Mads Kiilerich <mads@kiilerich.com>
parents:
13214
diff
changeset
|
81 |
13538
d24e97fd52a9
test-doctest: handle unix/windows path discrepancies
Patrick Mezard <pmezard@gmail.com>
parents:
13436
diff
changeset
|
82 >>> conv = lambda seq: [(v, util.pconvert(p)) for v,p in seq] |
34131
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34022
diff
changeset
|
83 >>> conv(urlrepos(b'hg', b'/opt', [b'/opt/r', b'/opt/r/r', b'/opt'])) |
13403
8ed91088acbb
hgweb: make paths wildcards expanding in a repo root match repo correctly
Mads Kiilerich <mads@kiilerich.com>
parents:
13402
diff
changeset
|
84 [('hg/r', '/opt/r'), ('hg/r/r', '/opt/r/r'), ('hg', '/opt')] |
34131
0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Yuya Nishihara <yuya@tcha.org>
parents:
34022
diff
changeset
|
85 >>> conv(urlrepos(b'', b'/opt', [b'/opt/r', b'/opt/r/r', b'/opt'])) |
13402
f947d9a4c45c
hgweb: doctest of url creation from wildcard expansion
Mads Kiilerich <mads@kiilerich.com>
parents:
13214
diff
changeset
|
86 [('r', '/opt/r'), ('r/r', '/opt/r/r'), ('', '/opt')] |
f947d9a4c45c
hgweb: doctest of url creation from wildcard expansion
Mads Kiilerich <mads@kiilerich.com>
parents:
13214
diff
changeset
|
87 """ |
f947d9a4c45c
hgweb: doctest of url creation from wildcard expansion
Mads Kiilerich <mads@kiilerich.com>
parents:
13214
diff
changeset
|
88 for path in paths: |
f947d9a4c45c
hgweb: doctest of url creation from wildcard expansion
Mads Kiilerich <mads@kiilerich.com>
parents:
13214
diff
changeset
|
89 path = os.path.normpath(path) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
90 yield ( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
91 prefix + b'/' + util.pconvert(path[len(roothead) :]).lstrip(b'/') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
92 ).strip(b'/'), path |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
93 |
13402
f947d9a4c45c
hgweb: doctest of url creation from wildcard expansion
Mads Kiilerich <mads@kiilerich.com>
parents:
13214
diff
changeset
|
94 |
36890
f8d6d9b29b39
hgweb: move readallowed to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36889
diff
changeset
|
95 def readallowed(ui, req): |
f8d6d9b29b39
hgweb: move readallowed to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36889
diff
changeset
|
96 """Check allow_read and deny_read config options of a repo's ui object |
f8d6d9b29b39
hgweb: move readallowed to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36889
diff
changeset
|
97 to determine user permissions. By default, with neither option set (or |
f8d6d9b29b39
hgweb: move readallowed to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36889
diff
changeset
|
98 both empty), allow all users to read the repo. There are two ways a |
f8d6d9b29b39
hgweb: move readallowed to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36889
diff
changeset
|
99 user can be denied read access: (1) deny_read is not empty, and the |
f8d6d9b29b39
hgweb: move readallowed to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36889
diff
changeset
|
100 user is unauthenticated or deny_read contains user (or *), and (2) |
f8d6d9b29b39
hgweb: move readallowed to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36889
diff
changeset
|
101 allow_read is not empty and the user is not in allow_read. Return True |
f8d6d9b29b39
hgweb: move readallowed to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36889
diff
changeset
|
102 if user is allowed to read the repo, else return False.""" |
f8d6d9b29b39
hgweb: move readallowed to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36889
diff
changeset
|
103 |
f8d6d9b29b39
hgweb: move readallowed to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36889
diff
changeset
|
104 user = req.remoteuser |
f8d6d9b29b39
hgweb: move readallowed to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36889
diff
changeset
|
105 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
106 deny_read = ui.configlist(b'web', b'deny_read', untrusted=True) |
36890
f8d6d9b29b39
hgweb: move readallowed to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36889
diff
changeset
|
107 if deny_read and (not user or ismember(ui, user, deny_read)): |
f8d6d9b29b39
hgweb: move readallowed to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36889
diff
changeset
|
108 return False |
f8d6d9b29b39
hgweb: move readallowed to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36889
diff
changeset
|
109 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
110 allow_read = ui.configlist(b'web', b'allow_read', untrusted=True) |
36890
f8d6d9b29b39
hgweb: move readallowed to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36889
diff
changeset
|
111 # by default, allow reading if no allow_read option has been set |
f8d6d9b29b39
hgweb: move readallowed to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36889
diff
changeset
|
112 if not allow_read or ismember(ui, user, allow_read): |
f8d6d9b29b39
hgweb: move readallowed to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36889
diff
changeset
|
113 return True |
f8d6d9b29b39
hgweb: move readallowed to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36889
diff
changeset
|
114 |
f8d6d9b29b39
hgweb: move readallowed to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36889
diff
changeset
|
115 return False |
f8d6d9b29b39
hgweb: move readallowed to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36889
diff
changeset
|
116 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
117 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
118 def rawindexentries(ui, repos, req, subdir=b''): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
119 descend = ui.configbool(b'web', b'descend') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
120 collapse = ui.configbool(b'web', b'collapse') |
36892
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
121 seenrepos = set() |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
122 seendirs = set() |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
123 for name, path in repos: |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
124 |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
125 if not name.startswith(subdir): |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
126 continue |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
127 name = name[len(subdir) :] |
36892
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
128 directory = False |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
129 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
130 if b'/' in name: |
36892
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
131 if not descend: |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
132 continue |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
133 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
134 nameparts = name.split(b'/') |
36892
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
135 rootname = nameparts[0] |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
136 |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
137 if not collapse: |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
138 pass |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
139 elif rootname in seendirs: |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
140 continue |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
141 elif rootname in seenrepos: |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
142 pass |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
143 else: |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
144 directory = True |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
145 name = rootname |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
146 |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
147 # redefine the path to refer to the directory |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
148 discarded = b'/'.join(nameparts[1:]) |
36892
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
149 |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
150 # remove name parts plus accompanying slash |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
151 path = path[: -len(discarded) - 1] |
36892
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
152 |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
153 try: |
41365
876494fd967d
cleanup: delete lots of unused local variables
Martin von Zweigbergk <martinvonz@google.com>
parents:
41319
diff
changeset
|
154 hg.repository(ui, path) |
36892
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
155 directory = False |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
156 except (IOError, error.RepoError): |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
157 pass |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
158 |
36902
e473a032f38a
hgweb: rewrite path generation for index entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36901
diff
changeset
|
159 parts = [ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
160 req.apppath.strip(b'/'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
161 subdir.strip(b'/'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
162 name.strip(b'/'), |
36902
e473a032f38a
hgweb: rewrite path generation for index entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36901
diff
changeset
|
163 ] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
164 url = b'/' + b'/'.join(p for p in parts if p) + b'/' |
15003
a31b8e03af28
hgweb: extract the path logic from updatereqenv and add doctests
Matt Mackall <mpm@selenic.com>
parents:
15002
diff
changeset
|
165 |
36892
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
166 # show either a directory entry or a repository |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
167 if directory: |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
168 # get the directory's time information |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
169 try: |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
170 d = (get_mtime(path), dateutil.makedate()[1]) |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
171 except OSError: |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
172 continue |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
173 |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
174 # add '/' to the name to make it obvious that |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
175 # the entry is a directory, not a regular repository |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
176 row = { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
177 b'contact': b"", |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
178 b'contact_sort': b"", |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
179 b'name': name + b'/', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
180 b'name_sort': name, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
181 b'url': url, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
182 b'description': b"", |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
183 b'description_sort': b"", |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
184 b'lastchange': d, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
185 b'lastchange_sort': d[1] - d[0], |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
186 b'archives': templateutil.mappinglist([]), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
187 b'isdirectory': True, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
188 b'labels': templateutil.hybridlist([], name=b'label'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
189 } |
36892
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
190 |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
191 seendirs.add(name) |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
192 yield row |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
193 continue |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
194 |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
195 u = ui.copy() |
44245
bf23d6ee7ec7
config: also respect HGRCSKIPREPO in hgwebdir_mod
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43986
diff
changeset
|
196 if rcutil.use_repo_hgrc(): |
bf23d6ee7ec7
config: also respect HGRCSKIPREPO in hgwebdir_mod
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43986
diff
changeset
|
197 try: |
bf23d6ee7ec7
config: also respect HGRCSKIPREPO in hgwebdir_mod
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43986
diff
changeset
|
198 u.readconfig(os.path.join(path, b'.hg', b'hgrc')) |
bf23d6ee7ec7
config: also respect HGRCSKIPREPO in hgwebdir_mod
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43986
diff
changeset
|
199 except Exception as e: |
bf23d6ee7ec7
config: also respect HGRCSKIPREPO in hgwebdir_mod
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43986
diff
changeset
|
200 u.warn(_(b'error reading %s/.hg/hgrc: %s\n') % (path, e)) |
bf23d6ee7ec7
config: also respect HGRCSKIPREPO in hgwebdir_mod
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43986
diff
changeset
|
201 continue |
36892
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
202 |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
203 def get(section, name, default=uimod._unset): |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
204 return u.config(section, name, default, untrusted=True) |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
205 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
206 if u.configbool(b"web", b"hidden", untrusted=True): |
36892
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
207 continue |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
208 |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
209 if not readallowed(u, req): |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
210 continue |
15003
a31b8e03af28
hgweb: extract the path logic from updatereqenv and add doctests
Matt Mackall <mpm@selenic.com>
parents:
15002
diff
changeset
|
211 |
36892
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
212 # update time with local timezone |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
213 try: |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
214 r = hg.repository(ui, path) |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
215 except IOError: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
216 u.warn(_(b'error accessing repository at %s\n') % path) |
36892
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
217 continue |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
218 except error.RepoError: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
219 u.warn(_(b'error accessing repository at %s\n') % path) |
36892
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
220 continue |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
221 try: |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
222 d = (get_mtime(r.spath), dateutil.makedate()[1]) |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
223 except OSError: |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
224 continue |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
225 |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
226 contact = get_contact(get) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
227 description = get(b"web", b"description") |
36892
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
228 seenrepos.add(name) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
229 name = get(b"web", b"name", name) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
230 labels = u.configlist(b'web', b'labels', untrusted=True) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
231 row = { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
232 b'contact': contact or b"unknown", |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
233 b'contact_sort': contact.upper() or b"unknown", |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
234 b'name': name, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
235 b'name_sort': name, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
236 b'url': url, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
237 b'description': description or b"unknown", |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
238 b'description_sort': description.upper() or b"unknown", |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
239 b'lastchange': d, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
240 b'lastchange_sort': d[1] - d[0], |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
241 b'archives': webutil.archivelist(u, b"tip", url), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
242 b'isdirectory': None, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
243 b'labels': templateutil.hybridlist(labels, name=b'label'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
244 } |
36892
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
245 |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
246 yield row |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
247 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
248 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
249 def _indexentriesgen( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
250 context, ui, repos, req, stripecount, sortcolumn, descending, subdir |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
251 ): |
36904
092ab4ba7ee5
hgweb: don't pass wsgireq to makeindex and other functions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36903
diff
changeset
|
252 rows = rawindexentries(ui, repos, req, subdir=subdir) |
36893
455918512ed2
hgweb: extract entries() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
253 |
455918512ed2
hgweb: extract entries() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
254 sortdefault = None, False |
455918512ed2
hgweb: extract entries() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
255 |
455918512ed2
hgweb: extract entries() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
256 if sortcolumn and sortdefault != (sortcolumn, descending): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
257 sortkey = b'%s_sort' % sortcolumn |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
258 rows = sorted(rows, key=lambda x: x[sortkey], reverse=descending) |
36893
455918512ed2
hgweb: extract entries() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
259 |
455918512ed2
hgweb: extract entries() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
260 for row, parity in zip(rows, paritygen(stripecount)): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
261 row[b'parity'] = parity |
36893
455918512ed2
hgweb: extract entries() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
262 yield row |
15003
a31b8e03af28
hgweb: extract the path logic from updatereqenv and add doctests
Matt Mackall <mpm@selenic.com>
parents:
15002
diff
changeset
|
263 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
264 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
265 def indexentries( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
266 ui, repos, req, stripecount, sortcolumn=b'', descending=False, subdir=b'' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
267 ): |
37508
30a7b32897f1
hgwebdir: wrap {entries} with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
37019
diff
changeset
|
268 args = (ui, repos, req, stripecount, sortcolumn, descending, subdir) |
30a7b32897f1
hgwebdir: wrap {entries} with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
37019
diff
changeset
|
269 return templateutil.mappinggenerator(_indexentriesgen, args=args) |
30a7b32897f1
hgwebdir: wrap {entries} with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
37019
diff
changeset
|
270 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
271 |
1559
59b3639df0a9
Convert all classes to new-style classes by deriving them from object.
Eric Hopper <hopper@omnifarious.org>
parents:
1554
diff
changeset
|
272 class hgwebdir(object): |
26132
9df8c729e2e7
hgweb: add some documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26072
diff
changeset
|
273 """HTTP server for multiple repositories. |
9df8c729e2e7
hgweb: add some documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26072
diff
changeset
|
274 |
9df8c729e2e7
hgweb: add some documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26072
diff
changeset
|
275 Given a configuration, different repositories will be served depending |
9df8c729e2e7
hgweb: add some documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26072
diff
changeset
|
276 on the request path. |
9df8c729e2e7
hgweb: add some documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26072
diff
changeset
|
277 |
9df8c729e2e7
hgweb: add some documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26072
diff
changeset
|
278 Instances are typically used as WSGI applications. |
9df8c729e2e7
hgweb: add some documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26072
diff
changeset
|
279 """ |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
280 |
8191
35604226d712
hgweb: kill parentui references
Matt Mackall <mpm@selenic.com>
parents:
8190
diff
changeset
|
281 def __init__(self, conf, baseui=None): |
8371
1bd0fdf4c1ec
hgwebdir: refresh configuration periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
8360
diff
changeset
|
282 self.conf = conf |
1bd0fdf4c1ec
hgwebdir: refresh configuration periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
8360
diff
changeset
|
283 self.baseui = baseui |
26072
06320fb11699
hgweb: make refresh interval configurable
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
284 self.ui = None |
8371
1bd0fdf4c1ec
hgwebdir: refresh configuration periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
8360
diff
changeset
|
285 self.lastrefresh = 0 |
9903
5d748045c2ae
Do not overwrite motd attribute of hgwebdir instances on refresh.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
9842
diff
changeset
|
286 self.motd = None |
8371
1bd0fdf4c1ec
hgwebdir: refresh configuration periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
8360
diff
changeset
|
287 self.refresh() |
47802
de2e04fe4897
hgwebdir: avoid systematic full garbage collection
Georges Racinet <georges.racinet@octobus.net>
parents:
47627
diff
changeset
|
288 self.requests_count = 0 |
40728
2cd5f1fac788
hgweb: load globally-enabled extensions explicitly
Yuya Nishihara <yuya@tcha.org>
parents:
39793
diff
changeset
|
289 if not baseui: |
2cd5f1fac788
hgweb: load globally-enabled extensions explicitly
Yuya Nishihara <yuya@tcha.org>
parents:
39793
diff
changeset
|
290 # set up environment for new ui |
2cd5f1fac788
hgweb: load globally-enabled extensions explicitly
Yuya Nishihara <yuya@tcha.org>
parents:
39793
diff
changeset
|
291 extensions.loadall(self.ui) |
40729
c93d046d4300
extensions: add "uipopulate" hook, called per instance, not per process
Yuya Nishihara <yuya@tcha.org>
parents:
40728
diff
changeset
|
292 extensions.populateui(self.ui) |
1181
4f5001f5b4c3
Make sure the repository names don't have slashes at the at or else in some
Vincent Wagelaar <vincent@ricardis.tudelft.nl>
parents:
1180
diff
changeset
|
293 |
8371
1bd0fdf4c1ec
hgwebdir: refresh configuration periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
8360
diff
changeset
|
294 def refresh(self): |
26072
06320fb11699
hgweb: make refresh interval configurable
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
295 if self.ui: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
296 refreshinterval = self.ui.configint(b'web', b'refreshinterval') |
34244
fe5202bef5ce
configitems: register the 'web.refreshinterval' config
Boris Feld <boris.feld@octobus.net>
parents:
34243
diff
changeset
|
297 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
298 item = configitems.coreitems[b'web'][b'refreshinterval'] |
34244
fe5202bef5ce
configitems: register the 'web.refreshinterval' config
Boris Feld <boris.feld@octobus.net>
parents:
34243
diff
changeset
|
299 refreshinterval = item.default |
26072
06320fb11699
hgweb: make refresh interval configurable
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
300 |
06320fb11699
hgweb: make refresh interval configurable
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
301 # refreshinterval <= 0 means to always refresh. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
302 if ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
303 refreshinterval > 0 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
304 and self.lastrefresh + refreshinterval > time.time() |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
305 ): |
8371
1bd0fdf4c1ec
hgwebdir: refresh configuration periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
8360
diff
changeset
|
306 return |
1bd0fdf4c1ec
hgwebdir: refresh configuration periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
8360
diff
changeset
|
307 |
1bd0fdf4c1ec
hgwebdir: refresh configuration periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
8360
diff
changeset
|
308 if self.baseui: |
11239
99bc18d1ab0f
hgweb: fix race in refreshing repo list (issue2188)
Matt Mackall <mpm@selenic.com>
parents:
10675
diff
changeset
|
309 u = self.baseui.copy() |
1143
4fffb3d84b7c
Allow list of (virtual, real) or dictionary to be passed to hgwebdir.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1142
diff
changeset
|
310 else: |
30559
d83ca854fa21
ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents:
29787
diff
changeset
|
311 u = uimod.ui.load() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
312 u.setconfig(b'ui', b'report_untrusted', b'off', b'hgwebdir') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
313 u.setconfig(b'ui', b'nontty', b'true', b'hgwebdir') |
25488
89ce95f907bd
hgewb: disable progress when serving (issue4582)
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25427
diff
changeset
|
314 # displaying bundling progress bar while serving feels wrong and may |
89ce95f907bd
hgewb: disable progress when serving (issue4582)
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25427
diff
changeset
|
315 # break some wsgi implementations. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
316 u.setconfig(b'progress', b'disable', b'true', b'hgweb') |
8136
6b5522cb2ad2
ui: refactor option setting
Matt Mackall <mpm@selenic.com>
parents:
7966
diff
changeset
|
317 |
8529
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
8389
diff
changeset
|
318 if not isinstance(self.conf, (dict, list, tuple)): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
319 map = {b'paths': b'hgweb-paths'} |
13214
5bcb6c9d16db
hgweb: abort if config file isn't found
Matt Mackall <mpm@selenic.com>
parents:
13066
diff
changeset
|
320 if not os.path.exists(self.conf): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
321 raise error.Abort(_(b'config file %s not found!') % self.conf) |
11239
99bc18d1ab0f
hgweb: fix race in refreshing repo list (issue2188)
Matt Mackall <mpm@selenic.com>
parents:
10675
diff
changeset
|
322 u.readconfig(self.conf, remap=map, trust=True) |
13667
8cbb59124e67
hgweb: support multiple directories for the same path
timeless <timeless@gmail.com>
parents:
13538
diff
changeset
|
323 paths = [] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
324 for name, ignored in u.configitems(b'hgweb-paths'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
325 for path in u.configlist(b'hgweb-paths', name): |
13667
8cbb59124e67
hgweb: support multiple directories for the same path
timeless <timeless@gmail.com>
parents:
13538
diff
changeset
|
326 paths.append((name, path)) |
8529
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
8389
diff
changeset
|
327 elif isinstance(self.conf, (list, tuple)): |
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
8389
diff
changeset
|
328 paths = self.conf |
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
8389
diff
changeset
|
329 elif isinstance(self.conf, dict): |
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
8389
diff
changeset
|
330 paths = self.conf.items() |
40729
c93d046d4300
extensions: add "uipopulate" hook, called per instance, not per process
Yuya Nishihara <yuya@tcha.org>
parents:
40728
diff
changeset
|
331 extensions.populateui(u) |
8345
dcebff8a25dd
hgwebdir: read --webdir-conf as actual configuration to ui (issue1586)
Alexander Solovyov <piranha@piranha.org.ua>
parents:
8225
diff
changeset
|
332 |
11239
99bc18d1ab0f
hgweb: fix race in refreshing repo list (issue2188)
Matt Mackall <mpm@selenic.com>
parents:
10675
diff
changeset
|
333 repos = findrepos(paths) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
334 for prefix, root in u.configitems(b'collections'): |
11239
99bc18d1ab0f
hgweb: fix race in refreshing repo list (issue2188)
Matt Mackall <mpm@selenic.com>
parents:
10675
diff
changeset
|
335 prefix = util.pconvert(prefix) |
13975
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13964
diff
changeset
|
336 for path in scmutil.walkrepos(root, followsym=True): |
11239
99bc18d1ab0f
hgweb: fix race in refreshing repo list (issue2188)
Matt Mackall <mpm@selenic.com>
parents:
10675
diff
changeset
|
337 repo = os.path.normpath(path) |
99bc18d1ab0f
hgweb: fix race in refreshing repo list (issue2188)
Matt Mackall <mpm@selenic.com>
parents:
10675
diff
changeset
|
338 name = util.pconvert(repo) |
99bc18d1ab0f
hgweb: fix race in refreshing repo list (issue2188)
Matt Mackall <mpm@selenic.com>
parents:
10675
diff
changeset
|
339 if name.startswith(prefix): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
340 name = name[len(prefix) :] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
341 repos.append((name.lstrip(b'/'), repo)) |
11239
99bc18d1ab0f
hgweb: fix race in refreshing repo list (issue2188)
Matt Mackall <mpm@selenic.com>
parents:
10675
diff
changeset
|
342 |
99bc18d1ab0f
hgweb: fix race in refreshing repo list (issue2188)
Matt Mackall <mpm@selenic.com>
parents:
10675
diff
changeset
|
343 self.repos = repos |
99bc18d1ab0f
hgweb: fix race in refreshing repo list (issue2188)
Matt Mackall <mpm@selenic.com>
parents:
10675
diff
changeset
|
344 self.ui = u |
47802
de2e04fe4897
hgwebdir: avoid systematic full garbage collection
Georges Racinet <georges.racinet@octobus.net>
parents:
47627
diff
changeset
|
345 self.gc_full_collect_rate = self.ui.configint( |
de2e04fe4897
hgwebdir: avoid systematic full garbage collection
Georges Racinet <georges.racinet@octobus.net>
parents:
47627
diff
changeset
|
346 b'experimental', b'web.full-garbage-collection-rate' |
de2e04fe4897
hgwebdir: avoid systematic full garbage collection
Georges Racinet <georges.racinet@octobus.net>
parents:
47627
diff
changeset
|
347 ) |
de2e04fe4897
hgwebdir: avoid systematic full garbage collection
Georges Racinet <georges.racinet@octobus.net>
parents:
47627
diff
changeset
|
348 self.gc_full_collections_done = 0 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
349 encoding.encoding = self.ui.config(b'web', b'encoding') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
350 self.style = self.ui.config(b'web', b'style') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
351 self.templatepath = self.ui.config( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
352 b'web', b'templates', untrusted=False |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
353 ) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
354 self.stripecount = self.ui.config(b'web', b'stripes') |
8621
13613221caf1
hgweb: extract config values after reading webdir-config
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8537
diff
changeset
|
355 if self.stripecount: |
13613221caf1
hgweb: extract config values after reading webdir-config
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8537
diff
changeset
|
356 self.stripecount = int(self.stripecount) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
357 prefix = self.ui.config(b'web', b'prefix') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
358 if prefix.startswith(b'/'): |
18515
bf8bbbf4aa45
hgwebdir: use web.prefix when creating url breadcrumbs (issue3790)
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
18258
diff
changeset
|
359 prefix = prefix[1:] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
360 if prefix.endswith(b'/'): |
18515
bf8bbbf4aa45
hgwebdir: use web.prefix when creating url breadcrumbs (issue3790)
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
18258
diff
changeset
|
361 prefix = prefix[:-1] |
bf8bbbf4aa45
hgwebdir: use web.prefix when creating url breadcrumbs (issue3790)
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
18258
diff
changeset
|
362 self.prefix = prefix |
8371
1bd0fdf4c1ec
hgwebdir: refresh configuration periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
8360
diff
changeset
|
363 self.lastrefresh = time.time() |
941 | 364 |
2535
b8ccf6386db7
Arrange for old copies of CGI scripts to still work.
Eric Hopper <hopper@omnifarious.org>
parents:
2514
diff
changeset
|
365 def run(self): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
366 if not encoding.environ.get(b'GATEWAY_INTERFACE', b'').startswith( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
367 b"CGI/1." |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
368 ): |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
369 raise RuntimeError( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
370 b"This function is only intended to be " |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
371 b"called while running as a CGI script." |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
372 ) |
5566
d74fc8dec2b4
Less indirection in the WSGI web interface. This simplifies some code, and makes it more compliant with WSGI.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5561
diff
changeset
|
373 wsgicgi.launch(self) |
d74fc8dec2b4
Less indirection in the WSGI web interface. This simplifies some code, and makes it more compliant with WSGI.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5561
diff
changeset
|
374 |
d74fc8dec2b4
Less indirection in the WSGI web interface. This simplifies some code, and makes it more compliant with WSGI.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5561
diff
changeset
|
375 def __call__(self, env, respond): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
376 baseurl = self.ui.config(b'web', b'baseurl') |
36911
f0a851542a05
hgweb: remove wsgirequest (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36908
diff
changeset
|
377 req = requestmod.parserequestfromenv(env, altbaseurl=baseurl) |
f0a851542a05
hgweb: remove wsgirequest (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36908
diff
changeset
|
378 res = requestmod.wsgiresponse(req, respond) |
7336
2dc868712dcc
hgweb: support for deny_read/allow_read options
Mark Edgington <edgimar@gmail.com>
parents:
7225
diff
changeset
|
379 |
36911
f0a851542a05
hgweb: remove wsgirequest (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36908
diff
changeset
|
380 return self.run_wsgi(req, res) |
7336
2dc868712dcc
hgweb: support for deny_read/allow_read options
Mark Edgington <edgimar@gmail.com>
parents:
7225
diff
changeset
|
381 |
36911
f0a851542a05
hgweb: remove wsgirequest (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36908
diff
changeset
|
382 def run_wsgi(self, req, res): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
383 profile = self.ui.configbool(b'profiling', b'enabled') |
32788
eede022fc142
profile: drop maybeprofile
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32004
diff
changeset
|
384 with profiling.profile(self.ui, enabled=profile): |
36845
ff2370a70fe8
hgweb: garbage collect on every request
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34703
diff
changeset
|
385 try: |
36978 | 386 for r in self._runwsgi(req, res): |
36845
ff2370a70fe8
hgweb: garbage collect on every request
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34703
diff
changeset
|
387 yield r |
ff2370a70fe8
hgweb: garbage collect on every request
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34703
diff
changeset
|
388 finally: |
ff2370a70fe8
hgweb: garbage collect on every request
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34703
diff
changeset
|
389 # There are known cycles in localrepository that prevent |
ff2370a70fe8
hgweb: garbage collect on every request
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34703
diff
changeset
|
390 # those objects (and tons of held references) from being |
47802
de2e04fe4897
hgwebdir: avoid systematic full garbage collection
Georges Racinet <georges.racinet@octobus.net>
parents:
47627
diff
changeset
|
391 # collected through normal refcounting. |
de2e04fe4897
hgwebdir: avoid systematic full garbage collection
Georges Racinet <georges.racinet@octobus.net>
parents:
47627
diff
changeset
|
392 # In some cases, the resulting memory consumption can |
de2e04fe4897
hgwebdir: avoid systematic full garbage collection
Georges Racinet <georges.racinet@octobus.net>
parents:
47627
diff
changeset
|
393 # be tamed by performing explicit garbage collections. |
de2e04fe4897
hgwebdir: avoid systematic full garbage collection
Georges Racinet <georges.racinet@octobus.net>
parents:
47627
diff
changeset
|
394 # In presence of actual leaks or big long-lived caches, the |
de2e04fe4897
hgwebdir: avoid systematic full garbage collection
Georges Racinet <georges.racinet@octobus.net>
parents:
47627
diff
changeset
|
395 # impact on performance of such collections can become a |
de2e04fe4897
hgwebdir: avoid systematic full garbage collection
Georges Racinet <georges.racinet@octobus.net>
parents:
47627
diff
changeset
|
396 # problem, hence the rate shouldn't be set too low. |
de2e04fe4897
hgwebdir: avoid systematic full garbage collection
Georges Racinet <georges.racinet@octobus.net>
parents:
47627
diff
changeset
|
397 # See "Collecting the oldest generation" in |
de2e04fe4897
hgwebdir: avoid systematic full garbage collection
Georges Racinet <georges.racinet@octobus.net>
parents:
47627
diff
changeset
|
398 # https://devguide.python.org/garbage_collector |
de2e04fe4897
hgwebdir: avoid systematic full garbage collection
Georges Racinet <georges.racinet@octobus.net>
parents:
47627
diff
changeset
|
399 # for more about such trade-offs. |
de2e04fe4897
hgwebdir: avoid systematic full garbage collection
Georges Racinet <georges.racinet@octobus.net>
parents:
47627
diff
changeset
|
400 rate = self.gc_full_collect_rate |
de2e04fe4897
hgwebdir: avoid systematic full garbage collection
Georges Racinet <georges.racinet@octobus.net>
parents:
47627
diff
changeset
|
401 |
de2e04fe4897
hgwebdir: avoid systematic full garbage collection
Georges Racinet <georges.racinet@octobus.net>
parents:
47627
diff
changeset
|
402 # this is not thread safe, but the consequence (skipping |
de2e04fe4897
hgwebdir: avoid systematic full garbage collection
Georges Racinet <georges.racinet@octobus.net>
parents:
47627
diff
changeset
|
403 # a garbage collection) is arguably better than risking |
de2e04fe4897
hgwebdir: avoid systematic full garbage collection
Georges Racinet <georges.racinet@octobus.net>
parents:
47627
diff
changeset
|
404 # to have several threads perform a collection in parallel |
de2e04fe4897
hgwebdir: avoid systematic full garbage collection
Georges Racinet <georges.racinet@octobus.net>
parents:
47627
diff
changeset
|
405 # (long useless wait on all threads). |
de2e04fe4897
hgwebdir: avoid systematic full garbage collection
Georges Racinet <georges.racinet@octobus.net>
parents:
47627
diff
changeset
|
406 self.requests_count += 1 |
de2e04fe4897
hgwebdir: avoid systematic full garbage collection
Georges Racinet <georges.racinet@octobus.net>
parents:
47627
diff
changeset
|
407 if rate > 0 and self.requests_count % rate == 0: |
de2e04fe4897
hgwebdir: avoid systematic full garbage collection
Georges Racinet <georges.racinet@octobus.net>
parents:
47627
diff
changeset
|
408 gc.collect() |
de2e04fe4897
hgwebdir: avoid systematic full garbage collection
Georges Racinet <georges.racinet@octobus.net>
parents:
47627
diff
changeset
|
409 self.gc_full_collections_done += 1 |
de2e04fe4897
hgwebdir: avoid systematic full garbage collection
Georges Racinet <georges.racinet@octobus.net>
parents:
47627
diff
changeset
|
410 else: |
de2e04fe4897
hgwebdir: avoid systematic full garbage collection
Georges Racinet <georges.racinet@octobus.net>
parents:
47627
diff
changeset
|
411 gc.collect(generation=1) |
29786
fc2442492606
hgweb: abstract call to hgwebdir wsgi function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29471
diff
changeset
|
412 |
36911
f0a851542a05
hgweb: remove wsgirequest (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36908
diff
changeset
|
413 def _runwsgi(self, req, res): |
5601
8279cb841467
hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5585
diff
changeset
|
414 try: |
25083
ef36536abea3
hgweb: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
22634
diff
changeset
|
415 self.refresh() |
5603
74f65f44a9aa
hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5602
diff
changeset
|
416 |
30766
d7bf7d2bd5ab
hgweb: support Content Security Policy
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30749
diff
changeset
|
417 csp, nonce = cspvalues(self.ui) |
d7bf7d2bd5ab
hgweb: support Content Security Policy
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30749
diff
changeset
|
418 if csp: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
419 res.headers[b'Content-Security-Policy'] = csp |
30766
d7bf7d2bd5ab
hgweb: support Content Security Policy
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30749
diff
changeset
|
420 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
421 virtual = req.dispatchpath.strip(b'/') |
30766
d7bf7d2bd5ab
hgweb: support Content Security Policy
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30749
diff
changeset
|
422 tmpl = self.templater(req, nonce) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
423 ctype = tmpl.render(b'mimetype', {b'encoding': encoding.encoding}) |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5603
diff
changeset
|
424 |
36873
98baf8dea553
hgweb: port static file handling to new response API
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36865
diff
changeset
|
425 # Global defaults. These can be overridden by any handler. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
426 res.status = b'200 Script output follows' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
427 res.headers[b'Content-Type'] = ctype |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5603
diff
changeset
|
428 |
25083
ef36536abea3
hgweb: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
22634
diff
changeset
|
429 # a static file |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
430 if virtual.startswith(b'static/') or b'static' in req.qsparams: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
431 if virtual.startswith(b'static/'): |
25083
ef36536abea3
hgweb: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
22634
diff
changeset
|
432 fname = virtual[7:] |
ef36536abea3
hgweb: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
22634
diff
changeset
|
433 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
434 fname = req.qsparams[b'static'] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
435 static = self.ui.config(b"web", b"static", untrusted=False) |
45378
dc9fe90bdbd5
hgweb: let staticfile() look up path from default location unless provided
Martin von Zweigbergk <martinvonz@google.com>
parents:
45318
diff
changeset
|
436 staticfile(self.templatepath, static, fname, res) |
36873
98baf8dea553
hgweb: port static file handling to new response API
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36865
diff
changeset
|
437 return res.sendresponse() |
5603
74f65f44a9aa
hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5602
diff
changeset
|
438 |
25083
ef36536abea3
hgweb: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
22634
diff
changeset
|
439 # top-level index |
31482
da7d19324b1e
hgwebdir: add support for explicit index files
Matt Harbison <matt_harbison@yahoo.com>
parents:
30766
diff
changeset
|
440 |
da7d19324b1e
hgwebdir: add support for explicit index files
Matt Harbison <matt_harbison@yahoo.com>
parents:
30766
diff
changeset
|
441 repos = dict(self.repos) |
da7d19324b1e
hgwebdir: add support for explicit index files
Matt Harbison <matt_harbison@yahoo.com>
parents:
30766
diff
changeset
|
442 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
443 if (not virtual or virtual == b'index') and virtual not in repos: |
36905
93717f082af9
hgweb: use modern response type for index generation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36904
diff
changeset
|
444 return self.makeindex(req, res, tmpl) |
5601
8279cb841467
hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5585
diff
changeset
|
445 |
25083
ef36536abea3
hgweb: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
22634
diff
changeset
|
446 # nested indexes and hgwebs |
6210
942287cb1f57
Removed trailing spaces from everything except test output
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6046
diff
changeset
|
447 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
448 if virtual.endswith(b'/index') and virtual not in repos: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
449 subdir = virtual[: -len(b'index')] |
31482
da7d19324b1e
hgwebdir: add support for explicit index files
Matt Harbison <matt_harbison@yahoo.com>
parents:
30766
diff
changeset
|
450 if any(r.startswith(subdir) for r in repos): |
36905
93717f082af9
hgweb: use modern response type for index generation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36904
diff
changeset
|
451 return self.makeindex(req, res, tmpl, subdir) |
31482
da7d19324b1e
hgwebdir: add support for explicit index files
Matt Harbison <matt_harbison@yahoo.com>
parents:
30766
diff
changeset
|
452 |
32004
bd3cb917761a
hgwebdir: allow a repository to be hosted at "/"
Matt Harbison <matt_harbison@yahoo.com>
parents:
31482
diff
changeset
|
453 def _virtualdirs(): |
42343
d8e55c0c642c
util: make util.dirs() and util.finddirs() include root directory (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41365
diff
changeset
|
454 # Check the full virtual path, and each parent |
d8e55c0c642c
util: make util.dirs() and util.finddirs() include root directory (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41365
diff
changeset
|
455 yield virtual |
43633
0b7733719d21
utils: move finddirs() to pathutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
43106
diff
changeset
|
456 for p in pathutil.finddirs(virtual): |
42343
d8e55c0c642c
util: make util.dirs() and util.finddirs() include root directory (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41365
diff
changeset
|
457 yield p |
32004
bd3cb917761a
hgwebdir: allow a repository to be hosted at "/"
Matt Harbison <matt_harbison@yahoo.com>
parents:
31482
diff
changeset
|
458 |
bd3cb917761a
hgwebdir: allow a repository to be hosted at "/"
Matt Harbison <matt_harbison@yahoo.com>
parents:
31482
diff
changeset
|
459 for virtualrepo in _virtualdirs(): |
25083
ef36536abea3
hgweb: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
22634
diff
changeset
|
460 real = repos.get(virtualrepo) |
ef36536abea3
hgweb: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
22634
diff
changeset
|
461 if real: |
36897
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36895
diff
changeset
|
462 # Re-parse the WSGI environment to take into account our |
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36895
diff
changeset
|
463 # repository path component. |
37712
a728e3695325
hgwebdir: un-bytes the env dict before re-parsing env
Augie Fackler <augie@google.com>
parents:
37515
diff
changeset
|
464 uenv = req.rawenv |
a728e3695325
hgwebdir: un-bytes the env dict before re-parsing env
Augie Fackler <augie@google.com>
parents:
37515
diff
changeset
|
465 if pycompat.ispy3: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
466 uenv = { |
43106
d783f945a701
py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43077
diff
changeset
|
467 k.decode('latin1'): v |
d783f945a701
py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43077
diff
changeset
|
468 for k, v in pycompat.iteritems(uenv) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
469 } |
36911
f0a851542a05
hgweb: remove wsgirequest (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36908
diff
changeset
|
470 req = requestmod.parserequestfromenv( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
471 uenv, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
472 reponame=virtualrepo, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
473 altbaseurl=self.ui.config(b'web', b'baseurl'), |
37818
877185de62cf
hgweb: reuse body file object when hgwebdir calls hgweb (issue5851)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37712
diff
changeset
|
474 # Reuse wrapped body file object otherwise state |
877185de62cf
hgweb: reuse body file object when hgwebdir calls hgweb (issue5851)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37712
diff
changeset
|
475 # tracking can get confused. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
476 bodyfh=req.bodyfh, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
477 ) |
25083
ef36536abea3
hgweb: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
22634
diff
changeset
|
478 try: |
ef36536abea3
hgweb: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
22634
diff
changeset
|
479 # ensure caller gets private copy of ui |
ef36536abea3
hgweb: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
22634
diff
changeset
|
480 repo = hg.repository(self.ui.copy(), real) |
36911
f0a851542a05
hgweb: remove wsgirequest (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36908
diff
changeset
|
481 return hgweb_mod.hgweb(repo).run_wsgi(req, res) |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25488
diff
changeset
|
482 except IOError as inst: |
34022
d5b2beca16c0
python3: wrap all uses of <exception>.strerror with strtolocal
Augie Fackler <raf@durin42.com>
parents:
33328
diff
changeset
|
483 msg = encoding.strtolocal(inst.strerror) |
25083
ef36536abea3
hgweb: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
22634
diff
changeset
|
484 raise ErrorResponse(HTTP_SERVER_ERROR, msg) |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25488
diff
changeset
|
485 except error.RepoError as inst: |
34358
8cbcee0b923d
py3: remove use of str() in hgwebdir
Yuya Nishihara <yuya@tcha.org>
parents:
34257
diff
changeset
|
486 raise ErrorResponse(HTTP_SERVER_ERROR, bytes(inst)) |
5601
8279cb841467
hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5585
diff
changeset
|
487 |
25083
ef36536abea3
hgweb: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
22634
diff
changeset
|
488 # browse subdirectories |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
489 subdir = virtual + b'/' |
25083
ef36536abea3
hgweb: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
22634
diff
changeset
|
490 if [r for r in repos if r.startswith(subdir)]: |
36905
93717f082af9
hgweb: use modern response type for index generation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36904
diff
changeset
|
491 return self.makeindex(req, res, tmpl, subdir) |
5603
74f65f44a9aa
hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5602
diff
changeset
|
492 |
25083
ef36536abea3
hgweb: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
22634
diff
changeset
|
493 # prefixes not found |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
494 res.status = b'404 Not Found' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
495 res.setbodygen(tmpl.generate(b'notfound', {b'repo': virtual})) |
36907
c1de7efca574
hgweb: port to new response API
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36906
diff
changeset
|
496 return res.sendresponse() |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5603
diff
changeset
|
497 |
36907
c1de7efca574
hgweb: port to new response API
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36906
diff
changeset
|
498 except ErrorResponse as e: |
c1de7efca574
hgweb: port to new response API
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36906
diff
changeset
|
499 res.status = statusmessage(e.code, pycompat.bytestr(e)) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
500 res.setbodygen( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
501 tmpl.generate(b'error', {b'error': e.message or b''}) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
502 ) |
36907
c1de7efca574
hgweb: port to new response API
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36906
diff
changeset
|
503 return res.sendresponse() |
5601
8279cb841467
hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5585
diff
changeset
|
504 finally: |
43986
71582c5ad00f
hgweb: delete local variable instead of setting it to `None`
Matt Harbison <matt_harbison@yahoo.com>
parents:
43793
diff
changeset
|
505 del tmpl |
5601
8279cb841467
hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5585
diff
changeset
|
506 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
507 def makeindex(self, req, res, tmpl, subdir=b""): |
8371
1bd0fdf4c1ec
hgwebdir: refresh configuration periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
8360
diff
changeset
|
508 self.refresh() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
509 sortable = [b"name", b"description", b"contact", b"lastchange"] |
36893
455918512ed2
hgweb: extract entries() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
510 sortcolumn, descending = None, False |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
511 if b'sort' in req.qsparams: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
512 sortcolumn = req.qsparams[b'sort'] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
513 descending = sortcolumn.startswith(b'-') |
5601
8279cb841467
hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5585
diff
changeset
|
514 if descending: |
8279cb841467
hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5585
diff
changeset
|
515 sortcolumn = sortcolumn[1:] |
8279cb841467
hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5585
diff
changeset
|
516 if sortcolumn not in sortable: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
517 sortcolumn = b"" |
4841
9b0ebb5e0f94
hgweb: let hgwebdir browse subdirectories
Brendan Cully <brendan@kublai.com>
parents:
4709
diff
changeset
|
518 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
519 sort = [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
520 ( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
521 b"sort_%s" % column, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
522 b"%s%s" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
523 % ( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
524 (not descending and column == sortcolumn) and b"-" or b"", |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
525 column, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
526 ), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
527 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
528 for column in sortable |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
529 ] |
5928
3340aa5a64f7
hgweb: move HTTP content types out of header templates
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5915
diff
changeset
|
530 |
8371
1bd0fdf4c1ec
hgwebdir: refresh configuration periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
8360
diff
changeset
|
531 self.refresh() |
6221
2eb18c780287
Support web.baseurl in hgwebdir, overriding SCRIPT_NAME
Brendan Cully <brendan@kublai.com>
parents:
6217
diff
changeset
|
532 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
533 entries = indexentries( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
534 self.ui, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
535 self.repos, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
536 req, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
537 self.stripecount, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
538 sortcolumn=sortcolumn, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
539 descending=descending, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
540 subdir=subdir, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
541 ) |
6221
2eb18c780287
Support web.baseurl in hgwebdir, overriding SCRIPT_NAME
Brendan Cully <brendan@kublai.com>
parents:
6217
diff
changeset
|
542 |
37019
c97b936d8bb5
templater: use named function to expand template against mapping dict (API)
Yuya Nishihara <yuya@tcha.org>
parents:
36989
diff
changeset
|
543 mapping = { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
544 b'entries': entries, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
545 b'subdir': subdir, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
546 b'pathdef': hgweb_mod.makebreadcrumb(b'/' + subdir, self.prefix), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
547 b'sortcolumn': sortcolumn, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
548 b'descending': descending, |
37019
c97b936d8bb5
templater: use named function to expand template against mapping dict (API)
Yuya Nishihara <yuya@tcha.org>
parents:
36989
diff
changeset
|
549 } |
c97b936d8bb5
templater: use named function to expand template against mapping dict (API)
Yuya Nishihara <yuya@tcha.org>
parents:
36989
diff
changeset
|
550 mapping.update(sort) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
551 res.setbodygen(tmpl.generate(b'index', mapping)) |
36905
93717f082af9
hgweb: use modern response type for index generation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36904
diff
changeset
|
552 return res.sendresponse() |
5602
d676d0f35bd8
hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5601
diff
changeset
|
553 |
30766
d7bf7d2bd5ab
hgweb: support Content Security Policy
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30749
diff
changeset
|
554 def templater(self, req, nonce): |
45314
d12fba074cc6
hgweb: remove some accesses to private member uimod._unset
Martin von Zweigbergk <martinvonz@google.com>
parents:
45306
diff
changeset
|
555 def config(*args, **kwargs): |
d12fba074cc6
hgweb: remove some accesses to private member uimod._unset
Martin von Zweigbergk <martinvonz@google.com>
parents:
45306
diff
changeset
|
556 kwargs.setdefault('untrusted', True) |
d12fba074cc6
hgweb: remove some accesses to private member uimod._unset
Martin von Zweigbergk <martinvonz@google.com>
parents:
45306
diff
changeset
|
557 return self.ui.config(*args, **kwargs) |
5602
d676d0f35bd8
hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5601
diff
changeset
|
558 |
8216
25266fe996b0
hgweb: use new sessionvars code in hgwebdir, too
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8215
diff
changeset
|
559 vars = {} |
45318
1a4f925f72c3
hgweb: enable reading styles from resources in frozen binaries
Martin von Zweigbergk <martinvonz@google.com>
parents:
45314
diff
changeset
|
560 styles, (style, mapfile, fp) = hgweb_mod.getstyle( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
561 req, config, self.templatepath |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
562 ) |
9842
d3dbdca92458
hgweb: don't choke when an inexistent style is requested (issue1901)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9724
diff
changeset
|
563 if style == styles[0]: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
564 vars[b'style'] = style |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
565 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
566 sessionvars = webutil.sessionvars(vars, b'?') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
567 logourl = config(b'web', b'logourl') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
568 logoimg = config(b'web', b'logoimg') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
569 staticurl = ( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
570 config(b'web', b'staticurl') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
571 or req.apppath.rstrip(b'/') + b'/static/' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
572 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
573 if not staticurl.endswith(b'/'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
574 staticurl += b'/' |
5602
d676d0f35bd8
hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5601
diff
changeset
|
575 |
28954
f97a0bcfd7a1
templater: separate function to create templater from map file (API)
Yuya Nishihara <yuya@tcha.org>
parents:
27046
diff
changeset
|
576 defaults = { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
577 b"encoding": encoding.encoding, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
578 b"url": req.apppath + b'/', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
579 b"logourl": logourl, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
580 b"logoimg": logoimg, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
581 b"staticurl": staticurl, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
582 b"sessionvars": sessionvars, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
583 b"style": style, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
584 b"nonce": nonce, |
28954
f97a0bcfd7a1
templater: separate function to create templater from map file (API)
Yuya Nishihara <yuya@tcha.org>
parents:
27046
diff
changeset
|
585 } |
38928
4167437a45dd
hgweb: use registrar to add "motd" template keyword
Yuya Nishihara <yuya@tcha.org>
parents:
38745
diff
changeset
|
586 templatekeyword = registrar.templatekeyword(defaults) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42343
diff
changeset
|
587 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
588 @templatekeyword(b'motd', requires=()) |
38928
4167437a45dd
hgweb: use registrar to add "motd" template keyword
Yuya Nishihara <yuya@tcha.org>
parents:
38745
diff
changeset
|
589 def motd(context, mapping): |
4167437a45dd
hgweb: use registrar to add "motd" template keyword
Yuya Nishihara <yuya@tcha.org>
parents:
38745
diff
changeset
|
590 if self.motd is not None: |
4167437a45dd
hgweb: use registrar to add "motd" template keyword
Yuya Nishihara <yuya@tcha.org>
parents:
38745
diff
changeset
|
591 yield self.motd |
4167437a45dd
hgweb: use registrar to add "motd" template keyword
Yuya Nishihara <yuya@tcha.org>
parents:
38745
diff
changeset
|
592 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
593 yield config(b'web', b'motd') |
38928
4167437a45dd
hgweb: use registrar to add "motd" template keyword
Yuya Nishihara <yuya@tcha.org>
parents:
38745
diff
changeset
|
594 |
45318
1a4f925f72c3
hgweb: enable reading styles from resources in frozen binaries
Martin von Zweigbergk <martinvonz@google.com>
parents:
45314
diff
changeset
|
595 return templater.templater.frommapfile( |
1a4f925f72c3
hgweb: enable reading styles from resources in frozen binaries
Martin von Zweigbergk <martinvonz@google.com>
parents:
45314
diff
changeset
|
596 mapfile, fp=fp, defaults=defaults |
1a4f925f72c3
hgweb: enable reading styles from resources in frozen binaries
Martin von Zweigbergk <martinvonz@google.com>
parents:
45314
diff
changeset
|
597 ) |