author | Augie Fackler <augie@google.com> |
Sun, 14 Oct 2018 08:55:30 -0400 | |
changeset 40305 | 6519f5aee06f |
parent 39793 | 536f22d6c2c5 |
child 40728 | 2cd5f1fac788 |
permissions | -rw-r--r-- |
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> |
2859 | 4 |
# Copyright 2005, 2006 Matt Mackall <mpm@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, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
33 |
hg, |
29787
80df04266a16
hgweb: profile HTTP requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29786
diff
changeset
|
34 |
profiling, |
34358
8cbcee0b923d
py3: remove use of str() in hgwebdir
Yuya Nishihara <yuya@tcha.org>
parents:
34257
diff
changeset
|
35 |
pycompat, |
38928
4167437a45dd
hgweb: use registrar to add "motd" template keyword
Yuya Nishihara <yuya@tcha.org>
parents:
38745
diff
changeset
|
36 |
registrar, |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
37 |
scmutil, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
38 |
templater, |
37508
30a7b32897f1
hgwebdir: wrap {entries} with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
37019
diff
changeset
|
39 |
templateutil, |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
40 |
ui as uimod, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
41 |
util, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
42 |
) |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
43 |
|
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
44 |
from . import ( |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
45 |
hgweb_mod, |
36804
b9b968e21f78
hgweb: rename req to wsgireq
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36607
diff
changeset
|
46 |
request as requestmod, |
27046
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
47 |
webutil, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
48 |
wsgicgi, |
37fcfe52c68c
hgweb: use absolute_import
Yuya Nishihara <yuya@tcha.org>
parents:
27045
diff
changeset
|
49 |
) |
36607
c6061cadb400
util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents:
34703
diff
changeset
|
50 |
from ..utils import dateutil |
138 | 51 |
|
8215
227707c90548
hgweb: some cleanups in hgwebdir, remove double defaults
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8209
diff
changeset
|
52 |
def cleannames(items): |
227707c90548
hgweb: some cleanups in hgwebdir, remove double defaults
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8209
diff
changeset
|
53 |
return [(util.pconvert(name).strip('/'), 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
|
54 |
|
8529
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
8389
diff
changeset
|
55 |
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
|
56 |
repos = [] |
8529
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
8389
diff
changeset
|
57 |
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
|
58 |
roothead, roottail = os.path.split(root) |
17104
5a9acb0b2086
help: improve hgweb help
Mads Kiilerich <mads@kiilerich.com>
parents:
16754
diff
changeset
|
59 |
# "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
|
60 |
# /bar/ be served as as foo/N . |
5a9acb0b2086
help: improve hgweb help
Mads Kiilerich <mads@kiilerich.com>
parents:
16754
diff
changeset
|
61 |
# '*' will not search inside dirs with .hg (except .hg/patches), |
5a9acb0b2086
help: improve hgweb help
Mads Kiilerich <mads@kiilerich.com>
parents:
16754
diff
changeset
|
62 |
# '**' 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
|
63 |
try: |
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
8389
diff
changeset
|
64 |
recurse = {'*': False, '**': True}[roottail] |
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
8389
diff
changeset
|
65 |
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
|
66 |
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
|
67 |
continue |
11677
8f8a7976f4bc
hgwebdir: allow pure relative globs in paths
Mads Kiilerich <mads@kiilerich.com>
parents:
11649
diff
changeset
|
68 |
roothead = os.path.normpath(os.path.abspath(roothead)) |
13975
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13964
diff
changeset
|
69 |
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
|
70 |
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
|
71 |
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
|
72 |
|
13402
f947d9a4c45c
hgweb: doctest of url creation from wildcard expansion
Mads Kiilerich <mads@kiilerich.com>
parents:
13214
diff
changeset
|
73 |
def urlrepos(prefix, roothead, paths): |
f947d9a4c45c
hgweb: doctest of url creation from wildcard expansion
Mads Kiilerich <mads@kiilerich.com>
parents:
13214
diff
changeset
|
74 |
"""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
|
75 |
|
13538
d24e97fd52a9
test-doctest: handle unix/windows path discrepancies
Patrick Mezard <pmezard@gmail.com>
parents:
13436
diff
changeset
|
76 |
>>> 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
|
77 |
>>> 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
|
78 |
[('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
|
79 |
>>> 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
|
80 |
[('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
|
81 |
""" |
f947d9a4c45c
hgweb: doctest of url creation from wildcard expansion
Mads Kiilerich <mads@kiilerich.com>
parents:
13214
diff
changeset
|
82 |
for path in paths: |
f947d9a4c45c
hgweb: doctest of url creation from wildcard expansion
Mads Kiilerich <mads@kiilerich.com>
parents:
13214
diff
changeset
|
83 |
path = os.path.normpath(path) |
13403
8ed91088acbb
hgweb: make paths wildcards expanding in a repo root match repo correctly
Mads Kiilerich <mads@kiilerich.com>
parents:
13402
diff
changeset
|
84 |
yield (prefix + '/' + |
8ed91088acbb
hgweb: make paths wildcards expanding in a repo root match repo correctly
Mads Kiilerich <mads@kiilerich.com>
parents:
13402
diff
changeset
|
85 |
util.pconvert(path[len(roothead):]).lstrip('/')).strip('/'), path |
13402
f947d9a4c45c
hgweb: doctest of url creation from wildcard expansion
Mads Kiilerich <mads@kiilerich.com>
parents:
13214
diff
changeset
|
86 |
|
36890
f8d6d9b29b39
hgweb: move readallowed to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36889
diff
changeset
|
87 |
def readallowed(ui, req): |
f8d6d9b29b39
hgweb: move readallowed to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36889
diff
changeset
|
88 |
"""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
|
89 |
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
|
90 |
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
|
91 |
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
|
92 |
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
|
93 |
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
|
94 |
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
|
95 |
|
f8d6d9b29b39
hgweb: move readallowed to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36889
diff
changeset
|
96 |
user = req.remoteuser |
f8d6d9b29b39
hgweb: move readallowed to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36889
diff
changeset
|
97 |
|
f8d6d9b29b39
hgweb: move readallowed to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36889
diff
changeset
|
98 |
deny_read = ui.configlist('web', 'deny_read', untrusted=True) |
f8d6d9b29b39
hgweb: move readallowed to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36889
diff
changeset
|
99 |
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
|
100 |
return False |
f8d6d9b29b39
hgweb: move readallowed to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36889
diff
changeset
|
101 |
|
f8d6d9b29b39
hgweb: move readallowed to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36889
diff
changeset
|
102 |
allow_read = ui.configlist('web', 'allow_read', untrusted=True) |
f8d6d9b29b39
hgweb: move readallowed to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36889
diff
changeset
|
103 |
# 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
|
104 |
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
|
105 |
return True |
f8d6d9b29b39
hgweb: move readallowed to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36889
diff
changeset
|
106 |
|
f8d6d9b29b39
hgweb: move readallowed to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36889
diff
changeset
|
107 |
return False |
f8d6d9b29b39
hgweb: move readallowed to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36889
diff
changeset
|
108 |
|
36904
092ab4ba7ee5
hgweb: don't pass wsgireq to makeindex and other functions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36903
diff
changeset
|
109 |
def rawindexentries(ui, repos, req, subdir=''): |
36892
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
110 |
descend = ui.configbool('web', 'descend') |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
111 |
collapse = ui.configbool('web', 'collapse') |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
112 |
seenrepos = set() |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
113 |
seendirs = set() |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
114 |
for name, path in repos: |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
115 |
|
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
116 |
if not name.startswith(subdir): |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
117 |
continue |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
118 |
name = name[len(subdir):] |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
119 |
directory = False |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
120 |
|
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
121 |
if '/' in name: |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
122 |
if not descend: |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
123 |
continue |
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 |
nameparts = name.split('/') |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
126 |
rootname = nameparts[0] |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
127 |
|
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
128 |
if not collapse: |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
129 |
pass |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
130 |
elif rootname in seendirs: |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
131 |
continue |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
132 |
elif rootname in seenrepos: |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
133 |
pass |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
134 |
else: |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
135 |
directory = True |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
136 |
name = rootname |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
137 |
|
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
138 |
# redefine the path to refer to the directory |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
139 |
discarded = '/'.join(nameparts[1:]) |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
140 |
|
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
141 |
# remove name parts plus accompanying slash |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
142 |
path = path[:-len(discarded) - 1] |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
143 |
|
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
144 |
try: |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
145 |
r = hg.repository(ui, path) |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
146 |
directory = False |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
147 |
except (IOError, error.RepoError): |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
148 |
pass |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
149 |
|
36902
e473a032f38a
hgweb: rewrite path generation for index entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36901
diff
changeset
|
150 |
parts = [ |
36904
092ab4ba7ee5
hgweb: don't pass wsgireq to makeindex and other functions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36903
diff
changeset
|
151 |
req.apppath.strip('/'), |
36902
e473a032f38a
hgweb: rewrite path generation for index entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36901
diff
changeset
|
152 |
subdir.strip('/'), |
e473a032f38a
hgweb: rewrite path generation for index entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36901
diff
changeset
|
153 |
name.strip('/'), |
e473a032f38a
hgweb: rewrite path generation for index entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36901
diff
changeset
|
154 |
] |
e473a032f38a
hgweb: rewrite path generation for index entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36901
diff
changeset
|
155 |
url = '/' + '/'.join(p for p in parts if p) + '/' |
15003
a31b8e03af28
hgweb: extract the path logic from updatereqenv and add doctests
Matt Mackall <mpm@selenic.com>
parents:
15002
diff
changeset
|
156 |
|
36892
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
157 |
# 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
|
158 |
if directory: |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
159 |
# get the directory's time information |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
160 |
try: |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
161 |
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
|
162 |
except OSError: |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
163 |
continue |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
164 |
|
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
165 |
# 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
|
166 |
# the entry is a directory, not a regular repository |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
167 |
row = {'contact': "", |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
168 |
'contact_sort': "", |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
169 |
'name': name + '/', |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
170 |
'name_sort': name, |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
171 |
'url': url, |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
172 |
'description': "", |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
173 |
'description_sort': "", |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
174 |
'lastchange': d, |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
175 |
'lastchange_sort': d[1] - d[0], |
37515
8a5ee6aa8870
hgweb: wrap {archives} with mappinglist
Yuya Nishihara <yuya@tcha.org>
parents:
37513
diff
changeset
|
176 |
'archives': templateutil.mappinglist([]), |
36892
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
177 |
'isdirectory': True, |
37510
876d54f800cf
hgweb: wrap {labels} by hybridlist()
Yuya Nishihara <yuya@tcha.org>
parents:
37508
diff
changeset
|
178 |
'labels': templateutil.hybridlist([], name='label'), |
36892
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
179 |
} |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
180 |
|
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
181 |
seendirs.add(name) |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
182 |
yield row |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
183 |
continue |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
184 |
|
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
185 |
u = ui.copy() |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
186 |
try: |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
187 |
u.readconfig(os.path.join(path, '.hg', 'hgrc')) |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
188 |
except Exception as e: |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
189 |
u.warn(_('error reading %s/.hg/hgrc: %s\n') % (path, e)) |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
190 |
continue |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
191 |
|
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
192 |
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
|
193 |
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
|
194 |
|
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
195 |
if u.configbool("web", "hidden", untrusted=True): |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
196 |
continue |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
197 |
|
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
198 |
if not readallowed(u, req): |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
199 |
continue |
15003
a31b8e03af28
hgweb: extract the path logic from updatereqenv and add doctests
Matt Mackall <mpm@selenic.com>
parents:
15002
diff
changeset
|
200 |
|
36892
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
201 |
# update time with local timezone |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
202 |
try: |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
203 |
r = hg.repository(ui, path) |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
204 |
except IOError: |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
205 |
u.warn(_('error accessing repository at %s\n') % path) |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
206 |
continue |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
207 |
except error.RepoError: |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
208 |
u.warn(_('error accessing repository at %s\n') % path) |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
209 |
continue |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
210 |
try: |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
211 |
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
|
212 |
except OSError: |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
213 |
continue |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
214 |
|
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
215 |
contact = get_contact(get) |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
216 |
description = get("web", "description") |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
217 |
seenrepos.add(name) |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
218 |
name = get("web", "name", name) |
37510
876d54f800cf
hgweb: wrap {labels} by hybridlist()
Yuya Nishihara <yuya@tcha.org>
parents:
37508
diff
changeset
|
219 |
labels = u.configlist('web', 'labels', untrusted=True) |
36892
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
220 |
row = {'contact': contact or "unknown", |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
221 |
'contact_sort': contact.upper() or "unknown", |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
222 |
'name': name, |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
223 |
'name_sort': name, |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
224 |
'url': url, |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
225 |
'description': description or "unknown", |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
226 |
'description_sort': description.upper() or "unknown", |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
227 |
'lastchange': d, |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
228 |
'lastchange_sort': d[1] - d[0], |
37513
40a7c1dd2df9
hgweb: move archivelist() of hgwebdir to webutil
Yuya Nishihara <yuya@tcha.org>
parents:
37511
diff
changeset
|
229 |
'archives': webutil.archivelist(u, "tip", url), |
36892
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
230 |
'isdirectory': None, |
37510
876d54f800cf
hgweb: wrap {labels} by hybridlist()
Yuya Nishihara <yuya@tcha.org>
parents:
37508
diff
changeset
|
231 |
'labels': templateutil.hybridlist(labels, name='label'), |
36892
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
232 |
} |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
233 |
|
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
234 |
yield row |
f370f1b4f12c
hgweb: move rawentries() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36891
diff
changeset
|
235 |
|
37508
30a7b32897f1
hgwebdir: wrap {entries} with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
37019
diff
changeset
|
236 |
def _indexentriesgen(context, ui, repos, req, stripecount, sortcolumn, |
30a7b32897f1
hgwebdir: wrap {entries} with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
37019
diff
changeset
|
237 |
descending, subdir): |
36904
092ab4ba7ee5
hgweb: don't pass wsgireq to makeindex and other functions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36903
diff
changeset
|
238 |
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
|
239 |
|
455918512ed2
hgweb: extract entries() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
240 |
sortdefault = None, False |
455918512ed2
hgweb: extract entries() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
241 |
|
455918512ed2
hgweb: extract entries() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
242 |
if sortcolumn and sortdefault != (sortcolumn, descending): |
455918512ed2
hgweb: extract entries() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
243 |
sortkey = '%s_sort' % sortcolumn |
455918512ed2
hgweb: extract entries() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
244 |
rows = sorted(rows, key=lambda x: x[sortkey], |
455918512ed2
hgweb: extract entries() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
245 |
reverse=descending) |
455918512ed2
hgweb: extract entries() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
246 |
|
455918512ed2
hgweb: extract entries() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
247 |
for row, parity in zip(rows, paritygen(stripecount)): |
455918512ed2
hgweb: extract entries() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
248 |
row['parity'] = parity |
455918512ed2
hgweb: extract entries() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
249 |
yield row |
15003
a31b8e03af28
hgweb: extract the path logic from updatereqenv and add doctests
Matt Mackall <mpm@selenic.com>
parents:
15002
diff
changeset
|
250 |
|
37508
30a7b32897f1
hgwebdir: wrap {entries} with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
37019
diff
changeset
|
251 |
def indexentries(ui, repos, req, stripecount, sortcolumn='', |
30a7b32897f1
hgwebdir: wrap {entries} with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
37019
diff
changeset
|
252 |
descending=False, subdir=''): |
30a7b32897f1
hgwebdir: wrap {entries} with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
37019
diff
changeset
|
253 |
args = (ui, repos, req, stripecount, sortcolumn, descending, subdir) |
30a7b32897f1
hgwebdir: wrap {entries} with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
37019
diff
changeset
|
254 |
return templateutil.mappinggenerator(_indexentriesgen, args=args) |
30a7b32897f1
hgwebdir: wrap {entries} with mappinggenerator
Yuya Nishihara <yuya@tcha.org>
parents:
37019
diff
changeset
|
255 |
|
1559
59b3639df0a9
Convert all classes to new-style classes by deriving them from object.
Eric Hopper <hopper@omnifarious.org>
parents:
1554
diff
changeset
|
256 |
class hgwebdir(object): |
26132
9df8c729e2e7
hgweb: add some documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26072
diff
changeset
|
257 |
"""HTTP server for multiple repositories. |
9df8c729e2e7
hgweb: add some documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26072
diff
changeset
|
258 |
|
9df8c729e2e7
hgweb: add some documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26072
diff
changeset
|
259 |
Given a configuration, different repositories will be served depending |
9df8c729e2e7
hgweb: add some documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26072
diff
changeset
|
260 |
on the request path. |
9df8c729e2e7
hgweb: add some documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26072
diff
changeset
|
261 |
|
9df8c729e2e7
hgweb: add some documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26072
diff
changeset
|
262 |
Instances are typically used as WSGI applications. |
9df8c729e2e7
hgweb: add some documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26072
diff
changeset
|
263 |
""" |
8191
35604226d712
hgweb: kill parentui references
Matt Mackall <mpm@selenic.com>
parents:
8190
diff
changeset
|
264 |
def __init__(self, conf, baseui=None): |
8371
1bd0fdf4c1ec
hgwebdir: refresh configuration periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
8360
diff
changeset
|
265 |
self.conf = conf |
1bd0fdf4c1ec
hgwebdir: refresh configuration periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
8360
diff
changeset
|
266 |
self.baseui = baseui |
26072
06320fb11699
hgweb: make refresh interval configurable
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
267 |
self.ui = None |
8371
1bd0fdf4c1ec
hgwebdir: refresh configuration periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
8360
diff
changeset
|
268 |
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
|
269 |
self.motd = None |
8371
1bd0fdf4c1ec
hgwebdir: refresh configuration periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
8360
diff
changeset
|
270 |
self.refresh() |
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
|
271 |
|
8371
1bd0fdf4c1ec
hgwebdir: refresh configuration periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
8360
diff
changeset
|
272 |
def refresh(self): |
26072
06320fb11699
hgweb: make refresh interval configurable
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
273 |
if self.ui: |
34244
fe5202bef5ce
configitems: register the 'web.refreshinterval' config
Boris Feld <boris.feld@octobus.net>
parents:
34243
diff
changeset
|
274 |
refreshinterval = self.ui.configint('web', 'refreshinterval') |
fe5202bef5ce
configitems: register the 'web.refreshinterval' config
Boris Feld <boris.feld@octobus.net>
parents:
34243
diff
changeset
|
275 |
else: |
fe5202bef5ce
configitems: register the 'web.refreshinterval' config
Boris Feld <boris.feld@octobus.net>
parents:
34243
diff
changeset
|
276 |
item = configitems.coreitems['web']['refreshinterval'] |
fe5202bef5ce
configitems: register the 'web.refreshinterval' config
Boris Feld <boris.feld@octobus.net>
parents:
34243
diff
changeset
|
277 |
refreshinterval = item.default |
26072
06320fb11699
hgweb: make refresh interval configurable
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
278 |
|
06320fb11699
hgweb: make refresh interval configurable
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
279 |
# refreshinterval <= 0 means to always refresh. |
06320fb11699
hgweb: make refresh interval configurable
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
280 |
if (refreshinterval > 0 and |
06320fb11699
hgweb: make refresh interval configurable
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
281 |
self.lastrefresh + refreshinterval > time.time()): |
8371
1bd0fdf4c1ec
hgwebdir: refresh configuration periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
8360
diff
changeset
|
282 |
return |
1bd0fdf4c1ec
hgwebdir: refresh configuration periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
8360
diff
changeset
|
283 |
|
1bd0fdf4c1ec
hgwebdir: refresh configuration periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
8360
diff
changeset
|
284 |
if self.baseui: |
11239
99bc18d1ab0f
hgweb: fix race in refreshing repo list (issue2188)
Matt Mackall <mpm@selenic.com>
parents:
10675
diff
changeset
|
285 |
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
|
286 |
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
|
287 |
u = uimod.ui.load() |
20790
49f2d5644f04
config: set a 'source' in most cases where config don't come from file but code
Mads Kiilerich <madski@unity3d.com>
parents:
20677
diff
changeset
|
288 |
u.setconfig('ui', 'report_untrusted', 'off', 'hgwebdir') |
49f2d5644f04
config: set a 'source' in most cases where config don't come from file but code
Mads Kiilerich <madski@unity3d.com>
parents:
20677
diff
changeset
|
289 |
u.setconfig('ui', 'nontty', 'true', 'hgwebdir') |
25488
89ce95f907bd
hgewb: disable progress when serving (issue4582)
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25427
diff
changeset
|
290 |
# 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
|
291 |
# break some wsgi implementations. |
89ce95f907bd
hgewb: disable progress when serving (issue4582)
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25427
diff
changeset
|
292 |
u.setconfig('progress', 'disable', 'true', 'hgweb') |
8136
6b5522cb2ad2
ui: refactor option setting
Matt Mackall <mpm@selenic.com>
parents:
7966
diff
changeset
|
293 |
|
8529
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
8389
diff
changeset
|
294 |
if not isinstance(self.conf, (dict, list, tuple)): |
a767998f0a78
hgweb: make hgwebdir handle dict/list paths the same as config paths
Jeremy Whitlock <jcscoobyrs@gmail.com>
parents:
8389
diff
changeset
|
295 |
map = {'paths': 'hgweb-paths'} |
13214
5bcb6c9d16db
hgweb: abort if config file isn't found
Matt Mackall <mpm@selenic.com>
parents:
13066
diff
changeset
|
296 |
if not os.path.exists(self.conf): |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26421
diff
changeset
|
297 |
raise error.Abort(_('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
|
298 |
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
|
299 |
paths = [] |
8cbb59124e67
hgweb: support multiple directories for the same path
timeless <timeless@gmail.com>
parents:
13538
diff
changeset
|
300 |
for name, ignored in u.configitems('hgweb-paths'): |
8cbb59124e67
hgweb: support multiple directories for the same path
timeless <timeless@gmail.com>
parents:
13538
diff
changeset
|
301 |
for path in u.configlist('hgweb-paths', name): |
8cbb59124e67
hgweb: support multiple directories for the same path
timeless <timeless@gmail.com>
parents:
13538
diff
changeset
|
302 |
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
|
303 |
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
|
304 |
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
|
305 |
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
|
306 |
paths = self.conf.items() |
8345
dcebff8a25dd
hgwebdir: read --webdir-conf as actual configuration to ui (issue1586)
Alexander Solovyov <piranha@piranha.org.ua>
parents:
8225
diff
changeset
|
307 |
|
11239
99bc18d1ab0f
hgweb: fix race in refreshing repo list (issue2188)
Matt Mackall <mpm@selenic.com>
parents:
10675
diff
changeset
|
308 |
repos = findrepos(paths) |
99bc18d1ab0f
hgweb: fix race in refreshing repo list (issue2188)
Matt Mackall <mpm@selenic.com>
parents:
10675
diff
changeset
|
309 |
for prefix, root in u.configitems('collections'): |
99bc18d1ab0f
hgweb: fix race in refreshing repo list (issue2188)
Matt Mackall <mpm@selenic.com>
parents:
10675
diff
changeset
|
310 |
prefix = util.pconvert(prefix) |
13975
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13964
diff
changeset
|
311 |
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
|
312 |
repo = os.path.normpath(path) |
99bc18d1ab0f
hgweb: fix race in refreshing repo list (issue2188)
Matt Mackall <mpm@selenic.com>
parents:
10675
diff
changeset
|
313 |
name = util.pconvert(repo) |
99bc18d1ab0f
hgweb: fix race in refreshing repo list (issue2188)
Matt Mackall <mpm@selenic.com>
parents:
10675
diff
changeset
|
314 |
if name.startswith(prefix): |
99bc18d1ab0f
hgweb: fix race in refreshing repo list (issue2188)
Matt Mackall <mpm@selenic.com>
parents:
10675
diff
changeset
|
315 |
name = name[len(prefix):] |
99bc18d1ab0f
hgweb: fix race in refreshing repo list (issue2188)
Matt Mackall <mpm@selenic.com>
parents:
10675
diff
changeset
|
316 |
repos.append((name.lstrip('/'), repo)) |
99bc18d1ab0f
hgweb: fix race in refreshing repo list (issue2188)
Matt Mackall <mpm@selenic.com>
parents:
10675
diff
changeset
|
317 |
|
99bc18d1ab0f
hgweb: fix race in refreshing repo list (issue2188)
Matt Mackall <mpm@selenic.com>
parents:
10675
diff
changeset
|
318 |
self.repos = repos |
99bc18d1ab0f
hgweb: fix race in refreshing repo list (issue2188)
Matt Mackall <mpm@selenic.com>
parents:
10675
diff
changeset
|
319 |
self.ui = u |
34239
344fd1fe237b
configitems: register the 'web.encoding' config
Boris Feld <boris.feld@octobus.net>
parents:
34238
diff
changeset
|
320 |
encoding.encoding = self.ui.config('web', 'encoding') |
34246
db63872e10cc
configitems: register the 'web.style' config
Boris Feld <boris.feld@octobus.net>
parents:
34245
diff
changeset
|
321 |
self.style = self.ui.config('web', 'style') |
34248
b59620c52eec
hgwebdir: read 'web.template' untrusted
Boris Feld <boris.feld@octobus.net>
parents:
34247
diff
changeset
|
322 |
self.templatepath = self.ui.config('web', 'templates', untrusted=False) |
34245
945c9816ec1d
configitems: register the 'web.stripes' config
Boris Feld <boris.feld@octobus.net>
parents:
34244
diff
changeset
|
323 |
self.stripecount = self.ui.config('web', 'stripes') |
8621
13613221caf1
hgweb: extract config values after reading webdir-config
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8537
diff
changeset
|
324 |
if self.stripecount: |
13613221caf1
hgweb: extract config values after reading webdir-config
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8537
diff
changeset
|
325 |
self.stripecount = int(self.stripecount) |
34243
d24816dfdcff
configitems: register the 'web.prefix' config
Boris Feld <boris.feld@octobus.net>
parents:
34239
diff
changeset
|
326 |
prefix = self.ui.config('web', 'prefix') |
18515
bf8bbbf4aa45
hgwebdir: use web.prefix when creating url breadcrumbs (issue3790)
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
18258
diff
changeset
|
327 |
if prefix.startswith('/'): |
bf8bbbf4aa45
hgwebdir: use web.prefix when creating url breadcrumbs (issue3790)
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
18258
diff
changeset
|
328 |
prefix = prefix[1:] |
bf8bbbf4aa45
hgwebdir: use web.prefix when creating url breadcrumbs (issue3790)
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
18258
diff
changeset
|
329 |
if prefix.endswith('/'): |
bf8bbbf4aa45
hgwebdir: use web.prefix when creating url breadcrumbs (issue3790)
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
18258
diff
changeset
|
330 |
prefix = prefix[:-1] |
bf8bbbf4aa45
hgwebdir: use web.prefix when creating url breadcrumbs (issue3790)
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
18258
diff
changeset
|
331 |
self.prefix = prefix |
8371
1bd0fdf4c1ec
hgwebdir: refresh configuration periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
8360
diff
changeset
|
332 |
self.lastrefresh = time.time() |
941 | 333 |
|
2535
b8ccf6386db7
Arrange for old copies of CGI scripts to still work.
Eric Hopper <hopper@omnifarious.org>
parents:
2514
diff
changeset
|
334 |
def run(self): |
30636
f1c9fafcbf46
py3: replace os.environ with encoding.environ (part 3 of 5)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30559
diff
changeset
|
335 |
if not encoding.environ.get('GATEWAY_INTERFACE', |
f1c9fafcbf46
py3: replace os.environ with encoding.environ (part 3 of 5)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30559
diff
changeset
|
336 |
'').startswith("CGI/1."): |
8663
45f626a39def
wrap string literals in error messages
Martin Geisler <mg@lazybytes.net>
parents:
8621
diff
changeset
|
337 |
raise RuntimeError("This function is only intended to be " |
45f626a39def
wrap string literals in error messages
Martin Geisler <mg@lazybytes.net>
parents:
8621
diff
changeset
|
338 |
"called while running as a CGI script.") |
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
|
339 |
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
|
340 |
|
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
|
341 |
def __call__(self, env, respond): |
36900
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36897
diff
changeset
|
342 |
baseurl = self.ui.config('web', 'baseurl') |
36911
f0a851542a05
hgweb: remove wsgirequest (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36908
diff
changeset
|
343 |
req = requestmod.parserequestfromenv(env, altbaseurl=baseurl) |
f0a851542a05
hgweb: remove wsgirequest (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36908
diff
changeset
|
344 |
res = requestmod.wsgiresponse(req, respond) |
7336
2dc868712dcc
hgweb: support for deny_read/allow_read options
Mark Edgington <edgimar@gmail.com>
parents:
7225
diff
changeset
|
345 |
|
36911
f0a851542a05
hgweb: remove wsgirequest (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36908
diff
changeset
|
346 |
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
|
347 |
|
36911
f0a851542a05
hgweb: remove wsgirequest (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36908
diff
changeset
|
348 |
def run_wsgi(self, req, res): |
32788
eede022fc142
profile: drop maybeprofile
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32004
diff
changeset
|
349 |
profile = self.ui.configbool('profiling', 'enabled') |
eede022fc142
profile: drop maybeprofile
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
32004
diff
changeset
|
350 |
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
|
351 |
try: |
36978 | 352 |
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
|
353 |
yield r |
ff2370a70fe8
hgweb: garbage collect on every request
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34703
diff
changeset
|
354 |
finally: |
ff2370a70fe8
hgweb: garbage collect on every request
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34703
diff
changeset
|
355 |
# 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
|
356 |
# those objects (and tons of held references) from being |
ff2370a70fe8
hgweb: garbage collect on every request
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34703
diff
changeset
|
357 |
# collected through normal refcounting. We mitigate those |
ff2370a70fe8
hgweb: garbage collect on every request
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34703
diff
changeset
|
358 |
# leaks by performing an explicit GC on every request. |
ff2370a70fe8
hgweb: garbage collect on every request
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34703
diff
changeset
|
359 |
# TODO remove this once leaks are fixed. |
ff2370a70fe8
hgweb: garbage collect on every request
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34703
diff
changeset
|
360 |
# TODO only run this on requests that create localrepository |
ff2370a70fe8
hgweb: garbage collect on every request
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34703
diff
changeset
|
361 |
# instances instead of every request. |
ff2370a70fe8
hgweb: garbage collect on every request
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34703
diff
changeset
|
362 |
gc.collect() |
29786
fc2442492606
hgweb: abstract call to hgwebdir wsgi function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29471
diff
changeset
|
363 |
|
36911
f0a851542a05
hgweb: remove wsgirequest (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36908
diff
changeset
|
364 |
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
|
365 |
try: |
25083
ef36536abea3
hgweb: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
22634
diff
changeset
|
366 |
self.refresh() |
5603
74f65f44a9aa
hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5602
diff
changeset
|
367 |
|
30766
d7bf7d2bd5ab
hgweb: support Content Security Policy
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30749
diff
changeset
|
368 |
csp, nonce = cspvalues(self.ui) |
d7bf7d2bd5ab
hgweb: support Content Security Policy
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30749
diff
changeset
|
369 |
if csp: |
36873
98baf8dea553
hgweb: port static file handling to new response API
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36865
diff
changeset
|
370 |
res.headers['Content-Security-Policy'] = csp |
30766
d7bf7d2bd5ab
hgweb: support Content Security Policy
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30749
diff
changeset
|
371 |
|
36903
803e0fc0cc9a
hgweb: replace PATH_INFO with dispatchpath
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36902
diff
changeset
|
372 |
virtual = req.dispatchpath.strip('/') |
30766
d7bf7d2bd5ab
hgweb: support Content Security Policy
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30749
diff
changeset
|
373 |
tmpl = self.templater(req, nonce) |
36989
de117f579431
templater: factor out helper that renders named template as string
Yuya Nishihara <yuya@tcha.org>
parents:
36978
diff
changeset
|
374 |
ctype = tmpl.render('mimetype', {'encoding': encoding.encoding}) |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5603
diff
changeset
|
375 |
|
36873
98baf8dea553
hgweb: port static file handling to new response API
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36865
diff
changeset
|
376 |
# Global defaults. These can be overridden by any handler. |
98baf8dea553
hgweb: port static file handling to new response API
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36865
diff
changeset
|
377 |
res.status = '200 Script output follows' |
98baf8dea553
hgweb: port static file handling to new response API
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36865
diff
changeset
|
378 |
res.headers['Content-Type'] = ctype |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5603
diff
changeset
|
379 |
|
25083
ef36536abea3
hgweb: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
22634
diff
changeset
|
380 |
# a static file |
36865
3d60a22e27f5
hgweb: perform all parameter lookup via qsparams
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36863
diff
changeset
|
381 |
if virtual.startswith('static/') or 'static' in req.qsparams: |
25083
ef36536abea3
hgweb: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
22634
diff
changeset
|
382 |
if virtual.startswith('static/'): |
ef36536abea3
hgweb: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
22634
diff
changeset
|
383 |
fname = virtual[7:] |
ef36536abea3
hgweb: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
22634
diff
changeset
|
384 |
else: |
36865
3d60a22e27f5
hgweb: perform all parameter lookup via qsparams
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36863
diff
changeset
|
385 |
fname = req.qsparams['static'] |
39793
536f22d6c2c5
hgweb: register web.static to the config table
Yuya Nishihara <yuya@tcha.org>
parents:
38928
diff
changeset
|
386 |
static = self.ui.config("web", "static", untrusted=False) |
25083
ef36536abea3
hgweb: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
22634
diff
changeset
|
387 |
if not static: |
ef36536abea3
hgweb: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
22634
diff
changeset
|
388 |
tp = self.templatepath or templater.templatepaths() |
ef36536abea3
hgweb: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
22634
diff
changeset
|
389 |
if isinstance(tp, str): |
ef36536abea3
hgweb: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
22634
diff
changeset
|
390 |
tp = [tp] |
ef36536abea3
hgweb: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
22634
diff
changeset
|
391 |
static = [os.path.join(p, 'static') for p in tp] |
36873
98baf8dea553
hgweb: port static file handling to new response API
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36865
diff
changeset
|
392 |
|
98baf8dea553
hgweb: port static file handling to new response API
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36865
diff
changeset
|
393 |
staticfile(static, fname, res) |
98baf8dea553
hgweb: port static file handling to new response API
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36865
diff
changeset
|
394 |
return res.sendresponse() |
5603
74f65f44a9aa
hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5602
diff
changeset
|
395 |
|
25083
ef36536abea3
hgweb: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
22634
diff
changeset
|
396 |
# top-level index |
31482
da7d19324b1e
hgwebdir: add support for explicit index files
Matt Harbison <matt_harbison@yahoo.com>
parents:
30766
diff
changeset
|
397 |
|
da7d19324b1e
hgwebdir: add support for explicit index files
Matt Harbison <matt_harbison@yahoo.com>
parents:
30766
diff
changeset
|
398 |
repos = dict(self.repos) |
da7d19324b1e
hgwebdir: add support for explicit index files
Matt Harbison <matt_harbison@yahoo.com>
parents:
30766
diff
changeset
|
399 |
|
32004
bd3cb917761a
hgwebdir: allow a repository to be hosted at "/"
Matt Harbison <matt_harbison@yahoo.com>
parents:
31482
diff
changeset
|
400 |
if (not virtual or virtual == '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
|
401 |
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
|
402 |
|
25083
ef36536abea3
hgweb: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
22634
diff
changeset
|
403 |
# nested indexes and hgwebs |
6210
942287cb1f57
Removed trailing spaces from everything except test output
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6046
diff
changeset
|
404 |
|
31482
da7d19324b1e
hgwebdir: add support for explicit index files
Matt Harbison <matt_harbison@yahoo.com>
parents:
30766
diff
changeset
|
405 |
if virtual.endswith('/index') and virtual not in repos: |
da7d19324b1e
hgwebdir: add support for explicit index files
Matt Harbison <matt_harbison@yahoo.com>
parents:
30766
diff
changeset
|
406 |
subdir = virtual[:-len('index')] |
da7d19324b1e
hgwebdir: add support for explicit index files
Matt Harbison <matt_harbison@yahoo.com>
parents:
30766
diff
changeset
|
407 |
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
|
408 |
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
|
409 |
|
32004
bd3cb917761a
hgwebdir: allow a repository to be hosted at "/"
Matt Harbison <matt_harbison@yahoo.com>
parents:
31482
diff
changeset
|
410 |
def _virtualdirs(): |
bd3cb917761a
hgwebdir: allow a repository to be hosted at "/"
Matt Harbison <matt_harbison@yahoo.com>
parents:
31482
diff
changeset
|
411 |
# Check the full virtual path, each parent, and the root ('') |
bd3cb917761a
hgwebdir: allow a repository to be hosted at "/"
Matt Harbison <matt_harbison@yahoo.com>
parents:
31482
diff
changeset
|
412 |
if virtual != '': |
bd3cb917761a
hgwebdir: allow a repository to be hosted at "/"
Matt Harbison <matt_harbison@yahoo.com>
parents:
31482
diff
changeset
|
413 |
yield virtual |
bd3cb917761a
hgwebdir: allow a repository to be hosted at "/"
Matt Harbison <matt_harbison@yahoo.com>
parents:
31482
diff
changeset
|
414 |
|
bd3cb917761a
hgwebdir: allow a repository to be hosted at "/"
Matt Harbison <matt_harbison@yahoo.com>
parents:
31482
diff
changeset
|
415 |
for p in util.finddirs(virtual): |
bd3cb917761a
hgwebdir: allow a repository to be hosted at "/"
Matt Harbison <matt_harbison@yahoo.com>
parents:
31482
diff
changeset
|
416 |
yield p |
bd3cb917761a
hgwebdir: allow a repository to be hosted at "/"
Matt Harbison <matt_harbison@yahoo.com>
parents:
31482
diff
changeset
|
417 |
|
bd3cb917761a
hgwebdir: allow a repository to be hosted at "/"
Matt Harbison <matt_harbison@yahoo.com>
parents:
31482
diff
changeset
|
418 |
yield '' |
bd3cb917761a
hgwebdir: allow a repository to be hosted at "/"
Matt Harbison <matt_harbison@yahoo.com>
parents:
31482
diff
changeset
|
419 |
|
bd3cb917761a
hgwebdir: allow a repository to be hosted at "/"
Matt Harbison <matt_harbison@yahoo.com>
parents:
31482
diff
changeset
|
420 |
for virtualrepo in _virtualdirs(): |
25083
ef36536abea3
hgweb: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
22634
diff
changeset
|
421 |
real = repos.get(virtualrepo) |
ef36536abea3
hgweb: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
22634
diff
changeset
|
422 |
if real: |
36897
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36895
diff
changeset
|
423 |
# 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
|
424 |
# repository path component. |
37712
a728e3695325
hgwebdir: un-bytes the env dict before re-parsing env
Augie Fackler <augie@google.com>
parents:
37515
diff
changeset
|
425 |
uenv = req.rawenv |
a728e3695325
hgwebdir: un-bytes the env dict before re-parsing env
Augie Fackler <augie@google.com>
parents:
37515
diff
changeset
|
426 |
if pycompat.ispy3: |
a728e3695325
hgwebdir: un-bytes the env dict before re-parsing env
Augie Fackler <augie@google.com>
parents:
37515
diff
changeset
|
427 |
uenv = {k.decode('latin1'): v for k, v in |
a728e3695325
hgwebdir: un-bytes the env dict before re-parsing env
Augie Fackler <augie@google.com>
parents:
37515
diff
changeset
|
428 |
uenv.iteritems()} |
36911
f0a851542a05
hgweb: remove wsgirequest (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36908
diff
changeset
|
429 |
req = requestmod.parserequestfromenv( |
37712
a728e3695325
hgwebdir: un-bytes the env dict before re-parsing env
Augie Fackler <augie@google.com>
parents:
37515
diff
changeset
|
430 |
uenv, reponame=virtualrepo, |
37818
877185de62cf
hgweb: reuse body file object when hgwebdir calls hgweb (issue5851)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37712
diff
changeset
|
431 |
altbaseurl=self.ui.config('web', 'baseurl'), |
877185de62cf
hgweb: reuse body file object when hgwebdir calls hgweb (issue5851)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37712
diff
changeset
|
432 |
# 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
|
433 |
# tracking can get confused. |
877185de62cf
hgweb: reuse body file object when hgwebdir calls hgweb (issue5851)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37712
diff
changeset
|
434 |
bodyfh=req.bodyfh) |
25083
ef36536abea3
hgweb: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
22634
diff
changeset
|
435 |
try: |
ef36536abea3
hgweb: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
22634
diff
changeset
|
436 |
# ensure caller gets private copy of ui |
ef36536abea3
hgweb: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
22634
diff
changeset
|
437 |
repo = hg.repository(self.ui.copy(), real) |
36911
f0a851542a05
hgweb: remove wsgirequest (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36908
diff
changeset
|
438 |
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
|
439 |
except IOError as inst: |
34022
d5b2beca16c0
python3: wrap all uses of <exception>.strerror with strtolocal
Augie Fackler <raf@durin42.com>
parents:
33328
diff
changeset
|
440 |
msg = encoding.strtolocal(inst.strerror) |
25083
ef36536abea3
hgweb: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
22634
diff
changeset
|
441 |
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
|
442 |
except error.RepoError as inst: |
34358
8cbcee0b923d
py3: remove use of str() in hgwebdir
Yuya Nishihara <yuya@tcha.org>
parents:
34257
diff
changeset
|
443 |
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
|
444 |
|
25083
ef36536abea3
hgweb: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
22634
diff
changeset
|
445 |
# browse subdirectories |
ef36536abea3
hgweb: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
22634
diff
changeset
|
446 |
subdir = virtual + '/' |
ef36536abea3
hgweb: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
22634
diff
changeset
|
447 |
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
|
448 |
return self.makeindex(req, res, tmpl, subdir) |
5603
74f65f44a9aa
hgwebdir: refactor inner loop
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5602
diff
changeset
|
449 |
|
25083
ef36536abea3
hgweb: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
22634
diff
changeset
|
450 |
# prefixes not found |
36907
c1de7efca574
hgweb: port to new response API
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36906
diff
changeset
|
451 |
res.status = '404 Not Found' |
37019
c97b936d8bb5
templater: use named function to expand template against mapping dict (API)
Yuya Nishihara <yuya@tcha.org>
parents:
36989
diff
changeset
|
452 |
res.setbodygen(tmpl.generate('notfound', {'repo': virtual})) |
36907
c1de7efca574
hgweb: port to new response API
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36906
diff
changeset
|
453 |
return res.sendresponse() |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5603
diff
changeset
|
454 |
|
36907
c1de7efca574
hgweb: port to new response API
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36906
diff
changeset
|
455 |
except ErrorResponse as e: |
c1de7efca574
hgweb: port to new response API
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36906
diff
changeset
|
456 |
res.status = statusmessage(e.code, pycompat.bytestr(e)) |
37019
c97b936d8bb5
templater: use named function to expand template against mapping dict (API)
Yuya Nishihara <yuya@tcha.org>
parents:
36989
diff
changeset
|
457 |
res.setbodygen(tmpl.generate('error', {'error': e.message or ''})) |
36907
c1de7efca574
hgweb: port to new response API
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36906
diff
changeset
|
458 |
return res.sendresponse() |
5601
8279cb841467
hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5585
diff
changeset
|
459 |
finally: |
8279cb841467
hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5585
diff
changeset
|
460 |
tmpl = None |
8279cb841467
hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5585
diff
changeset
|
461 |
|
36905
93717f082af9
hgweb: use modern response type for index generation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36904
diff
changeset
|
462 |
def makeindex(self, req, res, tmpl, subdir=""): |
8371
1bd0fdf4c1ec
hgwebdir: refresh configuration periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
8360
diff
changeset
|
463 |
self.refresh() |
5601
8279cb841467
hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5585
diff
changeset
|
464 |
sortable = ["name", "description", "contact", "lastchange"] |
36893
455918512ed2
hgweb: extract entries() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
465 |
sortcolumn, descending = None, False |
36889
fc4e31297ffb
hgweb: remove some use of wsgireq in hgwebdir
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36888
diff
changeset
|
466 |
if 'sort' in req.qsparams: |
fc4e31297ffb
hgweb: remove some use of wsgireq in hgwebdir
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36888
diff
changeset
|
467 |
sortcolumn = req.qsparams['sort'] |
5601
8279cb841467
hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5585
diff
changeset
|
468 |
descending = sortcolumn.startswith('-') |
8279cb841467
hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5585
diff
changeset
|
469 |
if descending: |
8279cb841467
hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5585
diff
changeset
|
470 |
sortcolumn = sortcolumn[1:] |
8279cb841467
hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5585
diff
changeset
|
471 |
if sortcolumn not in sortable: |
8279cb841467
hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5585
diff
changeset
|
472 |
sortcolumn = "" |
4841
9b0ebb5e0f94
hgweb: let hgwebdir browse subdirectories
Brendan Cully <brendan@kublai.com>
parents:
4709
diff
changeset
|
473 |
|
5601
8279cb841467
hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5585
diff
changeset
|
474 |
sort = [("sort_%s" % column, |
8279cb841467
hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5585
diff
changeset
|
475 |
"%s%s" % ((not descending and column == sortcolumn) |
8279cb841467
hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5585
diff
changeset
|
476 |
and "-" or "", column)) |
8279cb841467
hgwebdir: split out makeindex function, facilitate test failure diagnosis
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5585
diff
changeset
|
477 |
for column in sortable] |
5928
3340aa5a64f7
hgweb: move HTTP content types out of header templates
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5915
diff
changeset
|
478 |
|
8371
1bd0fdf4c1ec
hgwebdir: refresh configuration periodically
Bryan O'Sullivan <bos@serpentine.com>
parents:
8360
diff
changeset
|
479 |
self.refresh() |
6221
2eb18c780287
Support web.baseurl in hgwebdir, overriding SCRIPT_NAME
Brendan Cully <brendan@kublai.com>
parents:
6217
diff
changeset
|
480 |
|
36904
092ab4ba7ee5
hgweb: don't pass wsgireq to makeindex and other functions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36903
diff
changeset
|
481 |
entries = indexentries(self.ui, self.repos, req, |
36893
455918512ed2
hgweb: extract entries() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
482 |
self.stripecount, sortcolumn=sortcolumn, |
455918512ed2
hgweb: extract entries() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36892
diff
changeset
|
483 |
descending=descending, subdir=subdir) |
6221
2eb18c780287
Support web.baseurl in hgwebdir, overriding SCRIPT_NAME
Brendan Cully <brendan@kublai.com>
parents:
6217
diff
changeset
|
484 |
|
37019
c97b936d8bb5
templater: use named function to expand template against mapping dict (API)
Yuya Nishihara <yuya@tcha.org>
parents:
36989
diff
changeset
|
485 |
mapping = { |
c97b936d8bb5
templater: use named function to expand template against mapping dict (API)
Yuya Nishihara <yuya@tcha.org>
parents:
36989
diff
changeset
|
486 |
'entries': entries, |
c97b936d8bb5
templater: use named function to expand template against mapping dict (API)
Yuya Nishihara <yuya@tcha.org>
parents:
36989
diff
changeset
|
487 |
'subdir': subdir, |
c97b936d8bb5
templater: use named function to expand template against mapping dict (API)
Yuya Nishihara <yuya@tcha.org>
parents:
36989
diff
changeset
|
488 |
'pathdef': hgweb_mod.makebreadcrumb('/' + subdir, self.prefix), |
c97b936d8bb5
templater: use named function to expand template against mapping dict (API)
Yuya Nishihara <yuya@tcha.org>
parents:
36989
diff
changeset
|
489 |
'sortcolumn': sortcolumn, |
c97b936d8bb5
templater: use named function to expand template against mapping dict (API)
Yuya Nishihara <yuya@tcha.org>
parents:
36989
diff
changeset
|
490 |
'descending': descending, |
c97b936d8bb5
templater: use named function to expand template against mapping dict (API)
Yuya Nishihara <yuya@tcha.org>
parents:
36989
diff
changeset
|
491 |
} |
c97b936d8bb5
templater: use named function to expand template against mapping dict (API)
Yuya Nishihara <yuya@tcha.org>
parents:
36989
diff
changeset
|
492 |
mapping.update(sort) |
c97b936d8bb5
templater: use named function to expand template against mapping dict (API)
Yuya Nishihara <yuya@tcha.org>
parents:
36989
diff
changeset
|
493 |
res.setbodygen(tmpl.generate('index', mapping)) |
36905
93717f082af9
hgweb: use modern response type for index generation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36904
diff
changeset
|
494 |
return res.sendresponse() |
5602
d676d0f35bd8
hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5601
diff
changeset
|
495 |
|
30766
d7bf7d2bd5ab
hgweb: support Content Security Policy
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30749
diff
changeset
|
496 |
def templater(self, req, nonce): |
5602
d676d0f35bd8
hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5601
diff
changeset
|
497 |
|
34226
cf08aaaea7f0
web: use '_unset' default value for proxy config method
Boris Feld <boris.feld@octobus.net>
parents:
34131
diff
changeset
|
498 |
def config(section, name, default=uimod._unset, untrusted=True): |
8191
35604226d712
hgweb: kill parentui references
Matt Mackall <mpm@selenic.com>
parents:
8190
diff
changeset
|
499 |
return self.ui.config(section, name, default, untrusted) |
5602
d676d0f35bd8
hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5601
diff
changeset
|
500 |
|
8216
25266fe996b0
hgweb: use new sessionvars code in hgwebdir, too
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8215
diff
changeset
|
501 |
vars = {} |
34515
8afc25e7effc
hgweb: extract function for loading style from request context
Augie Fackler <augie@google.com>
parents:
34486
diff
changeset
|
502 |
styles, (style, mapfile) = hgweb_mod.getstyle(req, config, |
8afc25e7effc
hgweb: extract function for loading style from request context
Augie Fackler <augie@google.com>
parents:
34486
diff
changeset
|
503 |
self.templatepath) |
9842
d3dbdca92458
hgweb: don't choke when an inexistent style is requested (issue1901)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9724
diff
changeset
|
504 |
if style == styles[0]: |
d3dbdca92458
hgweb: don't choke when an inexistent style is requested (issue1901)
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9724
diff
changeset
|
505 |
vars['style'] = style |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
506 |
|
36805
ec46415ed826
hgweb: always use "?" when writing session vars
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36804
diff
changeset
|
507 |
sessionvars = webutil.sessionvars(vars, r'?') |
34612
c2cb6be4212f
configitems: register the 'web.logourl' config
Boris Feld <boris.feld@octobus.net>
parents:
34611
diff
changeset
|
508 |
logourl = config('web', 'logourl') |
34611
c879fc7bd71f
configitems: register the 'web.logoimg' config
Boris Feld <boris.feld@octobus.net>
parents:
34587
diff
changeset
|
509 |
logoimg = config('web', 'logoimg') |
36895
a5c478843c82
hgweb: construct static URL like hgweb does
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36894
diff
changeset
|
510 |
staticurl = (config('web', 'staticurl') |
38745
258d90f69076
hgweb: strip trailing '/' in apppath before appending '/static/' (issue5943)
Cédric Krier <ced@b2ck.com>
parents:
37818
diff
changeset
|
511 |
or req.apppath.rstrip('/') + '/static/') |
5602
d676d0f35bd8
hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5601
diff
changeset
|
512 |
if not staticurl.endswith('/'): |
d676d0f35bd8
hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5601
diff
changeset
|
513 |
staticurl += '/' |
d676d0f35bd8
hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5601
diff
changeset
|
514 |
|
28954
f97a0bcfd7a1
templater: separate function to create templater from map file (API)
Yuya Nishihara <yuya@tcha.org>
parents:
27046
diff
changeset
|
515 |
defaults = { |
f97a0bcfd7a1
templater: separate function to create templater from map file (API)
Yuya Nishihara <yuya@tcha.org>
parents:
27046
diff
changeset
|
516 |
"encoding": encoding.encoding, |
36906
6a0e4efbc61e
hgweb: pass modern request type into templater()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36905
diff
changeset
|
517 |
"url": req.apppath + '/', |
28954
f97a0bcfd7a1
templater: separate function to create templater from map file (API)
Yuya Nishihara <yuya@tcha.org>
parents:
27046
diff
changeset
|
518 |
"logourl": logourl, |
f97a0bcfd7a1
templater: separate function to create templater from map file (API)
Yuya Nishihara <yuya@tcha.org>
parents:
27046
diff
changeset
|
519 |
"logoimg": logoimg, |
f97a0bcfd7a1
templater: separate function to create templater from map file (API)
Yuya Nishihara <yuya@tcha.org>
parents:
27046
diff
changeset
|
520 |
"staticurl": staticurl, |
f97a0bcfd7a1
templater: separate function to create templater from map file (API)
Yuya Nishihara <yuya@tcha.org>
parents:
27046
diff
changeset
|
521 |
"sessionvars": sessionvars, |
f97a0bcfd7a1
templater: separate function to create templater from map file (API)
Yuya Nishihara <yuya@tcha.org>
parents:
27046
diff
changeset
|
522 |
"style": style, |
30766
d7bf7d2bd5ab
hgweb: support Content Security Policy
Gregory Szorc <gregory.szorc@gmail.com>
parents:
30749
diff
changeset
|
523 |
"nonce": nonce, |
28954
f97a0bcfd7a1
templater: separate function to create templater from map file (API)
Yuya Nishihara <yuya@tcha.org>
parents:
27046
diff
changeset
|
524 |
} |
38928
4167437a45dd
hgweb: use registrar to add "motd" template keyword
Yuya Nishihara <yuya@tcha.org>
parents:
38745
diff
changeset
|
525 |
templatekeyword = registrar.templatekeyword(defaults) |
4167437a45dd
hgweb: use registrar to add "motd" template keyword
Yuya Nishihara <yuya@tcha.org>
parents:
38745
diff
changeset
|
526 |
@templatekeyword('motd', requires=()) |
4167437a45dd
hgweb: use registrar to add "motd" template keyword
Yuya Nishihara <yuya@tcha.org>
parents:
38745
diff
changeset
|
527 |
def motd(context, mapping): |
4167437a45dd
hgweb: use registrar to add "motd" template keyword
Yuya Nishihara <yuya@tcha.org>
parents:
38745
diff
changeset
|
528 |
if self.motd is not None: |
4167437a45dd
hgweb: use registrar to add "motd" template keyword
Yuya Nishihara <yuya@tcha.org>
parents:
38745
diff
changeset
|
529 |
yield self.motd |
4167437a45dd
hgweb: use registrar to add "motd" template keyword
Yuya Nishihara <yuya@tcha.org>
parents:
38745
diff
changeset
|
530 |
else: |
4167437a45dd
hgweb: use registrar to add "motd" template keyword
Yuya Nishihara <yuya@tcha.org>
parents:
38745
diff
changeset
|
531 |
yield config('web', 'motd') |
4167437a45dd
hgweb: use registrar to add "motd" template keyword
Yuya Nishihara <yuya@tcha.org>
parents:
38745
diff
changeset
|
532 |
|
28954
f97a0bcfd7a1
templater: separate function to create templater from map file (API)
Yuya Nishihara <yuya@tcha.org>
parents:
27046
diff
changeset
|
533 |
tmpl = templater.templater.frommapfile(mapfile, defaults=defaults) |
5602
d676d0f35bd8
hgwebdir: split out templater creation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
5601
diff
changeset
|
534 |
return tmpl |